var a, t;
(a = getApp()),
  (t = getApp()),
  Page({
    data: {
      isShow: !1,
      canIUseGetUserProfile: !1,
      userInfo: [],
      avatarUrl: "",
      loginBanner: "",
      nickname: "",
    },
    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();
    },
    updateNackname: function (nickname) {
      var i = this;
      a.util.request({
        url: "auth/user/updateNackname",
        data: {
          nickname: nickname,
        },
        success: function (a) {
          console.log(a)
          wx.navigateBack({ delta: 0 });
        },
      });
    },
    loginForm: function (a) {
      a.detail.value.nickname ? this.updateNackname(a.detail.value.nickname) : wx.showModal({ content: "请输入昵称", showCancel: !1 });
    },
    onChooseAvatar(a) {
      const { avatarUrl: e } = a.detail;


      console.log('onChooseAvatar', a, e)

      this.setData({ avatarUrl: e });
      var i = [a.detail],
        n = {
          url: t.util.url("auth/avatar/upload"),
          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,
          header: {
            'token': wx.getStorageSync("userInfo").sessionid || ''
          },
          success: (a) => {
            n++, console.log(a), console.log(i);
          },
          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.nickname) {
        var e = this.avatarUrl, i = this.nickname, n = this;

        console.log(i)
      }
      console.log(t)
    },
    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: "auth/user/detail",
          data: {
            uid: t.uid,
            type: e,
            nickname: t.nickname,
          },
          success: function (a) {
            console.log(a),
              i.setData({
                detail: a.data.data,
                avatarUrl: a.data.data.user.avatar,
                is_member: a.data.data.is_member,
                store_img: a.data.data.store_img,
              }),
              1 == e && i.userdata();
          },
        });
    },
    onReachBottom: function () { },
  });