// pages/shop/apply/index.js import { saveFactory } from "../../../api/ztb" const util = require('../../../utils/util') import regions from '../../../utils/region' const app = getApp() Page({ /** * 页面的初始数据 */ data: { safeBottom: app.globalData.safeBottom, options: regions, region: [], form: {}, locateCityTag: {}, requesting: false }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { // var locateCityTag = app.globalData.userInfo.locateCityTag this.setData({ safeBottom: app.globalData.safeBottom, ['form.packageFactoryName']: app.globalData.userInfo.packageFactoryName }) }, bindInput: function(e){ this.data.form[e.target.id] = e.detail.value }, showRegion: function(){ this.cascaderView = this.cascaderView || this.selectComponent('#wux-cascader') this.cascaderView.showPicker(this.data.region) }, onRegionChange: function (e) { if (e.detail && e.detail.options) { this.setData({ ['form.areaStr']: e.detail.options.map((n) => n.label).join(' '), region: e.detail.value }) this.data.locateCityTag['provinceId'] = e.detail.value[0] this.data.locateCityTag['cityId'] = e.detail.value[1] this.data.locateCityTag['districtId'] = e.detail.value[2] this.data.form['locDistrictId'] = e.detail.value[2] } }, submitForm: function(){ if(this.data.requesting){ return } if(util.isEmpty(this.data.form.packageFactoryName)){ util.showToast('请输入工厂全称') return } // if(util.isEmpty(this.data.form.locDistrictId)){ // util.showToast('请选择所在区域') // return // } // if(util.isEmpty(this.data.form.locDetail)){ // util.showToast('请输入详细地址') // return // } // if(util.isEmpty(this.data.form.consignor)){ // util.showToast('请输入发货人姓名') // return // } this.data.requesting = true wx.showLoading({ title: '处理中', mask: true }) saveFactory(this.data.form).then(res => { wx.hideLoading() app.globalData.userInfo.hasShipmentsInfo = true const channel = this.getOpenerEventChannel() channel.emit('onCallback', { what: 1030 }) util.showBackToast('发货信息已填写') }).catch(err => { wx.hideLoading() this.data.requesting = false util.showToast(err) }) } })