纸通宝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.
 

81 lines
2.4 KiB

// pages/enterprise/address/index.js
import Dialog from '../../../components/dialog/dialog'
import { getAddressList, deleteAddress } from "../../api/user"
const event = require('../../../utils/event')
const util = require('../../../utils/util')
const storage = require('../../../utils/storage')
Page({
/**
* 页面的初始数据
*/
data: {
type: 0,
addressList: []
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
if(options.type){
this.data.type = Number(options.type)
}
event.on('EventMessage', this, this.onEvent)
this.fetchAddressList()
},
onEvent: function (message) {
if (message.what == 40) {
this.fetchAddressList()
}
},
fetchAddressList: function(){
wx.showLoading({ title: '加载中', mask: true })
// /product/{id}产品详情
getAddressList().then(result => {
wx.hideLoading()
this.setData({ addressList: result.data})
}).catch(err => {
wx.hideLoading()
})
},
lookItem: function(e){
var item = this.data.addressList[e.currentTarget.dataset.index]
if(this.data.type == 1){
event.emit('EventMessage', { what: 41, obj: item, desc: 'Address' })
wx.navigateBack()
} else {
storage.put('gdw-address', JSON.stringify(item), 1)
wx.navigateTo({ url: '/pages/enterprise/address-new/index?id=' + item.id })
}
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
addAddress: function (e) {
if(e.currentTarget.dataset.index >= 0){
var item = this.data.addressList[e.currentTarget.dataset.index]
storage.put('gdw-address', JSON.stringify(item), 1)
wx.navigateTo({ url: '/pages/enterprise/address-new/index?id=' + item.id })
} else {
wx.navigateTo({ url: '/pages/enterprise/address-new/index' })
}
},
delAddress: function(e){
var item = this.data.addressList[e.currentTarget.dataset.index]
var that = this
Dialog.confirm({ title: '温馨提示', message: '确定删除该地址?' }).then(() => {
wx.showLoading({ title: '处理中', mask: true })
deleteAddress(item.id).then(result => {
wx.hideLoading()
util.showToast('地址已删除')
that.fetchAddressList()
}).catch(err => {
console.log(err)
wx.hideLoading()
})
})
},
onUnload: function(){
event.remove('EventMessage', this)
}
})