food-card.js
3.15 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
// 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(表示任意类型)
},
sellerid: {
type: Number
},
orderid: {
type: Number
},
fromSoucre: {
type: Number,
value: 0
},
request_uri: {
type: Boolean,
value: false,
},
hasListModel: {
type: Boolean,
value: false,
},
identity: {
type: String,
value: '',
},
seeAll:String,//只看标识
},
/**
* 组件的初始数据
*/
data: {
item_clear_num: null,
hasIPhone: false,
labelIcon: {
'https://xt05.colorcun.com/uploads/label/lijie.png': '力荐',
'https://xt05.colorcun.com/uploads/label/tejia.png': '特价',
'https://xt05.colorcun.com/uploads/label/xinpin.png': '新品',
'https://xt05.colorcun.com/uploads/label/zhaopai.png': '招牌',
},
},
attached () {
console.log('food-card-ready', this.data.orderid, this.data.fromSoucre)
let item = this.data.item;
let item_clear_num;
if (typeof item.item_clear_num != 'undefined') {
item_clear_num = item.item_clear_num;
} else {
item_clear_num = item.clear_num;
if (item.spec) {
let clear_num = null;
item.spec.forEach(spec => {
if (spec.clear_num == 0) {
clear_num = 0;
} else {
clear_num = null;
}
})
if (clear_num == 0) {
item_clear_num = 0;
}
}
}
this.setData({
item_clear_num: item_clear_num,
hasIPhone: getApp().system.model.indexOf('iPhone') > -1
});
},
detached(){
},
/**
* 组件的方法列表
*/
methods: {
//规格 增加/减少 回调
foodSpecCallback(e){
let opt = e.detail;
console.log('foodSpecCallback', opt);
if (opt.type == 'specWin') {
return this.triggerEvent('foodCardCallback', opt);
}
let item = this.data.item;
let oldNum = (item.num || 0);
item.num = (item.num || 0) + opt.type;
let rotateFlag = (oldNum == 0 || item.num == 0);
console.log('num_rotate', rotateFlag);
this.setData({item: item, rotate_id: rotateFlag ? item.id : ''});
opt.num = item.num;
this.triggerEvent('foodCardCallback', opt);
},
//清除订单下某菜品所有数量
delOrderCook: function () {
this.selectComponent("#foodSpecDel").clean();
},
//triggerAdd
triggerAdd(e){
console.log('triggerAdd', e)
if (this.data.item_clear_num == 0) return;
this.selectComponent("#foodSpecAddOne").addCook();
},
//viewIMage
viewImage(){
wx.previewImage({
current: this.data.item.image, // 当前显示图片的http链接
urls: [this.data.item.image], // 需要预览的图片http链接列表
})
},
foodSpecAdd(e){
this.selectComponent("#foodSpecAdd-"+util.attr(e,'id')).addCook();
},
},
})