index.js
11.6 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
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
//首页数据调用、
//function getData(){
// var url = '/Index/index'
// var params = {
// t_id: '',
// unique_id: localStorage.getItem('unique_id')
//
// }
// ajaxsend(url,params,function(res){
// /*console.log(JSON.stringify(res))*/
// console.log(res);
// var data=res.data;
// console.log(data);
// var banner = data.banner;
// console.log(banner);
//
// })
//
//}
//
//getData()
/*获取*/
//$(document).ready(function(){
new Vue({
el:'#pageindex',
data: {
banner: [],
goods_list: [],
//头部地点就近自提
address:'',
distance:'',
//头部地点堂食地点
storeaddress:'',
storedistance:'',
//购物车的数量
cartnum:0,
current:-1,
//就近自提点
nearest_spot: {
spot_id: "", //id号
spot_name: "", //名字
},
//到店食堂
nearest_store: {
store_id: "",
store_name: "",
},
type: [],
//食堂列表
storelist:[],
//自取点城市
selfarea:[],
//每个区域的具体自提
spot:[],
//就近自提地点
nearest_spot:[],
//就近堂食地点
nearest_store:[],
nearaddress:'',
yespot:true,
yestore:false,
},
created: function() {
this.details();
this.selfaddress();
this.store();
this.num();
this.initSwiper()
//缓存顶部的地址
// this.getaddress();
},
methods: {
initSwiper(){
var swiper = new Swiper('.swiper-container', {
pagination: '.swiper-pagination',
paginationClickable: true,
observer:true, //修改swiper自己或子元素时,自动初始化swiper
observeParents:true//修改swiper的父元素时,自动初始化swiper
});
},
//获取信息
details: function() {
var that = this;
var url = '/Index/index'
var params = {
t_id: '',
unique_id: localStorage.getItem('unique_id')
}
ajaxsend(url, params, function(res) {
/*console.log(JSON.stringify(res))*/
console.log(res);
var data = JSON.parse(JSON.stringify(res.data));
if(data=="暂无商品"){
// alert('暂无商品');
return false;
}else{
console.log(data);
//banner图
that.banner = data.banner;
setTimeout(()=>{
that.initSwiper()
},1500)
//食品列表
var goods_list=data.goods_list;
that.goods_list=goods_list;
//美食种类
var type=data.type;
that.type=type;
console.log(that.type);
//最近的自提地点
that.nearest_spot=data.nearest_spot;
var nearspot=that.nearest_spot;
that.address=nearspot.spot_name;
var spotname=nearspot.spot_name;
var spotid=nearspot.spot_id;
//保存就近自提的地址
localStorage.setItem('spotaddress',spotname);
localStorage.setItem('spot_id',spotid)
// console.log(localStorage)
//就近堂食地点
that.nearest_store=data.nearest_store;
var nearstore=that.nearest_store;
that.storeaddress=nearstore.store_name;
//保存食堂的地点
var storename=nearstore.store_name;
var storeid=nearstore.store_id
localStorage.setItem('storeaddress',storename);
localStorage.setItem('store_id',storeid);
}
})
},
//获取自提点区域列表
selfaddress:function(){
var that=this;
var url = '/Spot/index'
var params = {
area_id: '',
unique_id: localStorage.getItem('unique_id')
}
ajaxsend(url, params, function(res) {
/*console.log(JSON.stringify(res))*/
console.log(res);
var data=res.data;
var selfarea=data.area;
console.log(selfarea);
that.selfarea=selfarea;
console.log(that.selfarea);
that.ads();
})
},
ads(){
var that=this;
console.log(that.selfarea[0]);
var areaid=that.selfarea[0].area_id;
var url = '/Spot/index';
var params = {
area_id: areaid,
unique_id: localStorage.getItem('unique_id')
}
ajaxsend(url, params, function(res) {
/*console.log(JSON.stringify(res))*/
console.log(res);
var data=res.data;
var spot=data.spot;
that.spot=spot;
})
},
//获取每个区域的地点
add:function(area_id){
window.event.stopPropagation();
var that=this;
var areaid=area_id;
var url = '/Spot/index'
var params = {
area_id: areaid,
unique_id: localStorage.getItem('unique_id')
}
ajaxsend(url, params, function(res) {
/*console.log(JSON.stringify(res))*/
console.log(res);
var data=res.data;
var spot=data.spot;
that.spot=spot;
})
},
//获取店铺列表
store:function(){
var that=this;
var url = '/Store/storeList'
var params = {
unique_id: localStorage.getItem('unique_id')
}
ajaxsend(url, params, function(res) {
/*console.log(JSON.stringify(res))*/
console.log(res);
var data=res.data;
that.storelist=data;
})
},
//加入购物车
addcart:function(goods_id){
var that=this;
window.event.stopPropagation();
var goodid=goods_id;
var num=1;
var url='/Cart/add';
var params = {
goods_id:goodid,
unique_id: localStorage.getItem('unique_id'),
goods_num:num
}
ajaxsend(url, params, function(res) {
/*console.log(JSON.stringify(res))*/
console.log(res);
if(res.state=="success"){
// alert("添加成功");
window.location.reload();
load();
}else if(res.state=="fail"){
// alert("库存不足");
unstock()
}
})
},
//添加购物车数量
addnum:function(obj){
window.event.stopPropagation();
var that=this;
var adnum="";
console.log(obj);
var cartid=obj.cart_id;
console.log(cartid);
adnum=parseInt(obj.goods_num);
obj.goods_num++;
adnum+=1;
// //更改购物车里的数量
var url = '/Cart/editNum';
var params = {
cart_id:cartid,
goods_num:adnum
}
ajaxsend(url, params, function(res) {
/*console.log(JSON.stringify(res))*/
console.log(res);
if(res.status==true){
// load();
window.location.reload();
}else if(res.status==false){
unstock()
// alert("库存不足");
// window.location.reload();
}
})
},
//减少购物车里的数量
reducenum:function(obj){
window.event.stopPropagation();
var that=this;
var adnum="";
console.log(obj);
var cartid=obj.cart_id;
console.log(cartid);
adnum=parseInt(obj.goods_num);
//剩一个商品的时候
if(adnum==1){
var that=this;
//var con=confirm("是否删除该商品");
//var carid=cart_id;
var url='/Cart/del';
var params = {
cart_id:cartid
}
ajaxsend(url, params, function(res) {
/*console.log(JSON.stringify(res))*/
console.log(res);
if(res.status==true){
//alert("删除成功");
window.location.reload();
}
})
}else{
obj.goods_num--;
adnum-=1;
//// var itemmoney=adnum*obj.goods_price;
//// itemmoney=Math.floor(itemmoney * 100) / 100;
//// console.log(itemmoney);
// //更改购物车里的数量
var url = '/Cart/editNum';
var params = {
cart_id:cartid,
goods_num:adnum
}
ajaxsend(url, params, function(res) {
/*console.log(JSON.stringify(res))*/
console.log(res);
if(res.status==true){
// alert("更改成功");
window.location.reload();
}else if(res.status==false){
unstock()
// window.location.reload();
}
})
}
},
//购物车数量
num:function(){
var that=this;
var url='/CountNum/countCart';
var params = {
unique_id: localStorage.getItem('unique_id')
}
ajaxsend(url, params, function(res) {
/*console.log(JSON.stringify(res))*/
console.log(res);
var data=res.data;
console.log(data[0].count)
that.cartnum=data[0].count;
console.log(that.cartnum)
})
},
find:function(t_id,index){
var that=this;
var food_id=t_id;
//改变每一个类型的颜色
that.current=index;
var el=document.getElementsByClassName("nav_list_item");
$(el).removeClass("active")
var url = '/Index/index'
var params = {
t_id: food_id,
unique_id: localStorage.getItem('unique_id')
}
ajaxsend(url, params, function(res) {
/*console.log(JSON.stringify(res))*/
console.log(res);
var data=res.data;
var goods_list=data.goods_list;
that.goods_list=goods_list;
if(data=="暂无商品"){
// alert("暂无商品");
that.goods_list=[];
}
})
},
//获取全部食品
allfood:function(){
var that=this;
var url = '/Index/index'
var el=document.getElementsByClassName("nav_list_item");
$(el).addClass("active");
$(el).siblings().removeClass("active")
var params = {
t_id: '',
unique_id: localStorage.getItem('unique_id')
}
ajaxsend(url, params, function(res) {
/*console.log(JSON.stringify(res))*/
console.log(res);
var data = JSON.parse(JSON.stringify(res.data));
console.log(data);
//食品列表
var goods_list=data.goods_list;
that.goods_list=goods_list;
})
},
//跳转自提点详情
jump:function(spot_id){
window.location.href='/index.php?g=&m=template&a=TakeDetails&id='+spot_id;
},
//跳转食堂详情
jumpaddress:function(obj){
window.event.stopPropagation();
// console.log(JSON.parse(event.target.id))
console.log(obj);
var storeid=obj.store_id;
console.log(storeid);
window.location.href=linkPath+'/addressdetails.html?id='+storeid;
},
//食品详情
fooddetail:function(goods_id){
var that=this;
var goodid=goods_id;
window.location.href=linkPath+'/productdetails.html?id='+goodid;
},
//切换地点
areaspot:function(){
var that=this;
that.yespot=true;
that.yestore=false;
},
areastore:function(){
var that=this;
that.yespot=false;
that.yestore=true;
},
//切换就近自提地点
cartpay:function(obj){
var that=this;
that.yespot=true;
that.yestore=false;
console.log(obj);
that.address=obj.spot_name;
that.distance=',距您'+obj.distance_text;
var spotplace=obj.spot_name+',距您'+obj.distance_text;
console.log(spotplace)
//把地址存在localstorage里
localStorage.setItem('spotaddress',spotplace);
localStorage.setItem('spot_id',obj.spot_id);
},
//切换食堂地点
changespot:function(obj){
var that=this;
that.yespot=false;
that.yestore=true;
console.log(obj);
that.storeaddress=obj.store_address;
that.storedistance=',距您'+obj.distance_text;
var storeplace=obj.store_address+',距您'+obj.distance_text;
localStorage.setItem('storeaddress',storeplace);
localStorage.setItem('store_id',obj.store_id);
// console.log(localStorage);
}
// //缓存顶部的地址
// getaddress:function(){
// var that=this;
// var spotaddress=that.address;
// console.log(spotaddress)
// }
}
})
//});