food-spec.js
13.8 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
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
// component/menu/addDelete.js
import util from '../../../utils/util';
import App from '../../../utils/api';
const {regeneratorRuntime} = global
Component({
/**
* 组件的属性列表
*/
properties: {
item: {
type: Object // 类型(必填),目前接受的类型包括:String, Number, Boolean, Object, Array, null(表示任意类型)
},
type: {
type: String,
default: '+'
},
sellerid: {
type: Number
},
orderid: {
type: Number
},
fromSoucre: {
type: Number,
value: 0
},
request_uri: {
type: Boolean,
value: false,
},
identity: {
type: String,
value: "",
}
},
/**
* 组件的初始数据
*/
data: {
hiddenFoodSpec: true,//加菜规格
hiddenFoodSpecReduce: true,//减菜规格
selectKind: [{title: 'xxxxx'}, {title: 'yyyyy'}],
},
ready () {
},
detached(){
},
/**
* 组件的方法列表
*/
methods: {
init(){
console.log('food-spec init');
this.setData({
hiddenFoodSpec: false
})
},
//关闭规格框
close: function () {
this.setData({
hiddenFoodSpec: true,
hiddenFoodSpecReduce: true,
})
//关闭了规格窗口
this.triggerEvent('foodSpecCallback', {
type: 'specWin',
value: 'hide'
});
},
//构造KindMenu
initKindMenu(){
return new Promise((success, fail) => {
let price = this.data.item.price;
let hasSpec = this.data.item.spec.length > 0;
let hasPractice = this.data.item.practice.length > 0;
if (hasSpec || hasPractice) {
var specs = this.data.item.spec//规格
var practice = this.data.item.practice//做法
var kind = []
var foodMenu = []
if (this.data.type == '-') {
if (specs) {
specs.map(function (r, n) {
if (r.id) {//某规格卖光了 就不显示 && r.clear_num>1
kind.push({id: r.id, price: r.price, title: r.specs, iskind: false})
}
})
}
if (practice) {
practice.map(function (r, n) {
if (r.id) {
foodMenu.push({id: r.id, price: r.price, title: r.name, iskind: false})
}
})
}
App.Advance.GetCookbookSelBySpecsId({
sellerid: this.data.sellerid,
orderid: this.data.orderid,
cookbookid: this.data.item.id,
status: this.data.fromSoucre != '' ? 2 : '',//只查没有下单的
identity: this.data.identity
}).then(res => {
this.setData({
selectKind: res.data,
hiddenFoodSpecReduce: false,
kind: kind ? kind : '',
foodMenu: foodMenu,
})
})
} else {
specs.map(function (r, n) {
if ((r.id && r.clear_num > 0) || r.clear_num == null) {//某规格卖光了 就不显示 && r.clear_num>1
kind.push({id: r.id, price: r.price, title: r.specs, iskind: false})
}
})
if (kind.length > 0) {
kind[0].iskind = true;
var kindPrice = kind[0].price;
var specs_id = kind[0].id;
}
practice.map(function (r, n) {
if (r.id) {
foodMenu.push({id: r.id, price: price, title: r.name, iskind: false})
}
})
if (foodMenu.length > 0) {
foodMenu[0].iskind = true;
var foodMenuPrice = foodMenu[0].price;
var practice_id = foodMenu[0].id;
}
this.setData({
selectKind: [],
hiddenFoodSpec: false,
kind: kind,
foodMenu: foodMenu,
showSpecsPrice: false,
cookbook_name: this.data.item.name,
cookbook_id: this.data.item.id,
specs_id: specs_id ? specs_id : '',
practice_id: practice_id ? practice_id : '',
selectPrice: kindPrice > 0 ? kindPrice : foodMenuPrice,
add_target: ''
})
}
success();
} else {
fail();
}
});
},
//选择规格
kindSelect: function (e) {
var index = e.currentTarget.dataset.key
var specsid = e.currentTarget.id
var price = e.currentTarget.dataset.price
for (var i = 0; i < this.data.kind.length; i++) {
if (i == index) {
this.data.kind[i].iskind = true;
} else {
this.data.kind[i].iskind = false;
}
}
var is_show = ''
if (this.data.foodMenu == '') {
is_show = 1
} else if (specsid && this.data.practice_id) {
is_show = 1
}
this.setData({
kind: this.data.kind,
selectPrice: price,
specs_id: specsid,
foodMenu: this.data.foodMenu ? this.data.foodMenu : '',
showSpecsPrice: price ? false : true,
showAdd: is_show ? false : true//showAdd:specsid?false:true
});
},
//选择做法
menuSelect: function (e) {
var index = e.currentTarget.dataset.key
var practiceid = e.currentTarget.id
var price = e.currentTarget.dataset.price
for (var i = 0; i < this.data.foodMenu.length; i++) {
if (i == index) {
this.data.foodMenu[i].iskind = true;
} else {
this.data.foodMenu[i].iskind = false;
}
}
var is_show = ''
if (this.data.kind == '') {
is_show = 1
} else if (this.data.specs_id && practiceid) {
is_show = 1
}
this.setData({
foodMenu: this.data.foodMenu,
foodMenuPrice: price,
practice_id: practiceid,
showAdd: is_show ? false : true
});
},
//加菜面板
addCook: function (e) {
console.log('addCook', this.data.item, e);
var cookbookid = this.data.item.identity>=0?this.data.item.cookbookid:this.data.item.id
var price = this.data.item.price;
this.initKindMenu().then(res => {
//打开了规格窗口
this.triggerEvent('foodSpecCallback', {
type: 'specWin',
value: 'show'
});
}).catch(res => {
console.log('initKindMenu', res);
if (this.data.item.clear_num && this.data.item.clear_num > 0
&& this.data.item.num + 1 > this.data.item.clear_num) {
wx.showToast({
title: '该菜品最多能点' + this.data.item.clear_num + '份',
duration: 2000,
mask: true,
icon: 'none'
});
return;
}
//通知
this.triggerEvent('foodSpecCallback', {
cookbookid: cookbookid,
type: 1,
});
//this.matchArray(cookbookid,1,countTotal,countPirce)
let params={
orderid: this.data.orderid,
openid: util.cache('openid'),
cookbookid: cookbookid,
price: price,
source: 1,
request_uri: this.data.request_uri == true ? 1 : '',//服务员通过消息通知进来 又加菜的标识
fromSoucre: this.data.fromSoucre ? this.data.fromSoucre : '',
identity: this.data.identity
}
if(this.data.item.specid>0){
params.specid=this.data.item.specid;
}
if(this.data.item.practiceid>0){
params.practiceid=this.data.item.practiceid;
}
App.Advance.AddCart(params);
});
},
//减菜面板
subtractCook(){
console.log('subtractCook', this.data.item);
var cookbookid = this.data.item.identity>=0?this.data.item.cookbookid:this.data.item.id
var price = this.data.item.price;
this.initKindMenu().then(res => {
//打开了规格窗口
this.triggerEvent('foodSpecCallback', {
type: 'specWin',
value: 'show'
});
}).catch(res => {
//通知
this.triggerEvent('foodSpecCallback', {
cookbookid: cookbookid,
type: -1,
});
let params={
orderid: this.data.orderid,
openid: getApp().openid,
cookbookid: cookbookid,
//specid: specid ? specid : '',
//practiceid: specid ? specid : '',
fromSoucre: this.data.fromSoucre ? this.data.fromSoucre : '',
request_uri: this.data.request_uri == true ? 1 : '',//服务员通过消息通知进来 又加菜的标识
status: this.data.fromSoucre != '' ? 2 : '',//只查没有下单的
source: 2,
identity: this.data.identity
}
if(this.data.item.specid>0){
params.specid=this.data.item.specid;
}
if(this.data.item.practiceid>0){
params.practiceid=this.data.item.practiceid;
}
App.Advance.ReduceOrder(params);
});
},
//减菜面板加菜按钮
add: function (e) {
console.log('add', util.attr(e, 'cookbookid'), e);
let index = util.attr(e, 'index');
let selectKind = this.data.selectKind;
console.log('selectKind', selectKind, index);
let specs = this.data.item.spec;
let clear_num = null;
specs.forEach(spec => {
if (spec.id == selectKind[index].specid) {
clear_num = spec.clear_num;
}
})
if (clear_num && clear_num > 0
&& selectKind[index].foodNum + 1 > clear_num) {
wx.showToast({
title: '该菜品最多能点' + clear_num + '份',
duration: 2000,
mask: true,
icon: 'none'
});
return;
}
selectKind[index].foodNum = parseInt(selectKind[index].foodNum) + 1;
this.setData({selectKind: selectKind});
this.formSubmit(e, true);
},
//减菜面板减菜按钮
reduce(e){
console.log('reduce', util.attr(e, 'cookbookid'), e);
var cookbookid = util.attr(e, 'cookbookid')
var specid = util.attr(e, 'specid')
var practice_id = util.attr(e, 'practiceid')
var price = util.attr(e, 'price')
let index = util.attr(e, 'index');
let selectKind = this.data.selectKind;
selectKind[index].foodNum -= 1;
if (selectKind[index].foodNum <= 0) {
selectKind.splice(index, 1);
}
this.setData({selectKind: selectKind});
if (selectKind.length < 1) {
this.close();
}
this.triggerEvent('foodSpecCallback', {
cookbookid: cookbookid,
type: -1
});
//执行删除操作
let params = {
orderid: this.data.orderid,
openid: getApp().openid,
cookbookid: cookbookid,
fromSoucre: this.data.fromSoucre ? this.data.fromSoucre : '',
status: this.data.fromSoucre ? 2 : '',//只查没有下单的
request_uri: this.data.request_uri == true ? 1 : '',//服务员通过消息通知进来 又加菜的标识
source: 2,
identity: this.data.identity
};
if (specid > 0) {
params.specid = specid;
}
if (practice_id > 0) {
params.practiceid = practice_id;
}
App.Advance.ReduceOrder(params);
},
/**
*
* @param e
* @param subtractCook 减菜面板
*/
formSubmit(e, subtractCook = false){
if (subtractCook) {//减菜面板
var cookbookid = util.attr(e, 'cookbookid')
var specid = util.attr(e, 'specid')
var practice_id = util.attr(e, 'practiceid')
var price = util.attr(e, 'price')
} else {
var cookbookid = util.val(e, 'cookbookid')
var specid = util.val(e, 'specs_id')
var practice_id = util.val(e, 'practice_id')
var price = util.val(e, 'price')
if (this.data.selectPrice) {
console.log(666666, this.data.selectPrice)
price = this.data.selectPrice
} else {
console.log('yyyyyy', this.data.foodMenuPrice)
price = this.data.foodMenuPrice
}
this.close();
}
console.log('formSubmit', cookbookid,specid, practice_id, price)
//return;
let selectKindNum = 0;
if (this.data.selectKind) {
this.data.selectKind.forEach((kind) => {
if (kind.specid == specid) {
selectKindNum = kind.foodNum
}
})
}
console.log('selectKindNum', this.data.selectKind, selectKindNum);
if (selectKindNum > 0) {
let clear_num = null;
let specs = this.data.item.spec;
specs.forEach(spec => {
if (spec.id == specid) {
clear_num = spec.clear_num;
}
})
if (clear_num && clear_num > 0
&& selectKindNum + 1 > clear_num) {
wx.showToast({
title: '该菜品最多能点' + clear_num + '份',
duration: 2000,
mask: true,
icon: 'none'
});
return;
}
}
this.triggerEvent('foodSpecCallback', {
cookbookid: cookbookid,
type: 1
});
let param = {
orderid: this.data.orderid,
openid: util.cache('openid'),
cookbookid: cookbookid,
price: price,
source: 1,
request_uri: this.data.request_uri == true ? 1 : '',//服务员通过消息通知进来 又加菜的标识
fromSoucre: this.data.fromSoucre ? this.data.fromSoucre : '',
identity: this.data.identity
}
if (specid > 0) {
param.specid = specid;
}
if (practice_id > 0) {
param.practiceid = practice_id;
}
App.Advance.AddCart(param);
},
//清除订单下某菜品所有数量
clean(){
let cookbookid = this.data.item.id
this.triggerEvent('foodSpecCallback', {
cookbookid: cookbookid,
type: this.data.item.num * -1
});
App.Advance.ClearCookById({
orderid: this.data.orderid,
sellerid: this.data.sellerid,
cookbookid: cookbookid
});
}
}
})