jhwxapp/miniprogram/pages/components/user-infos/index.js

193 lines
4.0 KiB
JavaScript

import {
removeToken
} from '../../../utils/auth'
import {
loginOut
} from '../../../api/login'
const app = getApp()
Component({
/**数据监听 */
observers: {},
/**
* 组件的初始数据
*/
data: {
show: false,
userData: {},
resPas: false,
oldPsw: '',
newPsw: '',
password: '',
showOldPass: true,
showNewPass: true,
showPassWord: true,
binding: false,
},
created() {
let that = this;
//获取缓存数据
wx.getStorage({
key: 'userinfo',
success: function (res) {
that.setData({
userData: res.data,
loginName: res.data.loginName,
})
}
})
},
/**
* 组件的方法列表
*/
methods: {
showPopup() {
this.setData({
show: true
});
},
/**
* 关闭用户详情
*/
closePopup() {
this.setData({
show: false
});
},
//修改密码
resPassword: function () {
this.setData({
resPas: true
});
},
//绑定公众号
binding: function () {
app.initWxAuth();
},
/**
* 修改密码返回
*/
closeResPas: function () {
this.setData({
resPas: false
});
},
/**
* 修改密码返回
*/
closeBinding: function () {
this.setData({
binding: false
});
},
bindingBuild: function () {
wx.previewImage({
urls: "https://szgcwx.jhncidg.com/staticFiles/qr.jpg".split(","),
current: 0
})
},
//退出登录
loginOut: function () {
loginOut({}).then(res => {
removeToken();
});
wx.clearStorageSync();
wx.setStorageSync('isReload', "1")
wx.redirectTo({
url: '../login/index',
})
},
seeTap1() {
let that = this;
that.setData({
// 切换图标
showOldPass: !that.data.showOldPass
})
},
seeTap2() {
let that = this;
that.setData({
// 切换图标
showNewPass: !that.data.showNewPass
})
},
seeTap3() {
let that = this;
that.setData({
// 切换图标
showPassWord: !that.data.showPassWord
})
if (that.data.newPsw != '' && that.data.newPsw != that.data.password) {
app.toast("两次密码输入不一致!");
}
},
/**
* 添加预警信息
*/
submit: function () {
var that = this;
if (that.data.oldPsw == '') {
app.toast("请输入旧密码!");
return;
}
if (that.data.password == '') {
app.toast("请确认新密码!");
return;
}
if (that.data.newPsw != '' && that.data.newPsw != that.data.password) {
app.toast("两次密码输入不一致!");
return;
}
if (that.data.oldPsw.length < 6) {
app.toast("请输入旧密码长度 [6-20]位字符!");
return;
}
if (that.data.newPsw.length < 6) {
app.toast("请输入新密码长度 [6-20]位字符!");
return;
}
if (that.data.password.length < 6) {
app.toast("请输入确认密码长度 [6-20]位字符!");
return;
}
wx.request({
header: {
'content-type': 'application/x-www-form-urlencoded'
},
url: app.globalData.reqUrl + '/wechat/updatePassword',
data: {
loginName: that.data.loginName,
oldPsw: that.data.oldPsw,
newPsw: that.data.newPsw,
password: that.data.password
},
method: "POST",
success: function (res) {
if (res.data && res.data.data == "200") {
removeToken();
wx.clearStorageSync();
wx.setStorageSync('isReload', "1");
app.toast("密码修改成功!");
wx.redirectTo({
url: '../login/index',
});
} else {
app.toast(res.data.info);
return;
}
}
})
},
}
})