YZProjectCloud/yanzhu-ui-app/miniprogram/pages/components/user-infos/index.js

198 lines
4.2 KiB
JavaScript

import { removeToken } from "../../../utils/auth";
import { loginOut, updatePwd, findOpenUserMsgId } from "../../../api/login";
import cfg from "../../../config";
const app = getApp();
Component({
/**数据监听 */
observers: {},
/**
* 组件的初始数据
*/
data: {
show: false,
userData: {},
resPas: false,
oldPsw: "",
newPsw: "",
password: "",
showOldPass: true,
showNewPass: true,
showPassWord: true,
binding: false,
msgOpenId: "",
baseImgUrl: cfg.baseImgUrl,
},
created() {
this.setData({
userData: app.globalData.userData,
loginName: app.globalData.userData.userName,
msgOpenId: "",
});
},
/**
* 组件的方法列表
*/
methods: {
loadUserInfo() {
let that = this;
//获取缓存数据
wx.getStorage({
key: "userinfo",
success: function (res) {
findOpenUserMsgId(res.data.openId).then((vo) => {
if (vo.code == 200 && vo.data) {
res.data.msgOpenId = vo.data.msgOpenId;
wx.setStorage({
key: "userinfo",
data: res.data,
});
that.setData({
show: true,
userData: res.data,
loginName: res.data.loginName,
msgOpenId: res.data.msgOpenId || "",
});
}
});
},
});
},
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: cfg.baseImgUrl + "/cdn/appimgs/qrv1.jpg".split(","),
current: 0,
});
},
//退出登录
loginOut: function () {
loginOut().then((res) => {
removeToken();
wx.clearStorageSync();
wx.navigateTo({
url: "/pages/login/login",
});
});
},
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.password == "") {
app.toast("请确认新密码!");
return;
}
if (that.data.newPsw != "" && that.data.newPsw != that.data.password) {
app.toast("两次密码输入不一致!");
return;
}
if (that.data.newPsw.length < 6) {
app.toast("请输入新密码长度 [6-20]位字符!");
return;
}
if (that.data.password.length < 6) {
app.toast("请输入确认密码长度 [6-20]位字符!");
return;
}
let data = {
loginName: that.data.loginName,
oldPass: that.data.oldPsw,
password: that.data.newPsw,
confPass: that.data.password,
source: "u",
};
updatePwd(data).then((res) => {
if (res.code == 200) {
app.toast("密码修改成功,请重新登录!", 800);
loginOut().then((res) => {
removeToken();
wx.clearStorageSync();
setTimeout(() => {
wx.redirectTo({
url: "../login/login",
});
}, 500);
});
}
});
},
},
});