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