let time = null; const _Http = getApp().globalData.http; const MD5 = require('../../../../utils/md5'); Page({ /** * 页面的初始数据 */ data: { attinfos: [], fromList1: [{ label: "姓名", error: false, errMsg: "", type: "text", value: "", placeholder: "请填写", valueName: "name", //绑定的字段名称 required: true, //必填 }, { label: "手机号", error: false, errMsg: "", type: "text", value: "", placeholder: "请填写", valueName: "phonenumber", //绑定的字段名称 required: true, //必填 callback: null, }], disabled: false, //禁用按钮 show: false, //显示验证码输入框 password: "", //验证码 countDown: 0, //倒计时 loading: false }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { const that = this; this.setData({ attinfos: JSON.parse(options.attinfos), "fromList1[0].value": options.name, "fromList1[1].value": options.phonenumber, "fromList1[1].callback": function ({ value }) { that.setData({ show: (value != that.data.copyPhonenumber) ? true : false, newPhone: value }) }, "copyPhonenumber": options.phonenumber }) }, /* from1监听 */ form1CompletedOrNot({ detail }) { this.setData({ disabled: !detail }) if (this.data.show) this.setData({ disabled: this.data.password.length == 6 }) }, /* 开始倒计时 */ startCountDown() { let countDown = this.data.countDown; if (countDown != 0) return wx.showToast({ title: '已发送验证码,请勿重新发送', icon: "none" }); if (this.data.newPhone.trim().length != 11) return wx.showToast({ title: '请输入正常手机号码', icon: "none" }) _Http.basic({ "classname": "common.usercenter.usercenter", "method": "updateUserMsg_getPassWord", "content": { "phonenumber": this.data.newPhone.trim() } }).then(res => { console.log(res) wx.showToast({ title: res.msg, icon: "none" }) if (res.code != 1) return; this.setData({ countDown: 30 }) time = setInterval(() => { if (this.data.countDown == '0') return clearInterval(time); this.setData({ countDown: this.data.countDown - 1 }) }, 1000); }) }, /* 提交 */ submit() { if (this.data.disabled || this.data.loading) return; let data = this.selectComponent("#form1").getData().returnData; if (data.phonenumber.length != 11) return wx.showToast({ title: '请输入正常手机号码', icon: "none" }); if (this.data.show && this.data.password.length == 0) return wx.showToast({ title: '请输入短信验证码', icon: "none" }); this.setData({ loading: true }) _Http.basic({ "classname": "common.usercenter.usercenter", "method": "updateUserMsg", "content": { "name": data.name, "phonenumber": data.phonenumber, "password": MD5.hexMD5(this.data.password.trim()) } }).then(res => { this.setData({ loading: false }) if (res.code != 1) return wx.showToast({ title: res.msg, icon: "none" }); wx.showToast({ title: '修改成功' }); this.changeUserMsg(); setTimeout(() => { wx.navigateBack({ delta: 0, }) }, 300); }) }, changeUserMsg() { let pages = getCurrentPages(); let prevPage = pages[pages.length - 2]; prevPage.queryUserMsg(); }, changeUserImage({ detail }) { _Http.basic({ "classname": "system.attachment.Attachment", "method": "createFileLink", "content": { "ownertable": "sys_users", "ownerid": wx.getStorageSync('userMsg').userid, "usetype": "headportrait", "attachmentids": detail } }).then(res => { console.log(res) if (res.msg != '成功') return wx.showToast({ title: res.data, icon: "none" }) let attinfos = this.data.attinfos; if (attinfos[0]) _Http.basic({ "classname": "system.attachment.Attachment", "method": "deleteFileLink", "content": { "linksids": [attinfos[0].linksid] } }); attinfos = res.data; this.setData({ attinfos }) this.changeUserMsg(); }) }, })