|
@@ -45,6 +45,7 @@ Page({
|
|
|
console.log('picker发送选择改变,携带值为', e.detail.value)
|
|
|
this.setData({ today: e.detail.value })
|
|
|
this.searchDate();
|
|
|
+ this.searchOrder();
|
|
|
},
|
|
|
// 禁止左右滑动
|
|
|
stopTab: function (e) {
|
|
@@ -72,27 +73,33 @@ Page({
|
|
|
// 选择餐数量
|
|
|
// 早餐,午餐,晚餐
|
|
|
oneChange: function (e) {
|
|
|
- if (this.data.infoTab == 0) this.setData({ oneStepper: e.detail })
|
|
|
- else if (this.data.infoTab == 1) this.setData({ twoStepper: e.detail })
|
|
|
- else if (this.data.infoTab == 2) this.setData({ thrStepper: e.detail })
|
|
|
+ console.log(e);
|
|
|
+ const { data, type } = e.target.dataset
|
|
|
+ const { detail } = e;
|
|
|
+ this.menuNumOpera(type, detail, data._id)
|
|
|
},
|
|
|
// 增加
|
|
|
onePlus: function (e) {
|
|
|
console.log('增加');
|
|
|
let data = e.target.dataset.data;
|
|
|
let type = this.data.infoTab;
|
|
|
+ let meal;
|
|
|
+ let mw;
|
|
|
if (type == 0) {//早餐
|
|
|
- var meal = this.data.form.breakfast;
|
|
|
+ mw = 'breakfast';
|
|
|
+ meal = this.data.form.breakfast;
|
|
|
// 计算卡路里
|
|
|
let reserve = meal.reserve + data.reserve;
|
|
|
this.setData({ 'form.breakfast.reserve': reserve })
|
|
|
} else if (type == 1) {//午餐
|
|
|
- var meal = this.data.form.lunch;
|
|
|
+ mw = 'lunch';
|
|
|
+ meal = this.data.form.lunch;
|
|
|
// 计算卡路里
|
|
|
let reserve = meal.reserve + data.reserve;
|
|
|
this.setData({ 'form.lunch.reserve': reserve })
|
|
|
} else if (type == 2) {//晚餐
|
|
|
- var meal = this.data.form.dinner;
|
|
|
+ mw = 'dinner';
|
|
|
+ meal = this.data.form.dinner;
|
|
|
// 计算卡路里
|
|
|
let reserve = meal.reserve + data.reserve;
|
|
|
this.setData({ 'form.dinner.reserve': reserve })
|
|
@@ -101,31 +108,59 @@ Page({
|
|
|
let res = meal.list.findIndex(i => i.id === data.id);
|
|
|
// 查询数据
|
|
|
let arr = meal.list.find(i => i.id === data.id);
|
|
|
+ let onum = 0;
|
|
|
if (arr) {//已有值
|
|
|
- let qwe = { ...arr, num: arr.num + 1 } //id: arr.id, title: arr.title
|
|
|
+ onum = arr.num + 1;
|
|
|
+ let qwe = { ...arr, num: onum } //id: arr.id, title: arr.title
|
|
|
meal.list.splice(res, 1, qwe)
|
|
|
} else {//没有值
|
|
|
- let arr = { ...data, num: 1 } //id: data.id, title: data.title
|
|
|
+ console.log(data)
|
|
|
+ let onum = 1;
|
|
|
+ let arr = { ...data, num: onum } //id: data.id, title: data.title
|
|
|
meal.list.push(arr)
|
|
|
}
|
|
|
},
|
|
|
+ /**
|
|
|
+ * 更新菜单的数量
|
|
|
+ * @param {String} type 三餐的类型
|
|
|
+ * @param {Number} num 当前的数量
|
|
|
+ * @param {String} id 指定菜品
|
|
|
+ */
|
|
|
+ menuNumOpera(type, num, id) {
|
|
|
+ let list = this.data[`${type}List`];
|
|
|
+ const li = list.findIndex(f => f._id === id)
|
|
|
+ const ld = list.find(f => f._id === id)
|
|
|
+ if (ld) {
|
|
|
+ ld.num = num;
|
|
|
+ list.splice(li, 1, ld)
|
|
|
+ this.setData({
|
|
|
+ [`${type}List`]: list
|
|
|
+ })
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
// 减少
|
|
|
oneMinus: function (e) {
|
|
|
console.log('减少');
|
|
|
let data = e.target.dataset.data;
|
|
|
let type = this.data.infoTab;
|
|
|
+ let meal;
|
|
|
+ let mw;
|
|
|
if (type == 0) {//早餐
|
|
|
- var meal = this.data.form.breakfast;
|
|
|
+ mw = 'breakfast';
|
|
|
+ meal = this.data.form.breakfast;
|
|
|
// 计算减少卡路里
|
|
|
let reserve = meal.reserve - data.reserve;
|
|
|
this.setData({ 'form.breakfast.reserve': reserve })
|
|
|
} else if (type == 1) {//午餐
|
|
|
- var meal = this.data.form.lunch;
|
|
|
+ mw = 'lunch';
|
|
|
+ meal = this.data.form.lunch;
|
|
|
// 计算减少卡路里
|
|
|
let reserve = meal.reserve - data.reserve;
|
|
|
this.setData({ 'form.lunch.reserve': reserve })
|
|
|
} else if (type == 2) {//晚餐
|
|
|
- var meal = this.data.form.dinner;
|
|
|
+ mw = 'dinner';
|
|
|
+ meal = this.data.form.dinner;
|
|
|
// 计算减少卡路里
|
|
|
let reserve = meal.reserve - data.reserve;
|
|
|
this.setData({ 'form.dinner.reserve': reserve })
|
|
@@ -135,24 +170,32 @@ Page({
|
|
|
// 查询数据
|
|
|
let arr = meal.list.find(i => i.id === data.id);
|
|
|
if (arr) {
|
|
|
- let qwe = { id: arr.id, title: arr.title, num: arr.num - 1 }
|
|
|
- meal.list.splice(res, 1, qwe)
|
|
|
+ if (arr.num - 1 <= 0) meal.list.splice(res, 1)
|
|
|
+ else {
|
|
|
+ let qwe = { ...arr, num: arr.num - 1 }
|
|
|
+ meal.list.splice(res, 1, qwe)
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
+ // this.menuNumOpera(mw, onum, data._id)
|
|
|
},
|
|
|
// 提交
|
|
|
onSubmit: function () {
|
|
|
const data = JSON.parse(JSON.stringify(this.data.form))
|
|
|
if (app.globalData.wxInfo) data.openid = app.globalData.wxInfo.openid;
|
|
|
if (this.data.today) data.date = this.data.today;
|
|
|
+ let url;
|
|
|
+ if (data._id) url = `${app.globalData.publicUrl}/api/st/dining/order/update/${data._id}`
|
|
|
+ else url = `${app.globalData.publicUrl}/api/st/dining/order`;
|
|
|
wx.request({
|
|
|
- url: `${app.globalData.publicUrl}/api/st/dining/order`,
|
|
|
+ url,
|
|
|
method: "post",
|
|
|
header: {
|
|
|
'x-tenant': app.globalData.tenant
|
|
|
},
|
|
|
data,
|
|
|
success: res => {
|
|
|
- if (res.errcode == 0) {
|
|
|
+ if (res.data.errcode == 0) {
|
|
|
wx.showToast({
|
|
|
title: '完成点餐',
|
|
|
})
|
|
@@ -176,6 +219,7 @@ Page({
|
|
|
let today = moment().format('YYYY-MM-DD');
|
|
|
this.setData({ today: today })
|
|
|
this.searchDate();
|
|
|
+ this.searchOrder();
|
|
|
},
|
|
|
// 查询时间
|
|
|
searchDate: function () {
|
|
@@ -233,6 +277,48 @@ Page({
|
|
|
}
|
|
|
})
|
|
|
},
|
|
|
+ // 查订单
|
|
|
+ searchOrder() {
|
|
|
+ let today = this.data.today;
|
|
|
+ let openid = app.globalData.wxInfo.openid;
|
|
|
+ wx.request({
|
|
|
+ url: `${app.globalData.publicUrl}/api/st/dining/order/getByOpenid?date=${today}&openid=${openid}`,
|
|
|
+ method: "get",
|
|
|
+ header: {
|
|
|
+ 'x-tenant': app.globalData.tenant
|
|
|
+ },
|
|
|
+ success: res => {
|
|
|
+ this.setData({
|
|
|
+ form: res.data.data,
|
|
|
+ })
|
|
|
+ const { breakfast, lunch, dinner } = res.data.data
|
|
|
+ this.dealOrderToMenu('breakfast', breakfast.list)
|
|
|
+ this.dealOrderToMenu('lunch', lunch.list)
|
|
|
+ this.dealOrderToMenu('dinner', dinner.list)
|
|
|
+ },
|
|
|
+ error: err => {
|
|
|
+ wx.showToast({
|
|
|
+ title: err.msg,
|
|
|
+ icon: 'error'
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 将点过的单还原,继续修改
|
|
|
+ * @param {String} type 三餐类型
|
|
|
+ * @param {Array} list 某餐的内容
|
|
|
+ */
|
|
|
+ dealOrderToMenu(type, list) {
|
|
|
+ console.log(type, list)
|
|
|
+ if (list.length <= 0) return;
|
|
|
+ const menu = this.data[`${type}List`]
|
|
|
+ if (!menu) return;
|
|
|
+ for (const o of list) {
|
|
|
+ const { num, _id } = o
|
|
|
+ this.menuNumOpera(type, num, _id)
|
|
|
+ }
|
|
|
+ },
|
|
|
|
|
|
/**
|
|
|
* 生命周期函数--监听页面初次渲染完成
|