Files
sphc/pages/my/my_address/my_address.js
2024-05-08 17:32:39 +08:00

199 lines
4.4 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// pages/my/my_address/my_address.js
const app = getApp();
Page({
/**
* 页面的初始数据
*/
data: {
select: false,
dataList: [],
orderAddress: false,
addressIdXz: '',
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
wx.showLoading({
title: '加载中',
})
wx.request({
url: app.globalData.ip + '/wisdommining/api/user/getUserAddress',
method: 'GET',
header: {
"content-type": "application/x-www-form-urlencoded",
},
data: {
userId: app.globalData.userId
},
success: res => {
console.log(res)
wx.hideLoading()
if (res.data.code == 1) {
let dataList = res.data.value;
for (let i = 0; i < dataList.length; i++) {
dataList[i].select = false;
if (dataList[i].id == this.data.addressIdXz) {
dataList[i].select = true;
}
}
this.setData({
dataList: dataList
})
} else {
wx.showModal({
title: '提示!',
content: res.data.message,
showCancel: false,
})
}
}
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
if (options.orderAddress) {
this.setData({
orderAddress: options.orderAddress,
addressIdXz: options.addressId
})
}
},
//选择地址
select: function (e) {
console.log("aaaaaaaaaaa")
let index = e.currentTarget.dataset.index;
let dataList = this.data.dataList;
for (let i = 0; i < dataList.length; i++) {
dataList[i].select = false;
}
this.setData({
dataList: dataList
})
const pages = getCurrentPages()
const prevPage = pages[pages.length - 2]  // 上一页
// 调用上一个页面的setData 方法将数据存储
if (this.data.dataList.length > 0) {
prevPage.setData({
address: dataList[index].addressProvince + dataList[index].addressCity + dataList[index].addressArea + dataList[index].addressDetailed,
addressId: dataList[index].id,
province: dataList[index].addressProvince,
orderPick: 2,
})
prevPage.requestUpdateAddress && prevPage.requestUpdateAddress()
} else {
prevPage.setData({
address: '选择收货方式',
addressId: '',
province: '',
orderPick: 2,
})
}
wx.navigateBack();
},
//编辑
edit: function (e) {
wx.navigateTo({
url: '/pages/my/my_address/my_address_details/my_address_details?id=' + e.currentTarget.dataset.id,
})
},
//新增
add: function (e) {
wx.navigateTo({
url: '/pages/my/my_address/my_address_details/my_address_details',
})
},
//删除
del: function (e) {
var id = e.currentTarget.dataset.id
wx.showModal({
title: '提示',
content: '确认要删除此地址吗?',
success: suc => {
if (suc.confirm) {
wx.showLoading({
title: '加载中',
})
wx.request({
url: app.globalData.ip + '/wisdommining/api/user/delUserAddress',
method: 'DELETE',
header: {
"content-type": "application/x-www-form-urlencoded",
},
data: {
id: id,
},
success: res => {
console.log(res)
wx.hideLoading()
if (res.data.code == 1) {
wx.showToast({
title: '删除成功~',
icon: 'none',
success: s => {
this.onShow()
}
})
} else {
wx.showModal({
title: '提示!',
content: res.data.message,
showCancel: false,
})
}
}
})
}
}
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
})