You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

169 lines
3.3 KiB
JavaScript

2 years ago
// pages/addressBook/index.js
var app = getApp();
Page({
/**
* 页面的初始数据
*/
data: {
items: [
{value: '1', name: '设为默认'},
{value: '2', name: '已设为默认', checked: 'true'},
{value: '3', name: '设为默认'},
],
hasAddress: false,
recordList: [],
},
getList() {
var that = this;
wx.request({
url: app.globalData.ip + "/user/address/getUserAddressList",
method: "POST",
header: app.globalData.headers,
data: that.data.searchForm,
success: function(res) {
console.log(res);
if (app.isNotEmptyCheck(res.data.data)) {
that.setData({
recordList: res.data.data,
hasAddress: true
});
} else {
that.setData({
recordList: [],
hasAddress: false
});
}
}
});
},
radioChange(e) {
console.log('radio发生change事件携带value值为', e.detail.value)
var that = this;
that.data.recordList.forEach(item => {
item.defaultFlag = 0;
if (item.id == e.detail.value) {
item.defaultFlag = 1;
}
});
this.setData({
recordList: that.data.recordList
})
wx.request({
url: app.globalData.ip + "/user/address/updateDefaultFlag",
method: "POST",
header: app.globalData.headers,
data: {
id: e.detail.value,
defaultFlag: 1,
},
success: function(res) {
console.log(res);
}
});
},
addAddress:function(){
wx.navigateTo({
url: '/pages/addAddress/index',
})
},
delAddress:function(e){
var that = this;
var record = e.currentTarget.dataset.record;
console.log(record);
wx.showModal({
title: '提示',
content: '确定要删除该地址吗?',
cancelColor:"#666666",
confirmColor:"#027AFF",
success (res) {
if (res.confirm) {
console.log('用户点击确定')
wx.request({
url: app.globalData.ip + "/user/address/deleteUserAddress",
method: "POST",
header: app.globalData.headers,
data: {
id: record.id
},
success: function(res) {
console.log(res);
that.getList();
}
});
} else if (res.cancel) {
console.log('用户点击取消')
}
}
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
this.getList();
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})