index_new.js
10.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
// pack-cookbook/pages/index_new.js
var mta = require('mta-wechat-analysis')
import util from '../../utils/util';
import App from '../../utils/api';
Page({
/**
* 页面的初始数据
*/
data: {
type:'A',//样式A,B,C
scrollTop: 0,
options:{},
check1:'',//做法
check2:'',//规格
isloading: true,
toView: "",
countPirce:'',
countTotal:'',
hasEnter: false,
totalWidth: getApp().system.windowWidth,
singleWidth: parseInt((getApp().system.windowWidth * 0.92 - 16) / 2),
totalHeight: getApp().system.windowHeight,
kindHeight: getApp().system.windowHeight - 68,
hasListModel: true,
cookbooklist: [],
showSkeleton: true,
order: {},
orderItemCount:0,
checkObj:'',
quantum:'',
normsList:[
{
text:'做饭',
},
{
text:'规格',
}
],
assortArr:[
{name:'淮扬热菜'},
{name:'精品凉菜'},
{name:'广式烧腊'},
{name:'海鲜'},
{name:'汤羹'},
{name:'四季时蔬'},
{name:'酒水'},
],
},
checkModal:'',
classifyModal:'',
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
console.log('options',options);
this.setData({
options: options,
})
this.getCookList();
this.initOrder();
mta.Page.init({
"appID": "500667280",
"eventID": "500667287",
"statPullDownFresh": true,
"statShareApp": true,
"statReachBottom": true,
"lauchOpts": options, //渠道分析
});
this.checkModal = this.selectComponent("#checkModal");
this.classifyModal = this.selectComponent("#classifyModal");
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
// 选择做法
checkSingle1(e){
const check1= e.currentTarget.dataset['item'];
console.log('check1',check1);
this.setData({
check1
})
},
// 已选菜单页面跳转
gotoShoppingCart(){
let arr=[]
this.data.cookbooklist.forEach(item=>{
if(item.quantum!='0'){
arr.push(item)
}
})
console.log(arr);
// wx.navigateTo({
// url: util.http_build_query({
// sellerName:this.data.options.sellerName,
// arr:[]
// }, '/pack-cookbook/pages/cart_new')
// })
},
// 选择规格
checkSingle2(e){
const check2= e.currentTarget.dataset['item'];
this.setData({
check2
})
},
// 展示做法规格弹窗
showModal() {
this.checkModal.showModal()
},
// 关闭做法规格弹窗
closeModal() {
this.checkModal.closeModal()
},
// 展示菜品分类弹框
showClassifyModal() {
this.classifyModal.showModal()
},
// 关闭菜品分类弹框
closeClassifyModal() {
this.classifyModal.closeModal()
},
// 选择菜品分类
checkItem(e){
const item= e.currentTarget.dataset['item'];
console.log(item);
},
// 选择做法和规格后点击确定
determineFun(){
let index =this.data.checkObj.index;
let indexs =this.data.checkObj.indexs;
let quantum =this.data.quantum;
let check1 = this.data.check1;
console.log(this.data.cookbooklist[indexs].cookbooklist[0][index].arr1[check1]);
let checkObj=`cookbooklist[${indexs}].cookbooklist[0][${index}].quantum`;
let arr1=`cookbooklist[${indexs}].cookbooklist[0][${index}].arr1[${check1}]`;
let practice=`cookbooklist[${indexs}].cookbooklist[0][${index}].practice`;
this.setData({
[checkObj]:quantum,
[practice]:check1
})
console.log(this.data.check1);
console.log(this.data.cookbooklist[indexs].cookbooklist[0][index]);
this.closeModal()
},
// 点击加号
addition(e){
const item= e.currentTarget.dataset['item'];
const index= e.currentTarget.dataset['key'];//菜下标
const indexs= e.currentTarget.dataset['indexs'];//分类下标
let quantum = item.quantum * 1 + 1;
console.log('index',index);
console.log('indexs',indexs);
console.log('indexs',indexs);
let checkObj={
indexs,
index
};
console.log(checkObj,quantum);
this.showModal()
this.setData({
checkObj,
quantum,
})
},
// 点击减号
subtraction(e){
const item= e.currentTarget.dataset['item'];
const index= e.currentTarget.dataset['key'];//菜下标
const indexs= e.currentTarget.dataset['indexs'];//分类下标
let quantum = item.quantum * 1 - 1;
let checkObj=`cookbooklist[${indexs}].cookbooklist[${index}]`;
this.setData({
checkObj,
quantum,
})
},
// 扫桌码点餐
initOrder() {
App.Advance.CreateOrder({
rid: this.data.options.rid,
identity: this.data.options.identity,
status: '0,1',
openid: getApp().openid,
}).then(res => {
let orderItemCount = 0;
res.data.cookbooklist.forEach(cb => {
if (this.data.options.identity == 1 && cb.status > 0) {
wx.redirectTo({
url: util.http_build_query({
rid: this.data.options.rid,
oid: res.data.id,
identity: 1
}, '/pack-cookbook/pages/success')
});
return false;
}
orderItemCount += parseInt(cb.num)
})
this.setData({
[`options.oid`]: res.data.id,
order: res.data,
orderItemCount: orderItemCount,
})
})
},
formatCookList(list){
//原栏目下显示
let hasShowClass = false;
//菜单中展示沽清的菜品
let hasClearCookbook = false;
//十道必选菜
let has10CaiOpen = false;
let flist = [];
let check1='';
let check2='';
if (list.length > 0) {
has10CaiOpen = list[0].status == 1;
list.forEach(function (cate, i) {
if (cate.status == 1 && cate.cookbooklist[0].length > 0) {
let cooks = [];
//let cooks_order=[];
cate.cookbooklist[0].forEach(function (cook, n) {
if (cook.status == 1) {
let flag = true;
if (has10CaiOpen) {
if (cate.class_type == 2 && !hasShowClass && flist.length > 0 && flist[0].class_type == 1) {
for (let fi = 0; fi < flist[0].cookbooklist[0].length; fi++) {
if (flist[0].cookbooklist[0][fi].id == cook.id) {
flag = false;
break;
}
}
}
}
cook.item_clear_num = cook.clear_num;
if (!hasClearCookbook) {//不显示卖光了
let item_clear_num = cook.clear_num;
if (cook.spec) {
let clear_num = null;
cook.spec.forEach(spec => {
if (spec.clear_num == 0) {
clear_num = 0;
} else {
clear_num = null;
}
})
if (clear_num == 0) {
item_clear_num = 0;
}
}
cook.item_clear_num = item_clear_num;
cook.quantum=0;
cook.index=n;
cook.practice='';
cook.arr1=['香辣','清蒸','爆炒','清汤'];
cook.arr2=['小份','中份','份','例','两只'];
check1=cook.arr1[0];
check2=cook.arr2[0];
if (item_clear_num == 0) {
flag = false;
}
}
if (flag) {
cooks.push(cook);
//cooks_order.push(cook.order_o);
}
}
})
if (cooks.length > 0) {
//cooks 排序...
cate.cookbooklist[0] = cooks;
flist.push(cate)
}
}
})
}
setTimeout(() => {
this.setData({
check1,
check2
})
}, 1);
return flist;
},
// 获取所有分类下所有菜品列表
getCookList(orderid) {
let param = {
sellerid: this.data.options.sid,
identity: this.data.options.identity,
orderid : this.data.options.oid,
status:'0,1',
};
App.Advance.GetCookbookByClass(param).then(json => {
//菜单分类添加修饰
let cookbooklist = this.formatCookList(json.data[0].list);
console.log({...cookbooklist[1].cookbooklist[0][0]});
setTimeout(() => {
this.setData({
cookbooklist: cookbooklist,
countPirce: json.data[0].countPirce ? json.data[0].countPirce : 0,
countTotal: json.data[0].countTotal ? json.data[0].countTotal : 0,
isloading: false,
showSkeleton: false,
})
}, 0)
}).catch(res => {
console.log('getCookList-catch', res);
this.selectComponent("#network").show('网络不给力,请检查网络后重试');
});
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})