const app = require('../../utils/util.js');
var util = require('../../utils/md5.js')
Page({
  data: {
    defaultType1: true,
    passwordType1: true,

    defaultType2: true,
    passwordType2: true,

    defaultType3: true,
    passwordType3: true,

    info: {},
  },
  eyeStatus1() {
    if (this.data.defaultType1) {
      this.setData({
        passwordType1: false,
        defaultType1: false,
      })
    } else {
      this.setData({
        passwordType1: true,
        defaultType1: true,
      })
    }
  },

  eyeStatus2() {
    if (this.data.defaultType2) {
      this.setData({
        passwordType2: false,
        defaultType2: false,
      })
    } else {
      this.setData({
        passwordType2: true,
        defaultType2: true,
      })
    }
  },

  eyeStatus3() {
    if (this.data.defaultType3) {
      this.setData({
        passwordType3: false,
        defaultType3: false,
      })
    } else {
      this.setData({
        passwordType3: true,
        defaultType3: true,
      })
    }
  },
  formSubmit(e) {
    console.log(e.detail, "daying");
    if (e.detail.value.oldPwd) {
      if (e.detail.value.pwd) {
        if (e.detail.value.newPwd) {
          if (e.detail.value.pwd.toString().length > 5) {
            if (e.detail.value.pwd == e.detail.value.newPwd) {
              wx.request({
                url: app.globalData.publicUrl + '/applet/updatePwd',
                method: "GET",
                header: {
                  appletsId: wx.getStorageSync('openId')
                },
                data: e.detail.value,
                success: (res) => {
                  if (res.data.code == 0) {
                    wx.showModal({
                      showCancel: false,
                      content: '密码已修改',
                      success: () => {
                        wx.switchTab({
                          url: '/pages/index/index',
                        })
                      }
                    })
                  } else if(res.data.code == 1) {
                    wx.showToast({
                      title: "修改失败,原密码不正确",
                      icon: 'none',
                      duration: 2000,
                    })
                  }else{
                    wx.showToast({
                      title: "修改失败,请联系管理员",
                      icon: 'none',
                      duration: 2000,
                    })
                  }
                }
              })
            } else {
              wx.showToast({
                title: "两次输入密码不一致",
                icon: 'none',
                duration: 2000,
              })
            }
          } else {
            wx.showToast({
              title: "密码长度最少为6位",
              icon: 'none',
              duration: 2000,
            })
          }
        } else {
          wx.showToast({
            title: "在输入新密码不能为空",
            icon: 'none',
            duration: 2000,
          })
        }
      } else {
        wx.showToast({
          title: "新密码不能为空",
          icon: 'none',
          duration: 2000,
        })
      }
    } else {
      wx.showToast({
        title: "原密码不能为空",
        icon: 'none',
        duration: 2000,
      })
    }

  },
  onLoad: function () {
    wx.request({
      url: app.globalData.publicUrl + '/applet/findUserInfo',
      method: "GET",
      header: {
        appletsId: wx.getStorageSync('openId')
      },
      success: (res) => {
        console.log(res, "000");
        this.setData({
          info: res.data.data
        })
      }
    })
  },
})