var a, t;
(a = getApp()),
  (t = getApp()),
  Page({
    data: {
      isShow: !1,
      canIUseGetUserProfile: !1,
      userInfo: [],
      avatarUrl:
        "https://pic.ym23.com/images/196/2022/11/u28R23VB4c92c2i4808JQc4C3Y82O5.png",
      loginBanner:
        "https://api.ym23.com/addons/czt_wxapp_zbsq/icon/weixin1.png",
    },
    onLoad: function (a) {
      wx.getUserProfile && this.setData({ canIUseGetUserProfile: !0 });
    },
    handleAgree() {
      if (!this.data.checked)
        return (
          wx.showToast({
            icon: "none",
            title: "请阅读并同意使用协议及隐私政策",
            duration: 2e3,
          }),
          !1
        );
    },
    onShow: function () {
      this.userdata();
    },
    loginForm: function (a) {
      console.log("bd", a.detail.value),
        a.detail.value.nickname
          ? this.setData({ nickname: a.detail.value.nickname })
          : wx.showModal({ content: "请输入昵称", showCancel: !1 });
    },
    onChooseAvatar(a) {
      const { avatarUrl: e } = a.detail;
      this.setData({ avatarUrl: e });
      var i = [a.detail],
        n = {
          url:
            t.util.url("entry/wxapp/scqiniu") +
            "&m=" +
            t.siteInfo.m +
            "&ids=uptp",
          path: i,
        };
      this.uploadimgs(n);
    },
    uploadimgs: function (a) {
      var e = this,
        i = a.i ? a.i : 0,
        n = a.success ? a.success : 0,
        o = a.fail ? a.fail : 0;
      wx.showLoading({ title: "上传中.." }),
        console.log("上传图片路径", a.path[i].avatarUrl),
        wx.uploadFile({
          url: a.url,
          filePath: a.path[i].avatarUrl,
          name: "file",
          formData: null,
          success: (a) => {
            n++, console.log(a), console.log(i);
            var t = a.data.replace("\r\n", "");
            1 != t
              ? e.setData({ avatarUrl: t })
              : wx.showToast({
                  title: "图片" + (i + 1) + "违规",
                  icon: "success",
                  duration: 2e3,
                });
          },
          fail: (a) => {
            o++, console.log("fail:" + i + "fail:" + o), wx.hideLoading();
          },
          complete: () => {
            console.log(i),
              ++i == a.path.length
                ? (console.log("执行完毕"),
                  console.log(t.globalData.files),
                  console.log("成功:" + n + " 失败:" + o),
                  wx.hideLoading())
                : (console.log(i),
                  (a.i = i),
                  (a.success = n),
                  (a.fail = o),
                  e.uploadimgs(a));
          },
        });
    },
    nicknameInput: function (a) {
      this.setData({ nickname: a.detail.value }), console.log(a.detail.value);
    },
    userdata: function () {
      var t = this;
      a.util.getUserInfo(function (a) {
        a.memberInfo
          ? (t.setData({ memberInfo: a.memberInfo }),
            wx.setStorageSync("uid", a.memberInfo.uid),
            t.firstin(a.memberInfo, 0))
          : t.setData({ isShow: !0 });
      });
    },
    hideDialog: function () {
      this.setData({ isShow: !this.data.isShow });
    },
    updateUserInfo: function (t) {
      var e = this;
      console.log("用户数据", t);
      var i = this.data.avatarUrl,
        n = this.data.nickname;
      a.util.getUserInfo(function (a) {
        wx.setStorageSync("uid", a.memberInfo.uid),
          e.hideDialog(),
          e.firstin(a.memberInfo, 0),
          a.util.getUserInfo(function (a) {
            var t = { uid: a.memberInfo.uid, avatar: i, nickname: n };
            e.firstin(t, 1),
              wx.showToast({ icon: "none", title: "登录成功", duration: 2e3 }),
              wx.navigateBack({ delta: 0 });
          });
      }, t.detail);
    },
    getUserProfile(t) {
      if (this.data.nickname)
        if (
          "https://pic.ym23.com/images/196/2022/11/u28R23VB4c92c2i4808JQc4C3Y82O5.png" !=
          this.data.avatarUrl
        ) {
          var e = this.data.avatarUrl,
            i = this.data.nickname,
            n = this;
          console.log("用户数据", t),
            wx.getUserProfile({
              desc: "用于完善会员资料",
              lang: "zh_CN",
              success: (t) => {
                console.log("登录信息", t.userInfo),
                  n.setData({ userInfo: t.userInfo, hasUserInfo: !0 }),
                  a.util.getUserInfo(function (a) {
                    var t = { uid: a.memberInfo.uid, avatar: e, nickname: i };
                    n.firstin(t, 1),
                      wx.showToast({
                        icon: "none",
                        title: "登录成功",
                        duration: 2e3,
                      }),
                      wx.navigateBack({ delta: 0 });
                  });
              },
              fail: (t) => {
                a.util.getUserInfo(function (a) {
                  var t = { uid: a.memberInfo.uid, avatar: e, nickname: i };
                  n.firstin(t, 1),
                    wx.showToast({
                      icon: "none",
                      title: "登录成功",
                      duration: 2e3,
                    }),
                    wx.navigateBack({ delta: 0 });
                });
              },
            });
        } else wx.showModal({ content: "请先获取头像", showCancel: !1 });
    },
    noLogin: function (a) {
      wx.navigateBack({ delta: 0 });
    },
    getUserInfo: function (t) {
      var e = this;
      console.log("用户数据", t),
        a.util.getUserInfo(function (a) {
          wx.setStorageSync("uid", a.memberInfo.uid),
            e.hideDialog(),
            e.firstin(a.memberInfo, 1);
        }, t.detail);
    },
    binding: function () {
      var t = this;
      a.util.request({
        url: "entry/wxapp/Api",
        data: {  do: "sjtouxian" },
        success: function (a) {
          console.log(a),
            200 == a.data.data.code &&
              t.setData({ avatarUrl: a.data.data.imgurl });
        },
      });
    },
    firstin: function (t, e) {
      var i = this;
      console.log("提交数据", t),
        a.util.request({
          url: "entry/wxapp/Api",
          data: {

            r: "me.detail",
            uid: t.uid,
            type: e,
            head_image: t.avatar,
            nickname: t.nickname,
          },
          success: function (a) {
            console.log(a),
              i.setData({
                detail: a.data.data,
                is_member: a.data.data.user.is_member,
                store_img: a.data.data.user.store_img,
              }),
              1 == e && i.userdata();
          },
        });
    },
    onReachBottom: function () {},
  });