| | |
| | | // pages/design/design.js |
| | | import { |
| | | getDictData, |
| | | getArea, |
| | | saveFreeCustomizationApply |
| | | } from '../../api/index' |
| | | Page({ |
| | | |
| | | /** |
| | |
| | | data: { |
| | | name: '', |
| | | phone: '', |
| | | city: '' |
| | | |
| | | showAreaList: false, |
| | | areaList: [], |
| | | addr: {}, |
| | | fieldNames: { |
| | | text: 'name', |
| | | value: 'id', |
| | | children: 'children', |
| | | }, |
| | | cascaderValue: '', |
| | | |
| | | DESIGN_BANNER: '', |
| | | WechatIMG558: '', |
| | | }, |
| | | onLoad(options) { |
| | | |
| | | this.initData() |
| | | }, |
| | | |
| | | onSubmit() { |
| | | console.log('dd', this.data.name); |
| | | console.log('dd', this.data.phone); |
| | | const { |
| | | name, |
| | | phone, |
| | | addr |
| | | } = this.data |
| | | if (!name) return wx.showToast({ |
| | | title: '请输入姓名', |
| | | icon: 'none' |
| | | }) |
| | | if (!phone) return wx.showToast({ |
| | | title: '请输入联系电话', |
| | | icon: 'none' |
| | | }) |
| | | if (phone.length !== 11) return wx.showToast({ |
| | | title: '请输入正确的联系电话', |
| | | icon: 'none' |
| | | }) |
| | | if (!addr.areaCode || !addr.cityCode) return wx.showToast({ |
| | | title: '请选择城市', |
| | | icon: 'none' |
| | | }) |
| | | saveFreeCustomizationApply({ |
| | | name, |
| | | phone, |
| | | ...addr |
| | | }).then(res => { |
| | | wx.showToast({ |
| | | title: '报名成功' |
| | | }) |
| | | }) |
| | | }, |
| | | selAddress() { |
| | | console.log('点击了'); |
| | | wx.chooseLocation({ |
| | | type: 'wgs84', |
| | | success: (res)=> { |
| | | this.setData({ |
| | | city: res.name |
| | | }) |
| | | console.log('res', res); |
| | | } |
| | | // 显示城市弹窗 |
| | | chooseCity () { |
| | | this.setData({ showAreaList: !this.data.showAreaList }) |
| | | console.log('chooseCity', this.data.showAreaList); |
| | | }, |
| | | onFinish(e) { |
| | | const { selectedOptions, value } = e.detail; |
| | | const addr = { |
| | | provinceCode: selectedOptions[0].id, |
| | | provinceName: selectedOptions[0].name, |
| | | cityCode: selectedOptions[1].id, |
| | | cityName: selectedOptions[1].name, |
| | | areaCode: selectedOptions[2].id, |
| | | areaName: selectedOptions[2].name, |
| | | } |
| | | this.setData({ addr, showAreaList: false }) |
| | | console.log('selectedOptions', addr); |
| | | }, |
| | | // 切换城市 |
| | | // confirmChange(e) { |
| | | // let { |
| | | // values |
| | | // } = e.detail |
| | | // let region = [] |
| | | // for (let i in values) { |
| | | // region.push(values[i].name) |
| | | // } |
| | | // this.setData({ |
| | | // region, |
| | | // cityCode: values[1].code |
| | | // }) |
| | | // this.getShopList() |
| | | // this.chooseCity() |
| | | // }, |
| | | onClose() { |
| | | this.setData({ showAreaList: false }) |
| | | }, |
| | | initData() { |
| | | getArea({ |
| | | "level": "", |
| | | "pid": "" |
| | | }).then(res => { |
| | | this.setData({areaList: res.data}) |
| | | }) |
| | | getDictData({ |
| | | code: 'WEIXIN_DEFAULT_IMGS', |
| | | label: 'DESIGN_BANNER' |
| | | }).then(res => { |
| | | this.setData({ |
| | | DESIGN_BANNER: res.data.code |
| | | }) |
| | | }) |
| | | getDictData({ |
| | | code: 'WEIXIN_DEFAULT_IMGS', |
| | | label: 'WechatIMG558' |
| | | }).then(res => { |
| | | this.setData({ |
| | | WechatIMG558: res.data.code |
| | | }) |
| | | }) |
| | | }, |
| | | onReady() { |