You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
git/scr/food/pages/address/address.js

123 lines
2.2 KiB

2 years ago
// pages/address/address.js
const db = wx.cloud.database({});
const app=getApp()
const userid=app.globalData.openid
Page({
/**
* 页面的初始数据
*/
data: {
addressList:[]
},
//增加地址
addAddress:function(){
wx.navigateTo({ url: '/pages/addAddress/addAddress' });
},
delAddress:function(event){
var that = this;
const index = event.currentTarget.id;
console.log(index)
let addressList = this.data. addressList;//购物车所有的商品数据
wx.showModal({
title: '温馨提示',
content: '确定删除当前地址吗?',
confirmColor: "#f00",
success: (res) => {
if (res.confirm) {
addressList.splice(index, 1);
this.setData({
addressList:addressList
})
db.collection('user')//回调回云数据库
.where({
"_openid":userid
})
.update(
{
data:{
['address']:this.data.addressList
}
}
)
}}
})
console.log(addressList)
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
db.collection('user').
where({
"_openid":userid
}) //还需修改
.get({
success: res => {
console.log(res.data.address)
console.log(res.data)
//这一步很重要给ne赋值没有这一步的话前台就不会显示值
this.setData({
addressList: res.data[0].address
})
}
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})