Files
2021-11-01 09:24:11 +08:00

250 lines
5.0 KiB
JavaScript

// pages/meeting/meeting.js
import UserApi from '../../assets/js/http/userApi'
Page({
/**
* 页面的初始数据
*/
data: {
userId: '',
form: {
name: '',
companyName: '',
post: '',
gender: null,
phone: '',
contactAddress: '',
email: '',
postalCode: '',
remarks: ''
},
isDisabled: true,
selects: [ // 自定义选择框参数
{
select: '状态',
active: false,
tabIndex: 1
},
{
select: '会议类型',
active: false,
tabIndex: 2
},
{
select: '时间',
active: false,
tabIndex: 3
}
],
sexArr: [{
value: '1',
name: '男',
checked: ''
},
{
value: '2',
name: '女',
checked: ''
}
]
},
postInput(e) {
this.setData({
"form.post": e.detail.value
})
},
contactAddressInput(e) {
this.setData({
"form.contactAddress": e.detail.value
})
},
postalCodeInput(e) {
this.setData({
"form.postalCode": e.detail.value
})
},
remarksInput(e) {
this.setData({
"form.remarks": e.detail.value
})
},
// 编辑
editForm() {
this.setData({
isDisabled: false
})
// 性别处理
if (this.data.form.gender == '1') {
this.data.sexArr[0].checked = "true"
this.setData({
sexArr: this.data.sexArr,
})
}
if (this.data.form.gender == '2') {
this.data.sexArr[1].checked = "true"
this.setData({
sexArr: this.data.sexArr,
})
}
},
// 提交
formSubmit(e) {
let flag = false
// 通讯地址校验
if (!e.detail.value.contactAddress) {
wx.showToast({
title: '请输入通讯地址',
icon: 'none'
})
flag = false
return
} else {
flag = true
}
// 邮箱校验
if(e.detail.value.email){
let isEmail = /^\w[-\w.+]*@([A-Za-z0-9][-A-Za-z0-9]+\.)+[A-Za-z]{2,14}/.test(e.detail.value.email)
if (!isEmail) {
wx.showToast({
title: '邮箱格式不正确',
icon: 'none'
})
flag = false
return
} else {
flag = true
}
}else{
wx.showToast({
title: '请输入邮箱',
icon: 'none'
})
flag = false
return
}
// 邮政编码校验
if (e.detail.value.postalCode) {
let isPost = /^[0-9]\d{5}$/.test(e.detail.value.postalCode)
if (!isPost) {
wx.showToast({
title: '邮政编码格式不正确',
icon: 'none'
})
flag = false
return
} else {
flag = true
}
}else{
wx.showToast({
title: '请输入邮政编码',
icon: 'none'
})
flag = false
return
}
let params = Object.assign(this.data.form, e.detail.value)
this.setData({
form: params
})
params.id = this.data.userId
if (flag) {
UserApi.editMineInfo(params).then(res => {
if (res.success) {
wx.showToast({
title: res.result,
})
// 编辑成功之后,显示查看页
this.setData({
isDisabled: true
})
}else{
wx.showToast({
title: res.message,
icon: 'none',
duration: 2000
})
}
}).catch(err => {
wx.showToast({
title: '加载失败',
icon: 'none',
duration: 2000
})
})
} else {
wx.showToast({
title: '检查表单是否填写正确',
})
}
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
wx.showToast({
title: '加载中...',
icon: 'loading'
})
const that = this
let userInfo = wx.getStorageSync('userInfo')
that.setData({
userId: userInfo.id
})
UserApi.mineInfo({
id: this.data.userId
}).then(res => {
if(res.success){
if(res.result.gender){
res.result.gender = res.result.gender.toString()
}
this.setData({
form: res.result
})
// 性别处理
if (this.data.form.gender == '1') {
this.data.sexArr[0].checked = "true"
this.setData({
sexArr: this.data.sexArr,
})
}
if (this.data.form.gender == '2') {
this.data.sexArr[1].checked = "true"
this.setData({
sexArr: this.data.sexArr,
})
}
}else{
wx.showToast({
title: res.message,
icon: 'none',
duration: 2000
})
}
}).catch(err => {
wx.showToast({
title: '加载失败',
icon: 'none',
duration: 2000
})
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
}
})