159 lines
3.6 KiB
JavaScript
159 lines
3.6 KiB
JavaScript
// pages/chooseaddr/chooseaddr.js
|
|
import { request } 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() {
|
|
wx.navigateTo({
|
|
url: "/pages/addaddress/addaddress"
|
|
})
|
|
},
|
|
// user_id/8/id/215
|
|
delete(e){
|
|
let t=this
|
|
wx.showModal({
|
|
title: '确认',
|
|
content: '要删除这个地址吗?',
|
|
success(){
|
|
|
|
|
|
console.log(e.currentTarget.dataset.id)
|
|
|
|
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
|
|
})
|
|
})
|
|
})
|
|
})
|
|
|
|
|
|
|
|
|
|
}
|
|
})
|
|
},
|
|
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() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面隐藏
|
|
*/
|
|
onHide: function() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面卸载
|
|
*/
|
|
onUnload: function() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
*/
|
|
onPullDownRefresh: function() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面上拉触底事件的处理函数
|
|
*/
|
|
onReachBottom: function() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 用户点击右上角分享
|
|
*/
|
|
onShareAppMessage: function() {
|
|
|
|
}
|
|
}) |