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.
166 lines
4.7 KiB
166 lines
4.7 KiB
// pages/shop/apply/index.js
|
|
import { getAddressInfo, deleteAddress, createAddress, updateAddress } from "../../../api/ztb"
|
|
const util = require('../../../utils/util')
|
|
import regions from '../../../const/region'
|
|
const app = getApp()
|
|
|
|
Page({
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
checked:'',
|
|
shippingAddressId:'',
|
|
options: regions,
|
|
theme: 'energized',
|
|
warning: '注意:店铺资料审核后不可修改,请谨慎填写',
|
|
region: [440000, 440100, 440106],
|
|
form: {
|
|
receiver:'',
|
|
phone:'',
|
|
details:'',
|
|
isDefault:'',
|
|
locProvinceId: '',
|
|
locCityId: '',
|
|
districtId: ''
|
|
},
|
|
requesting: false
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad: function (options) {
|
|
this.cascaderView = this.cascaderView || this.selectComponent('#wux-cascader')
|
|
if(options.storeId){
|
|
this.data.form['storeId'] = options.storeId
|
|
}
|
|
this.setData({
|
|
type: options.type,
|
|
shippingAddressId:options.shippingAddressId,
|
|
['form.receiver']: app.globalData.userInfo.realName,
|
|
['form.phone']: app.globalData.userInfo.mobile
|
|
})
|
|
if(this.data.type==0){
|
|
this.setData({ shippingAddressId:options.shippingAddressId })
|
|
this.getAdressDetails(options.shippingAddressId)
|
|
}
|
|
},
|
|
bindinput: function(e){
|
|
this.data.form[e.target.id] = e.detail.value
|
|
},
|
|
showRegion: function(){
|
|
if(this.data.disabled){
|
|
return
|
|
}
|
|
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.form['locProvinceId'] = e.detail.value[0]
|
|
this.data.form['locCityId'] = e.detail.value[1]
|
|
this.data.form['districtId'] = e.detail.value[2]
|
|
}
|
|
},
|
|
|
|
submitForm: function(){
|
|
if(util.isEmpty(this.data.form.receiver)){
|
|
util.showToast('请输入收货人')
|
|
return
|
|
}
|
|
if(util.isEmpty(this.data.form.phone)){
|
|
util.showToast('请输入手机号')
|
|
return
|
|
}
|
|
if(util.isEmpty(this.data.form.districtId)){
|
|
util.showToast('请选择店铺所在区域')
|
|
return
|
|
}
|
|
if(util.isEmpty(this.data.form.details)){
|
|
util.showToast('请输入店铺详细地址')
|
|
return
|
|
}
|
|
if(util.isEmpty(this.data.form.isDefault)){
|
|
util.showToast('请确定是否默认')
|
|
return
|
|
}
|
|
this.createAdress()
|
|
},
|
|
/**
|
|
* 新增收获地址列表
|
|
*/
|
|
createAdress:function(){
|
|
wx.showLoading({ title: '处理中', mask: true })
|
|
if(this.data.type == 1){
|
|
createAddress(this.data.form).then(res => {
|
|
wx.hideLoading()
|
|
util.showBackToast('新增地址成功')
|
|
}).catch(err => {
|
|
wx.hideLoading()
|
|
util.showToast(err)
|
|
})
|
|
}else if(this.data.type==0){
|
|
updateAddress('/recycle-service/update/shipping-address',this.data.form).then(res => {
|
|
wx.hideLoading()
|
|
util.showBackToast('编辑地址成功')
|
|
}).catch(err => {
|
|
wx.hideLoading()
|
|
util.showToast(err)
|
|
})
|
|
}
|
|
},
|
|
/**
|
|
* 获取收货地址详情
|
|
*/
|
|
getAdressDetails:function(shippingAddressId){
|
|
getAddressInfo(shippingAddressId).then(res => {
|
|
this.setData({
|
|
// ['form.areaStr']: e.detail.options.map((n) => n.label).join(' '),
|
|
// region: e.detail.value
|
|
['form.receiver']:res.data.receiver,
|
|
['form.phone']:res.data.phone,
|
|
['form.details']:res.data.details,
|
|
['form.isDefault']:res.data.isDefault,
|
|
['form.districtId']:res.data.districtId,
|
|
['form.shippingAddressId']:res.data.shippingAddressId,
|
|
checked: res.data.isDefault+'',
|
|
region:[res.data.provinceId, res.data.cityId, res.data.districtId]
|
|
})
|
|
this.cascaderView.getCurrentOptions(this.data.region, true)
|
|
}).catch(err => {
|
|
util.showToast(err)
|
|
})
|
|
},
|
|
onRegionInit: function (e) {
|
|
// if (this.data.form.locDistrictId && e.detail.length == 3) {
|
|
this.setData({ ['form.areaStr']: e.detail.map((n) => n.label).join(' ') })
|
|
// }
|
|
},
|
|
radiochange:function(e){
|
|
this.setData({ ['form.isDefault']:e.detail.value })
|
|
},
|
|
hideModal(e) {
|
|
this.setData({ modalName: null })
|
|
},
|
|
sureModal(e){
|
|
deleteAddress({shippingAddressId:this.data.shippingAddressId}).then(res => {
|
|
if(res.code==0){
|
|
util.showToast('删除地址成功!')
|
|
this.setData({ modalName: null })
|
|
wx.navigateBack()
|
|
}else{
|
|
util.showToast('删除地址失败!原因:'+res.message)
|
|
}
|
|
}).catch((e) => {
|
|
console.log(e)
|
|
})
|
|
},
|
|
showModal(e) {
|
|
this.setData({ modalName: e.currentTarget.dataset.target })
|
|
}
|
|
})
|