84 lines
1.9 KiB
JavaScript
84 lines
1.9 KiB
JavaScript
/**
|
|
* Soul创业派对 - 收货地址列表(增删改查)
|
|
*/
|
|
const app = getApp()
|
|
|
|
Page({
|
|
data: {
|
|
statusBarHeight: 44,
|
|
list: [],
|
|
loading: true
|
|
},
|
|
|
|
onLoad() {
|
|
this.setData({ statusBarHeight: app.globalData.statusBarHeight })
|
|
this.loadList()
|
|
},
|
|
|
|
onShow() {
|
|
this.loadList()
|
|
},
|
|
|
|
async loadList() {
|
|
const userId = app.globalData.userInfo?.id
|
|
if (!userId) {
|
|
this.setData({ list: [], loading: false })
|
|
return
|
|
}
|
|
this.setData({ loading: true })
|
|
try {
|
|
const res = await app.request('/api/user/addresses', { data: { userId } })
|
|
if (res.success && res.list) {
|
|
this.setData({ list: res.list, loading: false })
|
|
} else {
|
|
this.setData({ list: [], loading: false })
|
|
}
|
|
} catch (e) {
|
|
this.setData({ list: [], loading: false })
|
|
}
|
|
},
|
|
|
|
goAdd() {
|
|
wx.navigateTo({ url: '/pages/address-edit/address-edit' })
|
|
},
|
|
|
|
goEdit(e) {
|
|
const id = e.currentTarget.dataset.id
|
|
wx.navigateTo({ url: '/pages/address-edit/address-edit?id=' + id })
|
|
},
|
|
|
|
async deleteAddress(e) {
|
|
const id = e.currentTarget.dataset.id
|
|
const that = this
|
|
wx.showModal({
|
|
title: '删除地址',
|
|
content: '确定要删除该收货地址吗?',
|
|
success(res) {
|
|
if (!res.confirm) return
|
|
that.doDelete(id)
|
|
}
|
|
})
|
|
},
|
|
|
|
async doDelete(id) {
|
|
wx.showLoading({ title: '删除中...' })
|
|
try {
|
|
const res = await app.request('/api/user/addresses/' + id, { method: 'DELETE' })
|
|
wx.hideLoading()
|
|
if (res.success) {
|
|
wx.showToast({ title: '已删除', icon: 'success' })
|
|
this.loadList()
|
|
} else {
|
|
wx.showToast({ title: res.message || '删除失败', icon: 'none' })
|
|
}
|
|
} catch (e) {
|
|
wx.hideLoading()
|
|
wx.showToast({ title: '删除失败', icon: 'none' })
|
|
}
|
|
},
|
|
|
|
goBack() {
|
|
wx.navigateBack()
|
|
}
|
|
})
|