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.
|
|
|
// pages/orderlist/orderlist.js
|
|
|
|
const db = wx.cloud.database({});
|
|
|
|
const app=getApp()
|
|
|
|
const userid=app.globalData.openid
|
|
|
|
Page({
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 页面的初始数据
|
|
|
|
*/
|
|
|
|
data: {
|
|
|
|
orderlist:[]
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* 点击删除订单
|
|
|
|
*/
|
|
|
|
deleteGoods(event) {
|
|
|
|
var that = this;
|
|
|
|
const index = event.currentTarget.id;
|
|
|
|
console.log(index)
|
|
|
|
|
|
|
|
let orderlist = this.data.orderlist;//购物车所有的商品数据
|
|
|
|
let foodid=orderlist[index]._id
|
|
|
|
console.log(foodid)
|
|
|
|
wx.showModal({
|
|
|
|
title: '温馨提示',
|
|
|
|
content: '确定删除当前订单吗?',
|
|
|
|
confirmColor: "#f00",
|
|
|
|
success: (res) => {
|
|
|
|
if (res.confirm) {
|
|
|
|
orderlist.splice(index, 1);
|
|
|
|
this.setData({
|
|
|
|
orderlist:orderlist
|
|
|
|
})
|
|
|
|
db.collection('user')//回调回云数据库
|
|
|
|
. where({
|
|
|
|
"_openid":userid
|
|
|
|
})
|
|
|
|
.update(
|
|
|
|
{
|
|
|
|
data:{
|
|
|
|
['cartlist.'+[index]]:db.command.remove(),
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
db.collection('user')//回调回云数据库
|
|
|
|
.where({
|
|
|
|
"_openid":userid
|
|
|
|
})
|
|
|
|
.update(
|
|
|
|
{
|
|
|
|
data:{
|
|
|
|
['Orderlist']:this.data.orderlist
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}}
|
|
|
|
})
|
|
|
|
|
|
|
|
console.log(orderlist)
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* 生命周期函数--监听页面加载
|
|
|
|
*/
|
|
|
|
onLoad(options) {
|
|
|
|
db.collection("user")
|
|
|
|
.where({
|
|
|
|
"_openid":userid
|
|
|
|
})
|
|
|
|
.get()
|
|
|
|
.then(res => {
|
|
|
|
console.log("列表页", res.data);
|
|
|
|
console.log(res.data[0].Orderlist)
|
|
|
|
//再次显示数据
|
|
|
|
this.setData({
|
|
|
|
orderlist:res.data[0].Orderlist.reverse(),
|
|
|
|
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
console.log("加载失败", err);
|
|
|
|
})
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
|
|
*/
|
|
|
|
onReady() {
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 生命周期函数--监听页面显示
|
|
|
|
*/
|
|
|
|
onShow() {
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 生命周期函数--监听页面隐藏
|
|
|
|
*/
|
|
|
|
onHide() {
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 生命周期函数--监听页面卸载
|
|
|
|
*/
|
|
|
|
onUnload() {
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
|
|
*/
|
|
|
|
onPullDownRefresh() {
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 页面上拉触底事件的处理函数
|
|
|
|
*/
|
|
|
|
onReachBottom() {
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 用户点击右上角分享
|
|
|
|
*/
|
|
|
|
onShareAppMessage() {
|
|
|
|
|
|
|
|
}
|
|
|
|
})
|