Files
oil-client-wechat/pages/updateUser/updateUser.js
2025-12-19 11:20:59 +08:00

166 lines
4.4 KiB
JavaScript

const app = getApp();
const phoneReg = /^((\+|00)86)?1\d{10}$/;
Page({
/**
* 页面的初始数据
*/
data: {
nvabarData: {
showCapsule: 1, //是否显示左上角图标 1表示显示 0表示不显示
title: "编辑站员", //导航栏 中间的标题
},
name: "",
phone: "",
userItem: null,
// 此页面 页面内容距最顶部的距离
height: app.globalData.height * 2 + 20,
confirmName: '',//确认按钮名称
confirmBtn: false,//按钮颜色变化
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
const userItem = JSON.parse(options.queryBean) || null;
this.setData({
userItem,
["nvabarData.title"]: userItem ? "编辑站员" : "添加站员",
confirmName: userItem ? "修改" : "添加",
name: userItem ? userItem.name : "",
phone: userItem ? userItem.phone : "",
});
},
bindNameInput(e) {
this.setData({
name: e.detail.value,
});
this.isConfirmBtn()
},
bindPhoneInput(e) {
this.setData({
phone: e.detail.value,
});
this.isConfirmBtn()
},
isConfirmBtn() {
if (this.data.name != '' && this.data.phone != '') {
this.setData({
confirmBtn: true
});
}
},
cancelBtnHandle() {
wx.navigateBack();
},
confirmBtnHandle() {
if (!this.data.name) {
wx.showModal({
title: "提示",
content: "请输入姓名!",
showCancel: false,
});
return;
}
if (!this.data.phone) {
wx.showModal({
title: "提示",
content: "请输入手机号!",
showCancel: false,
});
return;
}
if (this.data.phone && !phoneReg.test(this.data.phone)) {
wx.showModal({
title: "提示",
content: "请输入正确的手机号!",
showCancel: false,
});
return;
}
const cooId = wx.getStorageSync("cooperation").id;
let params = {};
if (this.data.userItem) {
params.id = this.data.userItem.id;
}
params.cooId = cooId;
params.parentUserId = wx.getStorageSync("cooperation").userId;
params.name = this.data.name;
params.phone = this.data.phone;
params.userType = 1;
this.upadteUserHandle(params);
},
upadteUserHandle(params) {
wx.request({
url: app.globalData.devUrl + `/zx/user/create-or-update/user`,
method: `post`,
header: {
"content-type": "application/x-www-form-urlencoded",
},
data: {
...params,
},
success: function (res) {
if (res.data.code == "0000") {
wx.showModal({
title: "提示",
content: "操作成功",
showCancel: false,
});
wx.navigateBack();
} else {
wx.showModal({
title: "提示",
content: res.data.msg,
showCancel: false,
});
}
},
error: function () {
console.log(res);
},
fail: function (data) {
wx.showModal({
title: "提示",
content: "网络传输异常",
showCancel: false,
});
},
});
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() { },
/**
* 生命周期函数--监听页面显示
*/
onShow() { },
/**
* 生命周期函数--监听页面隐藏
*/
onHide() { },
/**
* 生命周期函数--监听页面卸载
*/
onUnload() { },
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() { },
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() { },
/**
* 用户点击右上角分享
*/
onShareAppMessage() { },
});