181 lines
4.0 KiB
JavaScript
181 lines
4.0 KiB
JavaScript
|
// index.js
|
||
|
var myRequest = require("../../utils/api.js");
|
||
|
import {
|
||
|
areaList
|
||
|
} from '@vant/area-data';
|
||
|
|
||
|
Page({
|
||
|
data: {
|
||
|
value: '',
|
||
|
areaList,
|
||
|
areaValue: '',
|
||
|
nickName: '',
|
||
|
phonenumber: '',
|
||
|
area: '',
|
||
|
areaData: [],
|
||
|
bankCardNumber: '',
|
||
|
bankName: '',
|
||
|
identityNumber: '',
|
||
|
role: '',
|
||
|
|
||
|
},
|
||
|
onLoad() {
|
||
|
this.getUserInfo()
|
||
|
},
|
||
|
getUserInfo() {
|
||
|
let that = this;
|
||
|
myRequest.myRequest('getInfo', {}, 'get').then(res => {
|
||
|
console.log(res)
|
||
|
let {
|
||
|
role,
|
||
|
areaCode,
|
||
|
cityCode,
|
||
|
provinceCode,
|
||
|
areaName,
|
||
|
cityName,
|
||
|
provinceName,
|
||
|
nickName,
|
||
|
identityNumber,
|
||
|
bankCardNumber,
|
||
|
bankName,
|
||
|
phonenumber
|
||
|
} = res.data.user
|
||
|
that.setData({
|
||
|
role,
|
||
|
user: res.data.user,
|
||
|
area: `${provinceName}-${cityName}-${areaName}`,
|
||
|
areaValue: areaCode,
|
||
|
areaData:[{name:provinceName,code:provinceCode},{name:cityName,code:cityCode},{name:areaName,code:areaCode}],
|
||
|
bankName,
|
||
|
bankCardNumber,
|
||
|
identityNumber,
|
||
|
nickName,
|
||
|
phonenumber
|
||
|
})
|
||
|
|
||
|
|
||
|
})
|
||
|
},
|
||
|
onChange(e) {
|
||
|
console.log(e)
|
||
|
let key = e.target.dataset.key
|
||
|
this.setData({
|
||
|
[key]: e.detail
|
||
|
})
|
||
|
|
||
|
},
|
||
|
showCity(e) {
|
||
|
console.log('111')
|
||
|
this.setData({
|
||
|
show: true
|
||
|
})
|
||
|
},
|
||
|
setArea(){},
|
||
|
onChangeArea(e) {
|
||
|
let area = e.detail.values.reduce((pre, cur) => {
|
||
|
return {
|
||
|
name: pre.name + '-' + cur.name
|
||
|
}
|
||
|
})
|
||
|
console.log(e)
|
||
|
|
||
|
|
||
|
this.setData({
|
||
|
areaData: e.detail.values,
|
||
|
areaValue: e.detail.values[2].code,
|
||
|
show: false,
|
||
|
area: area.name
|
||
|
})
|
||
|
},
|
||
|
closeArea() {
|
||
|
this.setData({
|
||
|
show: false
|
||
|
})
|
||
|
},
|
||
|
apply() {
|
||
|
|
||
|
if (!this.data.nickName) {
|
||
|
wx.showToast({
|
||
|
title: '请输入姓名',
|
||
|
icon: 'none'
|
||
|
})
|
||
|
return
|
||
|
}
|
||
|
|
||
|
let param = {
|
||
|
|
||
|
nickName: this.data.nickName,
|
||
|
|
||
|
}
|
||
|
if (this.data.role != 'customer') {
|
||
|
if (this.data.areaData.length == 0) {
|
||
|
wx.showToast({
|
||
|
title: '请选择合适的售后区域',
|
||
|
icon: 'none'
|
||
|
})
|
||
|
return
|
||
|
}
|
||
|
if (this.data.areaData.length == 0) {
|
||
|
wx.showToast({
|
||
|
title: '请选择合适的售后区域',
|
||
|
icon: 'none'
|
||
|
})
|
||
|
return
|
||
|
}
|
||
|
const reg = /^[1-9]\d{5}(19|20)\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[Xx\d]$/
|
||
|
if (!reg.test(this.data.identityNumber)) {
|
||
|
wx.showToast({
|
||
|
title: '请输入正确的身份证',
|
||
|
icon: 'none'
|
||
|
})
|
||
|
return
|
||
|
}
|
||
|
// 定义银行卡号的正则表达式
|
||
|
|
||
|
if (!this.data.bankName) {
|
||
|
wx.showToast({
|
||
|
title: '请输入开户行',
|
||
|
icon: 'none'
|
||
|
})
|
||
|
return
|
||
|
}
|
||
|
const bankCardRegex = /^([1-9]{1})(\d{15}|\d{16}|\d{18})$/;
|
||
|
if (!bankCardRegex.test(this.data.bankCardNumber)) {
|
||
|
wx.showToast({
|
||
|
title: '请输入正确的银行卡号',
|
||
|
icon: 'none'
|
||
|
})
|
||
|
return
|
||
|
}
|
||
|
param = {
|
||
|
...param,
|
||
|
provinceCode: this.data.areaData[0].code,
|
||
|
provinceName: this.data.areaData[0].name,
|
||
|
cityCode: this.data.areaData[1].code,
|
||
|
cityName: this.data.areaData[1].name,
|
||
|
areaCode: this.data.areaData[2].code,
|
||
|
areaName: this.data.areaData[2].name,
|
||
|
bankCardNumber: this.data.bankCardNumber,
|
||
|
bankName: this.data.bankName,
|
||
|
identityNumber: this.data.identityNumber
|
||
|
}
|
||
|
}
|
||
|
|
||
|
myRequest.myRequest('updateProfile', param, 'post').then(res => {
|
||
|
let userInfo ={...wx.getStorageSync('userInfo'),...param}
|
||
|
wx.setStorageSync('userInfo', userInfo)
|
||
|
|
||
|
|
||
|
|
||
|
wx.showToast({
|
||
|
title: '修改成功',
|
||
|
icon: 'none'
|
||
|
})
|
||
|
setTimeout(() => {
|
||
|
wx.navigateBack(-1)
|
||
|
}, 1000);
|
||
|
|
||
|
})
|
||
|
}
|
||
|
|
||
|
})
|