"use strict";
const common_vendor = require("../../common/vendor.js");
const API_api = require("../../API/api.js");
const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
  __name: "login",
  setup(__props) {
    let identify = common_vendor.ref("tom");
    const loginUser = (code) => {
      common_vendor.index.request({
        url: API_api.apiImageUrl + "/api/Alipay/parseCode",
        method: "GET",
        data: {
          authcode: code
        },
        /* data: JSON.stringify({ // 尝试将 data 转换为字符串形式
        			authcode: code
        		}),
        		header: { 'content-type': 'application/json' }, */
        success: (res) => {
          console.log(res, "是否有code");
          console.log(res.data);
          if (res.data.code == 0) {
            common_vendor.index.showToast({
              title: "登录成功",
              duration: 2e3
            });
            common_vendor.index.removeStorageSync("cookie");
            common_vendor.index.setStorageSync("userInfo", res.data.data);
            common_vendor.index.setStorageSync("cookie", res.header["Set-Cookie"]);
            common_vendor.index.switchTab({
              url: "/pages/index/index"
            });
          } else {
            common_vendor.index.showToast({
              icon: "error",
              title: "登录失败，请联系管理员"
            });
            return;
          }
        }
      });
    };
    const login = () => {
      common_vendor.index.login({
        scopes: "auth_user",
        success: function(loginRes) {
          if (loginRes.code !== null) {
            console.log("获取code:" + loginRes.code);
            loginUser(loginRes.code);
            common_vendor.index.setStorageSync("identify", identify.value);
          } else {
            console.log("code为空");
          }
        }
      });
    };
    const onButton = () => {
      my.request({
        url: API_api.apiImageUrl + "/api/Alipay/trade",
        method: "GET",
        success: function(result) {
          console.log(result);
          my.tradePay({
            tradeNO: result.data.data,
            success: (res) => {
              console.log("成功调用to");
              my.navigateTo({
                url: "/pages/index/index"
              });
              console.log("成功");
              console.log(res);
            },
            fail: (res) => {
              my.alert({
                content: JSON.stringify(res)
              });
              console.log("失败");
              console.log(res);
            }
          });
          console.log(result.data.data);
        }
      });
    };
    return (_ctx, _cache) => {
      return {
        a: common_vendor.o(login),
        b: common_vendor.o(onButton)
      };
    };
  }
});
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__file", "D:/111111000000/uniapp04/pages/login/login.vue"]]);
my.createPage(MiniProgramPage);
