nantai-erp-wechat-mobile/dispatcher/pages/mine/setting.js
2024-10-31 21:29:57 +08:00

119 lines
2.1 KiB
JavaScript

// driver/pages/mine/setting.js
const app = getApp()
Page({
/**
* 页面的初始数据
*/
data: {
userPhone: '',
userData: null
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
this.getUserData()
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
// 获取用户信息
getUserData: function () {
const url = '/mobile/user_data'
app.AppService.appRequest(url, 'POST', {}, (res) => {
this.setData({
userData: res.data || {},
userPhone: res.data.user_phone || ''
})
})
},
// 修改信息
editUserData: function () {
const userPhone = this.data.userPhone
const url = '/mobile/user_update'
const reg = /^(14[0-9]|13[0-9]|15[0-9]|17[0-9]|18[0-9])\d{8}$$/
if (!userPhone) {
wx.showToast({
title: '手机号不能为空',
icon: 'none'
})
return
} else if (!reg.test(userPhone)) {
wx.showToast({
title: '请输入正确的手机号',
icon: 'none'
})
return
}
app.AppService.appRequest(url, 'POST', {
user_phone: userPhone
}, (res) => {
wx.showToast({
title: '保存成功',
})
var timer = setTimeout(() => {
wx.navigateBack()
clearTimeout(timer)
}, 2000)
})
},
// 改变联系电话
bindChangePhone: function (e) {
this.setData({
userPhone: e.detail.value.trim()
})
},
// 拨打客服电话
makePhoneCall: function (e) {
const phoneNum = e.currentTarget.dataset.phone
wx.makePhoneCall({
phoneNumber: phoneNum
})
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
})