/* * 手太欠 * 愿这世界都如故事里一样 美好而动人~ */ Page({ /** * 页面的初始数据 */ data: { name : '', // 姓名 mobile : '', // 电话 address : '', // 地址 defaultVal: '', // 默认地址 // 省份选择 areasArr : [], areaId : '', areaIndex : 0, // 市级选择 cityArr : [], cityId : 0, cityIndex : 0, // 区域选择 regiArr : [], regiId : 0, regiIndex : 0, disabled : false }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { this.setData({ experience: options.experience }) }, /** * 生命周期函数--监听页面显示 */ onShow() { if(this.data.experience != false) { this.setData({ areaIndex: 18 }) } // 获取省市区列表 this.createInfo(); }, /** * 省市区列表 */ createInfo() { wx.$api.stock.create().then(res => { let areas = res.data, areaIndex = this.data.areaIndex this.setData({ areasArr : areas, areaId : areas[areaIndex].id, }) this.citylist(areas[areaIndex].id) }).catch(err => {}) }, /** * 所在省份-下拉 */ areasChange(e) { let area = this.data.areasArr, index = e.detail.value, atcode = area[index].id if (index != this.data.areaIndex) { this.setData({ areaIndex : index, areaId : atcode }) // 获取市级列表 this.citylist(atcode) } }, /** * 市级列表 */ citylist(cityId) { wx.$api.stock.create({ parent_id: cityId }).then(res=>{ let cityArr = res.data // 从体验官入口进入 默认为深圳 if(this.data.experience) { this.setData({ cityId : cityArr[2].id, cityIndex : 2, cityArr : cityArr }) this.regilist(cityArr[2].id) return } this.setData({ cityId : cityArr[0].id, cityIndex : 0, cityArr : cityArr }) // 获取区级列表 this.regilist(cityArr[0].id) }) }, /** * 市级下拉筛选 */ cityDrop(e) { let city = this.data.cityArr, index = e.detail.value, citycode = city[index].id if (index != this.data.areaIndex) { this.setData({ cityIndex : index, qcityId : citycode }) // 获取市级列表 this.regilist(citycode) } }, /** * 区列表 */ regilist(areaId) { wx.$api.stock.create({ parent_id: areaId }).then(res=>{ this.setData({ regiArr : res.data, regiId : res.data[0].id, regiIndex : 0 }) }) }, /** * 区下拉筛选 */ regiDrop(e) { let newIndex = e.detail.value this.setData({ regiIndex : newIndex, regiId : this.data.regiArr[newIndex].id }) }, // 提交表单 siteform(e) { let value = e.detail.value let data = { name : value.name, mobile : value.mobile, address : value.address, province_id : this.data.areaId, city_id : this.data.cityId, district_id : this.data.regiId } wx.$api.stock.siteAdd(data).then(res => { this.setData({ disabled: true }) wx.navigateBack() }).catch(err => {}) } })