// pages/home/tab2/index.js import { updateUserInfo, getBaseInfo } from '../../../api/ztb' import regions from '../../../const/region' Page({ /** * 页面的初始数据 */ data: { options: regions, region: [440000, ''], form: { bidType: 1, areaStr: '' }, cateName: '', dopantName: '', waterName: '', intervalName: '', sumAmount: 0, keyboard: 0, toView: '', focus: false, picking: false }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.getUerInfoFct() this.cascaderView = this.cascaderView || this.selectComponent('#wux-cascader') this.pickerView = this.pickerView || this.selectComponent('#picker-view') }, toNextTab: function () { wx.redirectTo({ url: '/pages/home/tab3/index' }) }, toMyInfo: function () { wx.navigateBack() }, showRegion: function () { if (this.data.disabled) { return } this.cascaderView.showPicker(this.data.region) this.setData({ picking: true }) }, onRegionChange: function (e) { if (e.detail && e.detail.options) { this.data.form['locProvinceId'] = e.detail.value[0] this.data.form['locProvinceName'] = e.detail.options[0].label this.data.form['locCityId'] = e.detail.value[1] this.data.form['locCityName'] = e.detail.options[1].label this.data.form['locDistrictId'] = e.detail.value[2] this.data.form['locDistrictName'] = e.detail.options[2].label this.setData({ picking: false, ['form.areaStr']: e.detail.options[0].label + e.detail.options[1].label }) this.submitForm({ locateCityTag: this.data.form.locCityId }) } }, submitForm: function (model) { console.log(model) updateUserInfo(model).then(result => { this.data.loopRequesting = false setTimeout(() => this.toNextTab(), 200) }).catch(err => { this.data.loopRequesting = false }) }, getUerInfoFct: function () { getBaseInfo().then(res => { if(res.data.locateCityTag) { this.setData({ region: [res.data.locateCityTag.provinceId, res.data.locateCityTag.cityId, res.data.locateCityTag.districtId], 'form.areaStr': res.data.locateCityTag.provinceName + res.data.locateCityTag.cityName }) } }) } })