"use strict";
var common_vendor = require("../../common/vendor.js");
var api_index = require("../../api/index.js");
require("../../utils/request.js");
const _sfc_main = {
  setup(__props) {
    const agreeStatus = common_vendor.ref(false);
    const code = common_vendor.ref("");
    common_vendor.onLoad(() => {
      if (common_vendor.index.getStorageSync("token")) {
        common_vendor.index.reLaunch({
          url: "/pages/index/index"
        });
      }
    });
    common_vendor.onShow(() => {
      getCode();
    });
    const login = () => {
      if (!agreeStatus.value)
        return common_vendor.index.showToast({
          title: "\u8BF7\u52FE\u9009\u534F\u8BAE",
          icon: "none"
        });
    };
    const getphonenumber = (e) => {
      if (e.detail.errMsg == "getPhoneNumber:fail user deny") {
        common_vendor.index.showToast({
          title: "\u60A8\u5DF2\u53D6\u6D88\u6388\u6743",
          icon: "none"
        });
      } else {
        getLogins(e.detail.encryptedData, e.detail.iv);
      }
    };
    const getCode = () => {
      common_vendor.index.login({
        provider: "weixin",
        success: function(loginRes) {
          console.log(loginRes);
          code.value = loginRes.code;
        }
      });
    };
    const getLogins = async (data, iv) => {
      try {
        let params = {
          code: code.value,
          encryptedData: data,
          iv
        };
        const res = await api_index.getLogin(params);
        common_vendor.index.setStorageSync("token", res.token);
        common_vendor.index.setStorageSync("userInfo", res);
        common_vendor.index.reLaunch({ url: "/pages/index/index" });
        console.log("getLogin", res);
      } catch (err) {
        console.log("getLogin", err);
      }
    };
    const toRichText = (e) => {
      common_vendor.index.navigateTo({
        url: `/pages/richText/richText?type=${e}`
      });
    };
    const agree = () => {
      agreeStatus.value = !agreeStatus.value;
    };
    return (_ctx, _cache) => {
      return common_vendor.e({
        a: !agreeStatus.value
      }, !agreeStatus.value ? {
        b: common_vendor.o(login)
      } : {
        c: common_vendor.o(getphonenumber)
      }, {
        d: !agreeStatus.value
      }, !agreeStatus.value ? {} : {}, {
        e: common_vendor.o(agree),
        f: common_vendor.o(($event) => toRichText(4)),
        g: common_vendor.o(($event) => toRichText(5))
      });
    };
  }
};
var MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__file", "D:/vue/\u5927\u5065\u5EB7\u5546\u57CE/healthMall/pages/login/login.vue"]]);
wx.createPage(MiniProgramPage);