[更新]
This commit is contained in:
102
pages/address/address.js
Normal file
102
pages/address/address.js
Normal file
@@ -0,0 +1,102 @@
|
||||
// pages/address/address.js
|
||||
Page({
|
||||
|
||||
/**
|
||||
* 页面的初始数据
|
||||
*/
|
||||
data: {
|
||||
type : '', //来源类型
|
||||
addressArr : [] //收货地址
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面加载
|
||||
*/
|
||||
onLoad (options) {
|
||||
this.setData({
|
||||
type: options.type
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面显示
|
||||
*/
|
||||
onShow(){
|
||||
this.addressInfo();
|
||||
},
|
||||
|
||||
/* 地址列表
|
||||
*/
|
||||
addressInfo(){
|
||||
wx.$api.address.index().then(res=>{
|
||||
this.setData({
|
||||
addressArr: res.data
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 删除地址
|
||||
*/
|
||||
addressRemove(e){
|
||||
let id = e.target.dataset.id,
|
||||
index = e.target.dataset.index,
|
||||
list = this.data.addressArr
|
||||
|
||||
list.splice(index,1)
|
||||
|
||||
wx.showModal({
|
||||
title : '提示',
|
||||
content : '是否删除地址',
|
||||
success : res=> {
|
||||
if (res.confirm) {
|
||||
wx.showLoading({
|
||||
title: '删除中',
|
||||
})
|
||||
wx.$api.address.remove(id).then(res=>{
|
||||
this.setData({
|
||||
addressArr: list
|
||||
})
|
||||
wx.showToast({
|
||||
title: res.data,
|
||||
icon : "none"
|
||||
})
|
||||
|
||||
wx.hideLoading()
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 设为默认地址
|
||||
*/
|
||||
addressDefault(e){
|
||||
let id = e.currentTarget.dataset.id
|
||||
|
||||
wx.$api.address.setdef(id).then(res=>{
|
||||
this.addressInfo();
|
||||
wx.showToast({
|
||||
title: res.data,
|
||||
icon : "none"
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 选择地址
|
||||
*/
|
||||
selectAddress(e){
|
||||
let atAdds = this.data.addressArr[e.currentTarget.dataset.index]
|
||||
|
||||
let pages = getCurrentPages(),
|
||||
prepage = pages[pages.length-2]
|
||||
|
||||
prepage.setData({
|
||||
address: atAdds
|
||||
})
|
||||
|
||||
wx.navigateBack()
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user