"use strict";
const common_vendor = require("../../common/vendor.js");
const common_assets = require("../../common/assets.js");
const util_index = require("../../util/index.js");
if (!Array) {
  const _component_uni_icons = common_vendor.resolveComponent("uni-icons");
  _component_uni_icons();
}
const _sfc_main = {
  __name: "index",
  setup(__props) {
    const userInfo = common_vendor.ref({});
    const deposit = common_vendor.ref("0.00");
    const openId = common_vendor.ref("");
    const authPopup = common_vendor.ref(null);
    const isPopupVisible = common_vendor.ref(false);
    common_vendor.onMounted(() => {
      getInfo();
    });
    const getInfo = async () => {
      try {
        const token = common_vendor.index.getStorageSync("token");
        if (!token) {
          await util_index.wxLogin();
          return;
        }
        const res = await util_index.getUserInfo();
        common_vendor.index.__f__("log", "at pages/my/index.vue:146", "User info response:", res);
        if (res.code == 200) {
          if (res.data.openId) {
            openId.value = res.data.openId;
            common_vendor.index.setStorageSync("openId", res.data.openId);
          }
          userInfo.value = {
            nickName: res.data.nickname,
            phone: res.data.phone,
            avatar: res.data.iconUrl,
            isAdmin: res.data.isAdmin
          };
          common_vendor.index.setStorageSync("userInfo", userInfo.value);
          deposit.value = res.data.balanceAmount || "0.00";
        }
      } catch (error) {
        common_vendor.index.__f__("error", "at pages/my/index.vue:167", "获取用户信息失败:", error);
        common_vendor.index.showToast({
          title: "获取用户信息失败",
          icon: "none"
        });
      }
    };
    const navigateTo = (url) => {
      common_vendor.index.navigateTo({
        url
      });
    };
    const handleWithdraw = () => {
      navigateTo("/pages/deposit/index");
    };
    const handleUserProfileClick = () => {
      if (!userInfo.value) {
        openAuthPopup();
      }
    };
    const openAuthPopup = () => {
      if (authPopup.value) {
        authPopup.value.open();
        isPopupVisible.value = true;
      }
    };
    function maskPhone(phone) {
      if (!phone)
        return "";
      return phone.replace(/(\d{3})\d{4}(\d{4})/, "$1****$2");
    }
    return (_ctx, _cache) => {
      return common_vendor.e({
        a: userInfo.value.avatar
      }, userInfo.value.avatar ? {
        b: userInfo.value.avatar
      } : {
        c: common_assets._imports_0$2
      }, {
        d: userInfo.value.isAdmin
      }, userInfo.value.isAdmin ? {} : {}, {
        e: userInfo.value
      }, userInfo.value ? {
        f: common_vendor.t(userInfo.value.nickName),
        g: common_vendor.t(userInfo.value.phone ? maskPhone(userInfo.value.phone) : "未绑定手机号")
      } : {}, {
        h: common_vendor.p({
          type: "right",
          size: "16",
          color: "#999"
        }),
        i: common_vendor.o(handleUserProfileClick),
        j: common_vendor.t(deposit.value),
        k: common_vendor.o(handleWithdraw),
        l: common_assets._imports_1,
        m: common_vendor.p({
          type: "right",
          size: "16",
          color: "#999"
        }),
        n: common_vendor.o(($event) => navigateTo("/pages/order/index")),
        o: common_assets._imports_2,
        p: common_vendor.p({
          type: "right",
          size: "16",
          color: "#999"
        }),
        q: common_vendor.o(($event) => navigateTo("/pages/feedback/index")),
        r: common_assets._imports_3,
        s: common_vendor.p({
          type: "right",
          size: "16",
          color: "#999"
        }),
        t: common_vendor.o(($event) => navigateTo("/pages/help/index"))
      });
    };
  }
};
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-f97bc692"]]);
wx.createPage(MiniProgramPage);
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/my/index.js.map
