"use strict";
const common_vendor = require("../../common/vendor.js");
const store_user = require("../../store/user.js");
const utils_file = require("../../utils/file.js");
const utils_utils = require("../../utils/utils.js");
const _sfc_main = {
  __name: "userInfo",
  setup(__props) {
    const userStore = store_user.useUserStore();
    const genderOptions = [
      { value: "male", label: "男" },
      { value: "female", label: "女" }
    ];
    const formData = common_vendor.ref({
      avatar: "",
      nickname: "",
      gender: "male",
      // 默认选中男
      birthday: "",
      phone: "1510987760"
    });
    common_vendor.onMounted(() => {
      const userInfo = userStore.getUserInfo;
      if (userInfo) {
        formData.value = {
          avatar: userInfo.avatar || "",
          nickname: userInfo.nickname || "",
          gender: userInfo.gender || "male",
          birthday: userInfo.birthday || "",
          phone: userInfo.phone || "1510987760"
        };
      }
    });
    const handleAvatarClick = () => {
      common_vendor.index.showActionSheet({
        itemList: ["微信头像", "从相册选择", "拍照"],
        success: (res) => {
          if (res.tapIndex === 0) {
            handleWechatAvatar();
          } else if (res.tapIndex === 1) {
            handleChooseAlbum();
          } else if (res.tapIndex === 2) {
            handleTakePhoto();
          }
        },
        fail: (err) => {
          common_vendor.index.__f__("log", "at pages/personal/userInfo.vue:136", "取消选择", err);
        }
      });
    };
    const handleWechatAvatar = () => {
      const userInfo = userStore.getUserInfo;
      if (userInfo && userInfo.avatar) {
        formData.value.avatar = userInfo.avatar;
        common_vendor.index.showToast({
          title: "已使用微信头像",
          icon: "success"
        });
        return;
      }
      common_vendor.wx$1.getUserProfile({
        desc: "用于完善个人资料",
        success: (res) => {
          if (res.userInfo && res.userInfo.avatarUrl) {
            formData.value.avatar = res.userInfo.avatarUrl;
            common_vendor.index.showToast({
              title: "获取成功",
              icon: "success"
            });
          }
        },
        fail: (err) => {
          common_vendor.index.__f__("log", "at pages/personal/userInfo.vue:168", "获取微信头像失败", err);
          common_vendor.index.showToast({
            title: "获取头像失败",
            icon: "none"
          });
        }
      });
    };
    const handleChooseAlbum = () => {
      common_vendor.index.chooseImage({
        count: 1,
        sizeType: ["original", "compressed"],
        sourceType: ["album"],
        success: (res) => {
          const tempFilePath = res.tempFilePaths[0];
          formData.value.avatar = tempFilePath;
        },
        fail: (err) => {
          common_vendor.index.__f__("log", "at pages/personal/userInfo.vue:199", "选择相册失败", err);
        }
      });
    };
    const handleTakePhoto = () => {
      common_vendor.index.chooseImage({
        count: 1,
        sizeType: ["original", "compressed"],
        sourceType: ["camera"],
        success: (res) => {
          const tempFilePath = res.tempFilePaths[0];
          formData.value.avatar = tempFilePath;
        },
        fail: (err) => {
          common_vendor.index.__f__("log", "at pages/personal/userInfo.vue:217", "拍照失败", err);
        }
      });
    };
    const handleBirthdayChange = (e) => {
      formData.value.birthday = e.detail.value;
    };
    const handleChangePhone = () => {
      utils_utils.go("/pages/personal/setPhone");
    };
    return (_ctx, _cache) => {
      return {
        a: formData.value.avatar || common_vendor.unref(utils_file.getFileUrl)("img/personal/userDemo.png"),
        b: formData.value.avatar ? "aspectFill" : "widthFix",
        c: common_vendor.o(handleAvatarClick),
        d: formData.value.nickname,
        e: common_vendor.o(($event) => formData.value.nickname = $event.detail.value),
        f: common_vendor.f(genderOptions, (item, k0, i0) => {
          return {
            a: common_vendor.unref(utils_file.getFileUrl)(formData.value.gender === item.value ? "img/personal/sele2.png" : "img/personal/sele1.png"),
            b: common_vendor.t(item.label),
            c: item.value,
            d: formData.value.gender === item.value ? 1 : "",
            e: common_vendor.o(($event) => formData.value.gender = item.value, item.value)
          };
        }),
        g: common_vendor.t(formData.value.birthday || "请选择生日"),
        h: common_vendor.n({
          placeholder: !formData.value.birthday
        }),
        i: formData.value.birthday,
        j: common_vendor.o(handleBirthdayChange),
        k: common_vendor.t(formData.value.phone || "1510987760"),
        l: common_vendor.o(handleChangePhone)
      };
    };
  }
};
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-2ef1855d"]]);
wx.createPage(MiniProgramPage);
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/personal/userInfo.js.map
