-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
236 lines (236 loc) · 7.01 KB
/
app.js
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
//app.js
App({
onLaunch: function () {
//调用API从本地缓存中获取数据
var logs = wx.getStorageSync('logs') || []
logs.unshift(Date.now())
wx.setStorageSync('logs', logs)
},
getUserInfo:function(cb){
var that = this
if(this.globalData.userInfo){
typeof cb == "function" && cb(this.globalData.userInfo)
}else{
//调用登录接口
wx.login({
success: function () {
wx.getUserInfo({
success: function (res) {
that.globalData.userInfo = res.userInfo
typeof cb == "function" && cb(that.globalData.userInfo)
}
})
}
})
}
},
globalData:{
userInfo:null,
good_hash: {
"239": {
"id": 239,
"name": "百岁山矿泉水",
"desc": "",
"price": "3.0",
"unit": "瓶",
"img": "http://o6wlxof9f.bkt.clouddn.com/i/cD4VSorB.jpg-g",
"detail_img": "http://o6wlxof9f.bkt.clouddn.com/i/cD4VSorB.jpg-d"
},
"240": {
"id": 240,
"name": "可口可乐500ml",
"desc": "",
"price": "3.0",
"unit": "瓶",
"img": "http://o6wlxof9f.bkt.clouddn.com/i/xIfIOJxi.jpg-g",
"detail_img": "http://o6wlxof9f.bkt.clouddn.com/i/xIfIOJxi.jpg-d"
},
"241": {
"id": 241,
"name": "可口可乐零度500ml",
"desc": "",
"price": "3.0",
"unit": "瓶",
"img": "http://o6wlxof9f.bkt.clouddn.com/i/tKUsCiLu.jpg-g",
"detail_img": "http://o6wlxof9f.bkt.clouddn.com/i/tKUsCiLu.jpg-d"
},
"242": {
"id": 242,
"name": "可口可乐零度灌装330ml",
"desc": null,
"price": "3.0",
"unit": "灌",
"img": "http://o6wlxof9f.bkt.clouddn.com/i/j1cD3TQd.jpg-g",
"detail_img": "http://o6wlxof9f.bkt.clouddn.com/i/j1cD3TQd.jpg-d"
},
"250": {
"id": 250,
"name": "可口可乐1.5L",
"desc": null,
"price": "5.5",
"unit": "瓶",
"img": "http://o6wlxof9f.bkt.clouddn.com/i/umueuaF0.jpg-g",
"detail_img": "http://o6wlxof9f.bkt.clouddn.com/i/umueuaF0.jpg-d"
},
"252": {
"id": 252,
"name": "可口可乐灌装330ml",
"desc": "",
"price": "2.5",
"unit": "灌",
"img": "http://o6wlxof9f.bkt.clouddn.com/i/p6o8agsz.jpg-g",
"detail_img": "http://o6wlxof9f.bkt.clouddn.com/i/p6o8agsz.jpg-d"
},
"255": {
"id": 255,
"name": "百事可乐600ml",
"desc": null,
"price": "3.0",
"unit": "瓶",
"img": "http://o6wlxof9f.bkt.clouddn.com/i/aL7dQtqf.jpg-g",
"detail_img": "http://o6wlxof9f.bkt.clouddn.com/i/aL7dQtqf.jpg-d"
},
"256": {
"id": 256,
"name": "百事可乐灌装330ml",
"desc": "",
"price": "2.5",
"unit": "灌",
"img": "http://o6wlxof9f.bkt.clouddn.com/i/nrkZDQX4.jpg-g",
"detail_img": "http://o6wlxof9f.bkt.clouddn.com/i/nrkZDQX4.jpg-d"
},
"257": {
"id": 257,
"name": "雪碧柠檬500ml",
"desc": null,
"price": "3.0",
"unit": "瓶",
"img": "http://o6wlxof9f.bkt.clouddn.com/i/wFe3otQ2.jpg-g",
"detail_img": "http://o6wlxof9f.bkt.clouddn.com/i/wFe3otQ2.jpg-d"
},
"259": {
"id": 259,
"name": "雪碧灌装330ml",
"desc": null,
"price": "2.5",
"unit": "灌",
"img": "http://o6wlxof9f.bkt.clouddn.com/i/qHx0jce3.jpg-g",
"detail_img": "http://o6wlxof9f.bkt.clouddn.com/i/qHx0jce3.jpg-d"
},
"260": {
"id": 260,
"name": "芬达",
"desc": "口味:葡萄味,青柠味,橙子味,蜜桃味,苹果味。购买时请备注好口味",
"price": "3.0",
"unit": "瓶装",
"img": "http://o6wlxof9f.bkt.clouddn.com/i/cs5V8p7Q.png-g",
"detail_img": "http://o6wlxof9f.bkt.clouddn.com/i/cs5V8p7Q.png-d"
},
"264": {
"id": 264,
"name": "怡泉+c柠檬味汽水330ml",
"desc": null,
"price": "3.0",
"unit": "灌",
"img": "http://o6wlxof9f.bkt.clouddn.com/i/AKBAOzJZ.jpg-g",
"detail_img": "http://o6wlxof9f.bkt.clouddn.com/i/AKBAOzJZ.jpg-d"
},
"266": {
"id": 266,
"name": "芬达橙子味灌装330ml",
"desc": null,
"price": "3.0",
"unit": "灌",
"img": "http://o6wlxof9f.bkt.clouddn.com/i/cQRsBZ3O.jpg-g",
"detail_img": "http://o6wlxof9f.bkt.clouddn.com/i/cQRsBZ3O.jpg-d"
},
"325": {
"id": 325,
"name": "可口可乐1.25L",
"desc": null,
"price": "5.5",
"unit": "瓶",
"img": "http://o6wlxof9f.bkt.clouddn.com/i/WoNfCTc2.png-g",
"detail_img": "http://o6wlxof9f.bkt.clouddn.com/i/WoNfCTc2.png-d"
},
"326": {
"id": 326,
"name": "雪碧柠檬1.25L",
"desc": null,
"price": "6.5",
"unit": "瓶",
"img": "http://o6wlxof9f.bkt.clouddn.com/i/KScikqGq.png-g",
"detail_img": "http://o6wlxof9f.bkt.clouddn.com/i/KScikqGq.png-d"
},
"327": {
"id": 327,
"name": "百事可乐1.25L",
"desc": null,
"price": "5.5",
"unit": "瓶",
"img": "http://o6wlxof9f.bkt.clouddn.com/i/hVpc5NWy.jpg-g",
"detail_img": "http://o6wlxof9f.bkt.clouddn.com/i/hVpc5NWy.jpg-d"
},
"392": {
"id": 392,
"name": "摩拉菲尔酸奶205ml",
"desc": "口味:红枣枸杞 、原味。购买时请备注口味",
"price": "5.5",
"unit": "盒",
"img": "http://o6wlxof9f.bkt.clouddn.com/i/YeL3yN9R.jpg-g",
"detail_img": "http://o6wlxof9f.bkt.clouddn.com/i/YeL3yN9R.jpg-d"
},
"393": {
"id": 393,
"name": "维他奶系列250ml",
"desc": "口味:原味、黑豆味、香草味、麦香味。购买时请备注口味",
"price": "3.0",
"unit": "盒",
"img": "http://o6wlxof9f.bkt.clouddn.com/i/of0yhZCz.jpg-g",
"detail_img": "http://o6wlxof9f.bkt.clouddn.com/i/of0yhZCz.jpg-d"
}
}
},
get_cart: function(){
return wx.getStorageSync("cart") || {}
},
handle_click_cart_icon: function(){
wx.navigateTo({
url: '../cart/index',
})
},
get_good: function(good_id){
return this.globalData.good_hash[good_id.toString()]
},
get_amount: function(good_id){
var cart = this.get_cart()
return cart[good_id] || 0
},
set_amount: function(good_id, amount, success, fail){
var cart = this.get_cart()
if(amount > 99){
amount = 99
}
if(amount < 0)
{
amount = 0
}
if(amount == 0){
delete(cart[good_id])
}
else{
cart[good_id] = amount
}
wx.setStorage({
key: "cart",
data: cart,
success: success,
fail: fail
})
},
change_amount: function(good_id, plus, success, fail){
var amount = this.get_amount(good_id)
amount += plus
this.set_amount(good_id, amount, success, fail)
}
})