// pages/setpwd/setpwd.js
const config = require('../../../config/config.js')
const Common = require("../../../common/common.js")
const app = getApp()

Page({
  data: {
    phone: '',
    yzm: ''
  },
  onLoad(e) {
    this.setData({
      phone: e.phone,
      yzm: e.code
    })
  },
  setPwd(e) {
    let {
      newPwd,
      pwd
    } = e.detail.value
    var regx = /^(?![0-9]+$)(?![a-zA-Z]+$)[a-zA-Z\d]{8,16}$/;
    if (newPwd.match(regx) == null) {
      wx.showToast({
        title: '密码为8-16位字母和数字的组合',
        icon: "none"
        // image: './../../static/images/fail.png',
      })
    } else {
      console.log(newPwd)
      console.log(pwd)
      if (newPwd == pwd) {
        Common.updateUserPassword(this.data.phone, this.data.yzm, newPwd)
          .then(res => {
            if (res.code == 200) {
              wx.showToast({
                title: "修改成功",
                icon: "none",
                duration:1200
              })
              setTimeout(function () {
                wx.reLaunch({
                  url: '/pages/index/index',
                })
              }, 1200)

            } else {
              wx.showToast({
                title: res.message,
                icon: "none"
              })
            }
          })
      } else {
        wx.showToast({
          title: '密码不一致',
          icon: "none"
          // image: './../../static/images/fail.png',
        })
      }
    }
  }
})