deguodaigou/pages/chooseaddr/chooseaddr.js

159 lines
3.6 KiB
JavaScript
Raw Normal View History

2019-12-14 10:02:03 +08:00
// pages/chooseaddr/chooseaddr.js
2019-12-20 14:03:59 +08:00
import { request } 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() {
wx.navigateTo({
url: "/pages/addaddress/addaddress"
})
},
2019-12-20 14:03:59 +08:00
// 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
})
})
})
},
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-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
/**
* 生命周期函数--监听页面隐藏
*/
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
})