2019-12-14 10:02:03 +08:00
|
|
|
// pages/chooseaddr/chooseaddr.js
|
2019-12-24 16:32:27 +08:00
|
|
|
import { request,getuserid } from "../../utils/bin"
|
2019-12-14 10:02:03 +08:00
|
|
|
Page({
|
|
|
|
|
2019-12-16 18:26:28 +08:00
|
|
|
/**
|
|
|
|
* 页面的初始数据
|
|
|
|
*/
|
|
|
|
data: {
|
2019-12-20 14:03:59 +08:00
|
|
|
addresslist:[],
|
|
|
|
userid:""
|
2019-12-14 10:02:03 +08:00
|
|
|
|
2019-12-16 18:26:28 +08:00
|
|
|
},
|
2019-12-14 10:02:03 +08:00
|
|
|
|
2019-12-16 18:26:28 +08:00
|
|
|
/**
|
|
|
|
* 生命周期函数--监听页面加载
|
|
|
|
*/
|
|
|
|
onLoad: function(options) {
|
2019-12-20 14:03:59 +08:00
|
|
|
request({
|
|
|
|
url: "User/validateOpenid",
|
|
|
|
}).then((res)=>{
|
|
|
|
this.setData({
|
|
|
|
userid:res.data.data.user_id
|
|
|
|
})
|
|
|
|
request({
|
|
|
|
url: "User/getAddressList",
|
|
|
|
urldata:{
|
|
|
|
user_id:this.data.userid
|
|
|
|
},
|
|
|
|
}).then((res)=>{
|
|
|
|
console.log(res)
|
|
|
|
this.setData({
|
|
|
|
addresslist:res.data.result
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-12-16 18:26:28 +08:00
|
|
|
},
|
|
|
|
add() {
|
2019-12-24 16:32:27 +08:00
|
|
|
getuserid().then((id)=>{
|
|
|
|
if(id == 0){
|
|
|
|
wx.showToast({
|
|
|
|
title: '请先登陆',
|
|
|
|
icon: 'none',
|
|
|
|
duration: 2000
|
|
|
|
})
|
|
|
|
}else{
|
|
|
|
wx.navigateTo({
|
|
|
|
url: "/pages/addaddress/addaddress"
|
|
|
|
})
|
|
|
|
}
|
2019-12-16 18:26:28 +08:00
|
|
|
})
|
2019-12-24 16:32:27 +08:00
|
|
|
|
2019-12-16 18:26:28 +08:00
|
|
|
},
|
2019-12-20 14:03:59 +08:00
|
|
|
// user_id/8/id/215
|
|
|
|
delete(e){
|
|
|
|
let t=this
|
|
|
|
wx.showModal({
|
|
|
|
title: '确认',
|
|
|
|
content: '要删除这个地址吗?',
|
2019-12-23 16:08:18 +08:00
|
|
|
success(res){
|
2019-12-20 14:03:59 +08:00
|
|
|
|
2019-12-23 16:08:18 +08:00
|
|
|
if (res.confirm) {
|
|
|
|
console.log('用户点击确定')
|
2019-12-20 14:03:59 +08:00
|
|
|
request({
|
2019-12-23 16:08:18 +08:00
|
|
|
url: "User/validateOpenid",
|
2019-12-20 14:03:59 +08:00
|
|
|
}).then((res)=>{
|
2019-12-23 16:08:18 +08:00
|
|
|
t.setData({
|
|
|
|
userid:res.data.data.user_id
|
|
|
|
})
|
2019-12-20 14:03:59 +08:00
|
|
|
request({
|
2019-12-23 16:08:18 +08:00
|
|
|
url: "User/del_address",
|
2019-12-20 14:03:59 +08:00
|
|
|
urldata:{
|
2019-12-23 16:08:18 +08:00
|
|
|
user_id:res.data.data.user_id,
|
|
|
|
id:e.currentTarget.dataset.id
|
2019-12-20 14:03:59 +08:00
|
|
|
},
|
|
|
|
}).then((res)=>{
|
|
|
|
console.log(res)
|
2019-12-23 16:08:18 +08:00
|
|
|
request({
|
|
|
|
url: "User/getAddressList",
|
|
|
|
urldata:{
|
|
|
|
user_id:t.data.userid
|
|
|
|
},
|
|
|
|
}).then((res)=>{
|
|
|
|
console.log(res)
|
|
|
|
t.setData({
|
|
|
|
addresslist:res.data.result
|
|
|
|
})
|
2019-12-20 14:03:59 +08:00
|
|
|
})
|
2019-12-23 16:08:18 +08:00
|
|
|
})
|
|
|
|
})
|
|
|
|
} else if (res.cancel) {
|
|
|
|
console.log('用户点击取消')
|
|
|
|
console.log("不能动啊")
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-12-20 14:03:59 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
setdefault(e){
|
|
|
|
console.log(e.currentTarget.dataset.id)
|
|
|
|
request({
|
|
|
|
url: "User/setDefaultAddress",
|
|
|
|
urldata:{
|
|
|
|
user_id:this.data.userid,
|
|
|
|
address_id:e.currentTarget.dataset.id
|
|
|
|
},
|
|
|
|
}).then((res)=>{
|
|
|
|
console.log(res)
|
|
|
|
request({
|
|
|
|
url: "User/getAddressList",
|
|
|
|
urldata:{
|
|
|
|
user_id:this.data.userid
|
|
|
|
},
|
|
|
|
}).then((res)=>{
|
|
|
|
console.log(res)
|
|
|
|
this.setData({
|
|
|
|
addresslist:res.data.result
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
},
|
2019-12-16 18:26:28 +08:00
|
|
|
/**
|
|
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
|
|
*/
|
|
|
|
onReady: function() {
|
2019-12-14 10:02:03 +08:00
|
|
|
|
2019-12-16 18:26:28 +08:00
|
|
|
},
|
2019-12-14 10:02:03 +08:00
|
|
|
|
2019-12-16 18:26:28 +08:00
|
|
|
/**
|
|
|
|
* 生命周期函数--监听页面显示
|
|
|
|
*/
|
|
|
|
onShow: function() {
|
2019-12-26 09:13:34 +08:00
|
|
|
this.onLoad()
|
2019-12-16 18:26:28 +08:00
|
|
|
},
|
2019-12-14 10:02:03 +08:00
|
|
|
|
2019-12-16 18:26:28 +08:00
|
|
|
/**
|
|
|
|
* 生命周期函数--监听页面隐藏
|
|
|
|
*/
|
|
|
|
onHide: function() {
|
2019-12-14 10:02:03 +08:00
|
|
|
|
2019-12-16 18:26:28 +08:00
|
|
|
},
|
2019-12-14 10:02:03 +08:00
|
|
|
|
2019-12-16 18:26:28 +08:00
|
|
|
/**
|
|
|
|
* 生命周期函数--监听页面卸载
|
|
|
|
*/
|
|
|
|
onUnload: function() {
|
2019-12-14 10:02:03 +08:00
|
|
|
|
2019-12-16 18:26:28 +08:00
|
|
|
},
|
2019-12-14 10:02:03 +08:00
|
|
|
|
2019-12-16 18:26:28 +08:00
|
|
|
/**
|
|
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
|
|
*/
|
|
|
|
onPullDownRefresh: function() {
|
2019-12-14 10:02:03 +08:00
|
|
|
|
2019-12-16 18:26:28 +08:00
|
|
|
},
|
2019-12-14 10:02:03 +08:00
|
|
|
|
2019-12-16 18:26:28 +08:00
|
|
|
/**
|
|
|
|
* 页面上拉触底事件的处理函数
|
|
|
|
*/
|
|
|
|
onReachBottom: function() {
|
2019-12-14 10:02:03 +08:00
|
|
|
|
2019-12-16 18:26:28 +08:00
|
|
|
},
|
2019-12-14 10:02:03 +08:00
|
|
|
|
2019-12-16 18:26:28 +08:00
|
|
|
/**
|
|
|
|
* 用户点击右上角分享
|
|
|
|
*/
|
|
|
|
onShareAppMessage: function() {
|
2019-12-14 10:02:03 +08:00
|
|
|
|
2019-12-16 18:26:28 +08:00
|
|
|
}
|
2019-12-14 10:02:03 +08:00
|
|
|
})
|