纸通宝SAAS仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

110 lines
3.1 KiB

// pages/enterprise/address-new/index.js
import { deleteAddress, saveAddress } from "../../api/user"
const util = require('../../../utils/util')
const region = require('../../../utils/area')
const storage = require('../../../utils/storage')
const event = require('../../../utils/event')
const app = getApp()
Page({
/**
* 页面的初始数据
*/
data: {
id: null,
show: false,
areaList: region.default,
form: {
receiver:'',
receiverMobile:'',
detail:'',
isDefault: 0,
provinceId: '',
provinceName: '',
cityId: '',
cityName: '',
districtId: '',
districtName: ''
},
requesting: false
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
if(options.id){
this.setData({ id: Number(options.id)})
}
var json = storage.get('gdw-address')
if(json){
storage.remove('gdw-address')
var form = JSON.parse(json)
form.areaStr = form.provinceName + ' ' + form.cityName + ' ' + form.districtName
this.setData({ form: form})
}
},
showRegion: function(){
if(this.data.disabled){
return
}
this.setData({ show: true })
},
bindinput: function(e){
this.data.form[e.target.id] = e.detail.value
},
onChange: function({ detail }) {
// 需要手动对 checked 状态进行更新
this.setData({ ['form.isDefault']: detail ? 1 : 0 })
},
onConfirm: function({ detail }){
this.data.form.enterpriseId = app.accountInfo.enterpriseId
this.data.form.provinceId = detail.values[0].code
this.data.form.provinceName = detail.values[0].name
this.data.form.cityId = detail.values[1].code
this.data.form.cityName = detail.values[1].name
this.data.form.districtId = detail.values[2].code
this.data.form.districtName = detail.values[2].name
var areaStr = detail.values[0].name + ' ' + detail.values[1].name + ' ' + detail.values[2].name
this.setData({ show: false, ['form.areaStr']: areaStr })
},
deleteForm: function(){
wx.showLoading({ title: '处理中', mask: true })
deleteAddress(this.data.form.id).then(result => {
wx.hideLoading()
event.emit('EventMessage', { what: 40, desc: 'Address' })
util.showBackToast('地址已删除')
}).catch(err => {
wx.hideLoading()
})
},
submitForm: function () {
if(util.isEmpty(this.data.form.receiver)){
util.showToast('请输入联系人')
return
}
if(util.isEmpty(this.data.form.receiverMobile)){
util.showToast('请输入联系电话')
return
}
if(util.isEmpty(this.data.form.districtId)){
util.showToast('请选择所在地区')
return
}
if(util.isEmpty(this.data.form.detail)){
util.showToast('请输入详细地址')
return
}
wx.showLoading({ title: '处理中', mask: true })
saveAddress(this.data.form).then(result => {
wx.hideLoading()
event.emit('EventMessage', { what: 40, desc: 'Address' })
util.showBackToast('添加成功')
}).catch(err => {
wx.hideLoading()
util.showToast(err)
})
},
onClose: function() {
this.setData({ show: false })
}
})