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.
182 lines
3.8 KiB
182 lines
3.8 KiB
// pages/user/address/index.js
|
|
import user from "../../../utils/https/user.js"
|
|
import util from "../../../utils/util.js"
|
|
import common from "../../../utils/https/common.js"
|
|
let app = getApp()
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
pageNo:1,
|
|
isMore:true,
|
|
list:[],
|
|
isOrder:false,
|
|
safeBottom:app.globalData.safeBottom
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad: function (options) {
|
|
if(options && options.from){
|
|
this.setData({
|
|
isOrder:true,
|
|
pid:options.pid,
|
|
sid:options.sid
|
|
})
|
|
}
|
|
},
|
|
// 选择收货地址
|
|
selectItem:function(e){
|
|
if(this.data.isOrder){
|
|
let addressItem = e.currentTarget.dataset.item;
|
|
let pid = this.data.pid,sid = this.data.sid;
|
|
let products = app.globalData.shoppingCart;
|
|
products.map(item=>{
|
|
if(item.baseInfo.id==pid && item.skuInfo.id==sid){
|
|
// 给当前产品添加收货地址
|
|
item.address = addressItem;
|
|
}
|
|
})
|
|
app.globalData.shoppingCart = products;
|
|
util.back();
|
|
}
|
|
},
|
|
getList:function(){
|
|
user.user_post("user/getContactOrConsignee",{
|
|
contactType:"CONSIGNEE",
|
|
offset: this.data.list.length,
|
|
limit:10,
|
|
tm_flag: true,
|
|
}).then(res=>{
|
|
let list = this.data.list.concat(res.data), isMore = true;
|
|
if(res.data.length<10){
|
|
isMore:false
|
|
}
|
|
this.setData({
|
|
list:list,
|
|
pageNo: this.data.pageNo + 1,
|
|
isMore: isMore
|
|
})
|
|
})
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
*/
|
|
onReady: function () {
|
|
|
|
},
|
|
// 设为默认
|
|
setDefault:function(e){
|
|
let item = e.currentTarget.dataset.item;
|
|
if(item.is_default==1) return;
|
|
user.user_post("user/setDefaultConsignee",{
|
|
id:item.id
|
|
}).then(res=>{
|
|
// 设置默认成功
|
|
let list = this.data.list;
|
|
if(res.code==1){
|
|
wx.showToast({
|
|
title: '操作成功!',
|
|
icon:"success"
|
|
});
|
|
list.map((i,index,arr)=>{
|
|
if(i.id==item.id){
|
|
i.is_default = 1;
|
|
}
|
|
else {
|
|
i.is_default = 0;
|
|
}
|
|
})
|
|
this.setData({
|
|
list:list
|
|
})
|
|
}
|
|
})
|
|
},
|
|
// 删除单个地址
|
|
add:function(e){
|
|
console.log(e)
|
|
if(e.target.dataset.id){
|
|
wx.navigateTo({
|
|
url: './add/index?id=' + e.target.dataset.id
|
|
})
|
|
}
|
|
else {
|
|
wx.navigateTo({
|
|
url: './add/index?id='
|
|
})
|
|
}
|
|
|
|
},
|
|
del:function(e){
|
|
let that = this, id = e.currentTarget.dataset.id, index = e.currentTarget.dataset.index;
|
|
wx.showModal({
|
|
title: '提示',
|
|
content: '确定删除吗?',
|
|
success:function(res){
|
|
if (res.confirm){
|
|
// 确定删除
|
|
user.user_post("user/delConsignee", { id:id}).then(res=>{
|
|
if(res.code==1){
|
|
wx.showToast({
|
|
title: '删除成功',
|
|
icon:'success'
|
|
})
|
|
let data = that.data.list;
|
|
data.splice(index, 1)
|
|
that.setData({
|
|
list: data
|
|
})
|
|
}
|
|
})
|
|
}
|
|
}
|
|
})
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面显示
|
|
*/
|
|
onShow: function () {
|
|
this.setData({
|
|
list:[],
|
|
pageNo:1,
|
|
isMore:true
|
|
})
|
|
this.getList();
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面隐藏
|
|
*/
|
|
onHide: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面卸载
|
|
*/
|
|
onUnload: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
*/
|
|
onPullDownRefresh: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面上拉触底事件的处理函数
|
|
*/
|
|
onReachBottom: function () {
|
|
if(this.data.isMore){
|
|
this.getList();
|
|
}
|
|
}
|
|
})
|