"use strict";
const common_vendor = require("../../common/vendor.js");
const store_modules_user = require("../../store/modules/user.js");
const api_user = require("../../api/user.js");
if (!Math) {
  AgreementPopup();
}
const AgreementPopup = () => "../agreement/AgreementPopup.js";
const _sfc_main = {
  __name: "LoginPopup",
  setup(__props) {
    const userStore = store_modules_user.useUserStore();
    const { loginPopupVisible } = common_vendor.storeToRefs(userStore);
    common_vendor.ref("wechat");
    const form = common_vendor.ref({
      username: "",
      password: ""
    });
    const showPassword = common_vendor.ref(false);
    const agreed = common_vendor.ref(false);
    const showAgreement = common_vendor.ref(false);
    const agreementType = common_vendor.ref("user");
    const isLogging = common_vendor.ref(false);
    const openAgreement = (type) => {
      agreementType.value = type;
      showAgreement.value = true;
    };
    const handleAgreementConfirm = () => {
      agreed.value = true;
    };
    const handleClose = () => {
      userStore.hideLoginPopup();
      form.value.username = "";
      form.value.password = "";
      agreed.value = false;
      isLogging.value = false;
      common_vendor.index.hideLoading();
    };
    const handleAccountLogin = async () => {
      if (isLogging.value) {
        common_vendor.index.__f__("log", "at components/login/LoginPopup.vue:165", "正在登录中，请勿重复点击");
        return;
      }
      if (!agreed.value) {
        common_vendor.index.showToast({
          title: "请先同意用户协议和隐私协议",
          icon: "none"
        });
        return;
      }
      if (!form.value.username || !form.value.password) {
        common_vendor.index.showToast({
          title: "请输入用户名和密码",
          icon: "none"
        });
        return;
      }
      try {
        isLogging.value = true;
        common_vendor.index.showLoading({
          title: "获取微信授权...",
          mask: true
        });
        common_vendor.index.login({
          provider: "weixin",
          success: async function(loginRes) {
            try {
              common_vendor.index.__f__("log", "at components/login/LoginPopup.vue:197", "wxcode", loginRes.code);
              common_vendor.index.showLoading({
                title: "登录中...",
                mask: true
              });
              try {
                const res = await api_user.userApi.accountLogin({
                  yhm: form.value.username,
                  mm: form.value.password,
                  wdConfirmationCaptchaService: "0",
                  wechatCode: loginRes.code
                });
                common_vendor.index.hideLoading();
                common_vendor.index.__f__("log", "at components/login/LoginPopup.vue:214", "account登录成功", res.data);
                common_vendor.index.$emit("login", res.data);
                userStore.setUserInfo(res.data);
                handleClose();
              } catch (error) {
                common_vendor.index.__f__("error", "at components/login/LoginPopup.vue:221", "登录失败：", error);
                common_vendor.index.showToast({
                  title: "登录失败",
                  icon: "none"
                });
              } finally {
                isLogging.value = false;
                common_vendor.index.hideLoading();
              }
            } catch (outerError) {
              common_vendor.index.__f__("error", "at components/login/LoginPopup.vue:232", "登录过程出错：", outerError);
              common_vendor.index.showToast({
                title: "登录失败",
                icon: "none"
              });
              isLogging.value = false;
              common_vendor.index.hideLoading();
            }
          },
          fail: function(error) {
            common_vendor.index.__f__("error", "at components/login/LoginPopup.vue:242", "获取微信授权失败：", error);
            common_vendor.index.showToast({
              title: "获取微信授权失败",
              icon: "none"
            });
            isLogging.value = false;
            common_vendor.index.hideLoading();
          }
        });
      } catch (e) {
        common_vendor.index.__f__("error", "at components/login/LoginPopup.vue:253", "登录过程出错：", e);
        common_vendor.index.showToast({
          title: "登录失败",
          icon: "none"
        });
        isLogging.value = false;
        common_vendor.index.hideLoading();
      }
    };
    return (_ctx, _cache) => {
      return {
        a: common_vendor.o(handleClose),
        b: common_vendor.o(handleClose),
        c: form.value.username,
        d: common_vendor.o(($event) => form.value.username = $event.detail.value),
        e: !showPassword.value,
        f: form.value.password,
        g: common_vendor.o(($event) => form.value.password = $event.detail.value),
        h: showPassword.value ? "/static/icon/eye-open.png" : "/static/icon/eye-close.png",
        i: common_vendor.o(($event) => showPassword.value = !showPassword.value),
        j: common_vendor.t(isLogging.value ? "登录中..." : "登录"),
        k: isLogging.value ? 1 : "",
        l: isLogging.value,
        m: common_vendor.o(handleAccountLogin),
        n: agreed.value,
        o: common_vendor.o(handleAgreementConfirm),
        p: common_vendor.o(($event) => openAgreement("user")),
        q: common_vendor.o(($event) => openAgreement("privacy")),
        r: common_vendor.unref(loginPopupVisible) ? 1 : "",
        s: common_vendor.o(($event) => showAgreement.value = $event),
        t: common_vendor.p({
          type: agreementType.value,
          visible: showAgreement.value
        })
      };
    };
  }
};
const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-4aa1cbac"]]);
wx.createComponent(Component);
//# sourceMappingURL=../../../.sourcemap/mp-weixin/components/login/LoginPopup.js.map
