165 lines
3.5 KiB
JavaScript
165 lines
3.5 KiB
JavaScript
// user/address/address.js
|
|
const app = getApp();
|
|
const util = app.loadUtils("util")
|
|
const regeneratorRuntime = app.loadAsync()
|
|
const model = app.loadModel("index")
|
|
const http = app.loadHttp()
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
system: app.globalData.system, //设备相关信息
|
|
pageTitle: "选择地址", //头部标题
|
|
isBack: true,//显示返回
|
|
currentId: null,//当前选中的地址id
|
|
addList: [],//收货地址列表
|
|
isAdd: false,//是否点击地址返回上一层
|
|
right: [
|
|
{
|
|
text: '删除',
|
|
style: 'background-color: #F4333C; color: white',
|
|
}],
|
|
},
|
|
// 修改收货地址信息
|
|
updataAdd(e) {
|
|
let item = e.currentTarget.dataset.item
|
|
model.storage.setStorage("updataAdd", item)
|
|
wx.navigateTo({
|
|
url: "/user/address/address?modify=" + 0
|
|
})
|
|
},
|
|
// 获取微信收货地址
|
|
getWxAdd() {
|
|
wx.chooseAddress({
|
|
success(res) {
|
|
model.storage.setStorage("address", res)
|
|
wx.navigateBack({
|
|
url: "/user/appointment/appointment"
|
|
})
|
|
}
|
|
})
|
|
},
|
|
// 选择收货地址方法
|
|
selectAdd(e) {
|
|
if (this.data.isAdd) {
|
|
return
|
|
}
|
|
let index = e.currentTarget.dataset.index
|
|
this.setData({
|
|
currentId: index
|
|
})
|
|
// 获取下表对应的地址
|
|
let indexAdd = this.data.addList[index]
|
|
let data = {
|
|
provinceName: indexAdd.address + indexAdd.detail,
|
|
userName: indexAdd.userName,
|
|
telNumber: indexAdd.telNumber,
|
|
cityName: "",
|
|
countyName: "",
|
|
detailInfo: "",
|
|
type: true,
|
|
id: indexAdd.id
|
|
}
|
|
// 存构造好的地址返回上一页
|
|
model.storage.setStorage("address", data)
|
|
wx.navigateBack({
|
|
url: "/user/appointment/appointment"
|
|
})
|
|
},
|
|
// 获取收货地址列表
|
|
async getUserAddress() {
|
|
|
|
let res = await http.http.request2({ url: `${http.api.getUserAddress}`, method: "POST" })
|
|
|
|
// 拿出默认地址
|
|
let defaultAddress = res.data.data.filter((val)=> val.is_default == 1);
|
|
|
|
// 本地保存
|
|
if(defaultAddress.length !== 0){
|
|
let data = {
|
|
provinceName: defaultAddress[0].provinceName,
|
|
userName: defaultAddress[0].userName,
|
|
telNumber: defaultAddress[0].telNumber,
|
|
cityName: defaultAddress[0].cityName,
|
|
countyName: defaultAddress[0].countryName,
|
|
detailInfo: defaultAddress[0].detail,
|
|
type: true,
|
|
id: defaultAddress[0].id
|
|
}
|
|
model.storage.setStorage("address", data)
|
|
}
|
|
|
|
this.setData({
|
|
addList: res.data.data
|
|
})
|
|
if(res.data.data.length <= 0){
|
|
wx.redirectTo({
|
|
url: "/user/address/address?modify=1"
|
|
})
|
|
}
|
|
},
|
|
// 侧滑删除
|
|
onClick(e) {
|
|
|
|
},
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad: function (options) {
|
|
let data = {
|
|
isAdd: options.isAdd
|
|
}
|
|
this.setData(data)
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
*/
|
|
onReady: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面显示
|
|
*/
|
|
onShow: function () {
|
|
this.getUserAddress()
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面隐藏
|
|
*/
|
|
onHide: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面卸载
|
|
*/
|
|
onUnload: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
*/
|
|
onPullDownRefresh: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面上拉触底事件的处理函数
|
|
*/
|
|
onReachBottom: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 用户点击右上角分享
|
|
*/
|
|
onShareAppMessage: function () {
|
|
|
|
}
|
|
}) |