app.js
21.5 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
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
var t = require("setting.js"), o = require("./utils/auth.js"), a = require("./utils/request.js"), e = require("./utils/common.js"), ut = require("./utils/util.js");
var os=t;
var regeneratorRuntime = require('./utils/runtime.js');
var api = require("./api/api.js")
//公共方法和变量
App({
def_list:[
{
"weappurl": "pages/index/index/index",
"nav_name": "首页",
"src": t.imghost+"/miniapp/images/bar/index.png",
"src_sele": t.imghost+"/miniapp/images/bar/index_on.png",
},
{
"weappurl": "pages/goods/categoryList/categoryList",
"nav_name": "分类",
"src": t.imghost+"/miniapp/images/bar/fl.png",
"src_sele": t.imghost+"/miniapp/images/bar/fl_on.png"
},
{
"weappurl": "pages/distribution/distribution",
"nav_name": "分销",
"src": t.imghost+"/miniapp/images/bar/fx.png",
"src_sele": t.imghost+"/miniapp/images/bar/fx_on.png"
},
{
"weappurl": "pages/cart/cart/cart",
"nav_name": "购物车",
"src": t.imghost+"/miniapp/images/bar/car.png",
"src_sele": t.imghost+"/miniapp/images/bar/car_on.png"
},
{
"weappurl": "pages/user/index/index",
"nav_name": "我的",
"src": t.imghost+"/miniapp/images/bar/user.png",
"src_sele": t.imghost+"/miniapp/images/bar/user_on.png"
}
],
globalData: {
cartGoodsNum:0, //购物车总数量
isTabBar :false,
isIpx: false, //适配IPhoneX
url:"",
setting: t,
wechatUser: null,
userInfo: null,
config: null, //门店参数
config2: null, //门店配置
code: null,
heigth:0,
user_id:null,// 3674923,// 4379287,// null,// 5682068,
buy_now:null,
picklist:null, //门店列表
wuliuprice: null, //物流价格表
wuliu: null, //物流公司
baddr:null,
mobile: null, //记录手机
getu:null, //记录会员信息
sessionKey: null,//记录会员信息
openid: null, //记录会员信息
to_group:null, //参团传递的数据
wxapp_buy_obj:null, //微信小程序购买的Object
pk_store:null, //选择的门店
first_leader:null, //分享会员ID
guide_id:null, //分享导购ID
windowWidth:0, //整个窗体的宽度
room_id:null, //直播间分享的房间ID
room_goods_id:null, //直播间分享的商品ID
},
auth: o,
request: a,
onLaunch: function() {
wx.hideTabBar();
this.initExt();
var t = this.globalData.setting;
//console.log(t)
t.resourceUrl = t.url + "/template/mobile/rainbow";
var clientWidth = wx.getSystemInfoSync().windowWidth;
var rpxR = 750 / clientWidth;
var calc = wx.getSystemInfoSync().windowHeight * rpxR;
this.globalData.heigth=calc;
this.globalData.windowWidth=clientWidth;
var app=this;
if(!app.globalData.userInfo){
var user = wx.getStorageSync("userinfo");
if (user && user.user_id){
app.globalData.userInfo=wx.getStorageSync("userinfo");
app.globalData.user_id= app.globalData.userInfo.user_id;
}
}
wx.getSystemInfo({
success: (res) => {
// console.log(res)
let modelmes = res.model; //手机品牌
console.log('手机品牌', modelmes)
if (modelmes.indexOf('iPhone X') != -1) { //XS,XR,XS MAX均可以适配,因为indexOf()会将包含'iPhone X'的字段都查出来
this.globalData.isIpx = true
}
},
})
var th=this;
var pages = getCurrentPages(); //获取加载的页面
var currentPage = pages[pages.length - 1]; //获取当前页面的对象
if(!currentPage || currentPage.route.indexOf('error/error')==-1){
var tt=this.globalData.wxapp_buy_obj;
if (!tt){
this.get_isbuy(function (){
tt=th.globalData.wxapp_buy_obj;
if (tt.isout == 1){
th.promiseGet('/api/weshop/store/get/'+t.stoid,{}).then(res=>{
wx.reLaunch({
url: "/pages/error/error?msg=该商城已到期,暂停浏览!\r\n可联系:"+res.data.data.store_tel,
});
})
}
else if (tt.isbuy == 0)
wx.reLaunch({
url: "/pages/error/error?msg=还未购买小程序",
});
})
}
}
},
//---初始化第三方----
initExt: function() {
var tt=t;
console.log("initExt");
console.log(11);
var t = wx.getExtConfigSync(), o = this.globalData.setting;
console.log(t);
t.appName ? (o.appName = t.appName, o.stoid = t.stoid) : tt=1;
},
//首页的第一次登录
getUserFir(t){
var s = this;
if (o.isAuth()) "function" == typeof t && t(s.globalData.userInfo, s.globalData.wechatUser); else {
if (!o.isAuth()) return o.wxLogin_fir(t);
if (null == s.globalData.userInfo) {
return o.wxLogin_fir(t);
}
}
},
getUserInfo: function(t, n, i) {
var s = this;
if (o.isAuth()) "function" == typeof t && t(s.globalData.userInfo, s.globalData.wechatUser); else {
if (!o.isAuth()) return o.auth(t);
if (null == s.globalData.userInfo){
return o.auth(t);
}
/*---
a.get("/api/user/userInfo", {
isShowLoading: void 0 === i || i,
success: function(o) {
s.globalData.userInfo = o.data.result, s.globalData.userInfo.head_pic = e.getFullUrl(s.globalData.userInfo.head_pic),
"function" == typeof t && t(s.globalData.userInfo, s.globalData.wechatUser);
}
});--*/
}
},
//----------------获取配置参数--------------------
getConfig: function(t, o) {
var e = this; if(this.globalData.config==undefined) this.globalData.config=null;
this.globalData.config ? "function" == typeof t && t(this.globalData.config) : e.request.get("/api/weshop/store/get/" + e.globalData.setting.stoid, {
success: function(o) {
console.log('getConfig');
if(o.data.code==0){
e.globalData.config = o.data.data, "function" == typeof t && t(e.globalData.config);
}
}
});
},
//----------------获取配置参数--------------------
getConfig2: function (t, o) {
var e = this;
this.globalData.config2 && !o ?
"function" == typeof t && t(this.globalData.config2) : a.get("/api/weshop/storeconfig/get/" + e.globalData.setting.stoid, {
success: function (o) {
console.log('getConfig2');
if (o.data.code == 0) {
e.globalData.config2 = o.data.data, "function" == typeof t && t(e.globalData.config2);
}
}
});
},
//----------------获取商家开启的物流--------------------
getwuliu: function (t, o){
var th = this, st = this.globalData.setting;
this.globalData.wuliu && !o ?
"function" == typeof t && t(this.globalData.wuliu) : a.get("/api/weshop/storeshipping/list", {
data: { store_id: st.stoid, status: 1, pageSize:600 },
success: function (o) {
console.log('getwuliu');
console.log(o);
if (o.data.code == 0 && o.data.data && o.data.data.pageData && o.data.data.pageData.length>0) {
var arr = o.data.data.pageData;
console.log(arr);
arr.forEach(function(item,index){
arr[index].code = item.shipping_code; arr[index].name = item.shipping_name;
})
th.globalData.wuliu = arr, "function" == typeof t && t(arr);
}
}
});
},
//----------------获取物流价格表--------------------
getwuliuprice: function (t, o) {
var e = this,th=e, st = this.globalData.setting;
this.globalData.wuliuprice && !o ?
"function" == typeof t && t(this.globalData.wuliuprice) : a.get("/api/weshop/shippingarea/list",{
data: { store_id: st.stoid,pageSize: 600 },
success: function (o) {
console.log('getwuliuprice');
console.log(o);
if (o.data.code == 0) {
var arr=o.data.data.pageData;
console.log(arr);
if (arr.length>0){
for (var i = 0; i < arr.length;i++){
arr[i].code = arr[i].shipping_code;
if (arr[i].json_config != "" && arr[i].json_config != undefined && arr[i].json_config != null )
arr[i].config = JSON.parse(arr[i].json_config);
}
}
th.globalData.wuliuprice = o.data.data, "function" == typeof t && t(e.globalData.wuliuprice);
}
}
});
},
//----------------设置立即购买数组--------------------
set_b_now: function (d) { this.globalData.buy_now=d;},
get_b_now: function () {return this.globalData.buy_now},
getPrevPageData: function(t) {
void 0 === t && (t = 1);
var o = getCurrentPages();
return o[o.length - t - 1].data;
},
showLoading: function(t, o) {
void 0 === o && (o = 1500), wx.showToast({
title: "加载中",
icon: "loading",
duration: o,
mask: !0,
complete: function() {
"function" == typeof t && setTimeout(t, o);
}
});
},
showSuccess: function(t, o, a) {
void 0 === a && (a = 1e3), wx.showToast({
title: t,
icon: "success",
duration: a,
mask: !0,
complete: function() {
"function" == typeof o && setTimeout(o, a);
}
});
},
showWarning: function(t, o, a, e) {
//var imghost=this.globalData.setting.imghost;
!a && (a = 1500), void 0 === e && (e = !0), wx.showToast({
title: t,
mask: e,
duration: a,
image:"/images/gt.png",
complete: function() {
"function" == typeof o && setTimeout(o, a);
}
});
},
confirmBox: function(t, o) {
wx.showModal({
title: t,
showCancel: !1,
complete: function() {
"function" == typeof o && o();
}
});
},
//----------获取所有的门店------------
get_allsto(func){
var th=this;
if (this.globalData.picklist!=null){
"function" == typeof func && func(th.globalData.picklist);
}else{
th.request.get("/api/weshop/pickup/page", {
data: { store_id: th.globalData.setting.stoid, pageSize: 600 },
success: function (da) {
//设置门店
//th.setData({ allsto: da.data.data.pageData });
th.globalData.picklist = da.data.data.pageData;
"function" == typeof func && func(th.globalData.picklist);
}
})
}
},
//同步化,在调用的时候要await
async get_isbuy(func) {
var th=this
var stoid=os.stoid;
await this.promiseGet("/store/storemoduleendtime/page?store_id=" +stoid + "&type=5",{}).then(res=>{
var o=res;
if (o.data.code == 0) {
var ob = { isout: 0, isbuy: 1 };
var arr = o.data.data.pageData;
var isbuy = 0;
//----如果数组不为空----
if (arr.length > 0) {
arr.forEach(function (val, ind) {
if (val.is_sy == 0 && val.type == 5) {
isbuy = 1;
var now = ut.gettimestamp();
if (now > val.end_time) ob.isout = 1;
return false;
}
})
}
ob.isbuy = isbuy;
th.globalData.wxapp_buy_obj=ob;
if(func){
func();
}
}
})
},
//--同步化,在调用的时候要await,获取商家config--
async getConfig_ays(){
if(this.globalData.config!=null) return false;
var th=this;
await api.get_config(this.globalData.setting.stoid).then(res=>{
var o=res;
if(o.data.code==0){
th.globalData.config = o.data.data;
}
})
},
//----智能跳转,判断 非tabBar,tabBar页面的跳转----
goto:function (url) {
var arr=getCurrentPages();
if(arr.length>8){
arr.splice(0, 2);
}
var arr_tabbar=["/pages/index/index/index",
"/pages/goods/categoryList/categoryList",
"/pages/goods/categoryList/categoryList?type=2",
"/pages/goods/categoryList/categoryList?type=1",
"/pages/cart/cart/cart","/pages/user/index/index",
"/pages/distribution/distribution"];
if(arr_tabbar.indexOf(url)!=-1){
if(url.indexOf("categoryList?type=1")!=-1) this.globalData.cat_type=1;
if(url.indexOf("categoryList?type=2")!=-1) this.globalData.cat_type=2;
wx.switchTab({url: url,}) //跳到tabbar页
}else{
if (getCurrentPages().length > 9) {
wx.redirectTo({url: url,}) //跳到非tabbar页
}else{
wx.navigateTo({url: url,}) //跳到tabbar页
}
}
//wx.navigateTo({ url: url, }) //跳到非tabbar页
},
//显示提示,word提示内容,type 0失败,提示 1成功
my_warnning(word,type,that,width){
var warn = that.selectComponent("#warn"); //组件的id
warn.open(word,type,width);
return 1;
},
//获取会员门店
get_user_store:function (func)
{
var th=this;
this.getConfig2(function (conf) {
//---空会员的情况---
if(!th.globalData.userInfo){
return func(null);
}
if(!th.globalData.pk_store){
var pick_id=0;
//先找一个会员是否有设置默认的地址
if(th.globalData.userInfo.def_pickup_id){
pick_id= th.globalData.userInfo.def_pickup_id
}
//查找会员的注册的地址
else if(th.globalData.userInfo.pickup_id){
//--购买门店是否默认登记门店--
if(conf.switch_list){
var t_swi=JSON.parse(conf.switch_list);
if(t_swi.is_regstores){
pick_id= th.globalData.userInfo.pickup_id
}
}
}
//---如果会员没有设置默认门店,同时也没有再注册的时候选择门店--
if(pick_id==0) return func(null);
//返回门店的数量
th.get_pk_num(function(num){
//获取用户注册时候的门店,这个门店不能关闭,同时这个门店的分类不能关闭
th.request.get("/api/weshop/pickup/get/"+os.stoid+"/"+pick_id,{
data:{},
success:function (res) {
th.globalData.pk_store=null;
if(res.data.code==0 && res.data.data && res.data.data.isstop==0){
//--门店的数量大于5个才要关心门店的分类有没有关闭--
if(res.data.data.category_id && num>5){
th.request.get( "/api/weshop/storagecategory/get/"+os.stoid+"/"+res.data.data.category_id, {
data: {},
success: function (ee) {
if(ee.data.code==0 && ee.data.data ){
if(ee.data.data.is_show==1){
th.globalData.pk_store = res.data.data;
func(th.globalData.pk_store);
}else{
func(null);
}
}else{
func(null);
}
}
})
}else{
th.globalData.pk_store = res.data.data;
func(th.globalData.pk_store);
}
}else{
func(null);
}
}
})
})
}else{
func(th.globalData.pk_store);
}
})
},
//-- 获取门店的数量 --
get_pk_num:function(func){
this.request.get("/api/weshop/pickup/page",{
data:{page:1,pageSize:1,isstop:0,store_id:os.stoid},
success:function (res) {
if(res.data.code==0){
func(res.data.data.total); //门店数量
}
}
});
},
//-------获取购物车数量----------
requestCardNum: function(th) {
if(!this.globalData.user_id) return false;
this.request.get("/api/weshop/cart/page", {
isShoeLoading:false,
data: {
store_id: this.globalData.setting.stoid,
user_id: this.globalData.user_id,
state:0,
is_gift:0
},
success: function(e) {
var num = 0;
if(e.data.data && e.data.data.pageData) {
for (var i = 0; i < e.data.data.pageData.length; i++) {
num += e.data.data.pageData[i].goods_num;
}
}
getApp().globalData.cartGoodsNum=num;
/*---
wx.setTabBarBadge({ //tabbar右上角添加文本
index: 2, ////tabbar下标
text: '' + num //显示的内容
});--*/
th.getTabBar().setData({cartGoodsNum:num});
th.data.up_dating = 0
}
});
},
//------定时等待某个值,有值才进行运算--------
waitfor:function(page,key,pop_value,func){
var n=0;
if(!page.data[key]){
page.data[key]=setInterval(function(){
console.log(page.data[key]);n++;
if(pop_value) {
clearInterval(page.data[key]);
func();
}
if(n>15) clearInterval(page.data[key]);
},1000);
}
},
//------定时等待某个值,有值才进行运算--------
waitfor2:function(page,key,pop_value_key,func){
var n=0;
if(!page.data[key]){
page.data[key]=setInterval(function(){
console.log(page.data[key]);n++;
if(page.data[pop_value_key] && Object.keys(page.data[pop_value_key]).length>0) {
clearInterval(page.data[key]);
func();
}
if(n>15){
clearInterval(page.data[key]);
func();
}
},1000);
}
},
//清空登录时候缓存的值
onHide:function () {
this.globalData.is_test=0;
this.globalData.guide_id=null; //导购清空
this.globalData.first_leader=null; //分享的会员清空
this.globalData.wuliu=null; //关闭要把物流清空
this.globalData.room_id=null; //关闭要把房间号关闭
this.globalData.room_goods_id=null; //关闭要把物流清空
this.globalData.config2=null; //清除config2的缓存
this.globalData.config=null; //清除config的缓存
},
clear_word:function (word) {
var str=word;
let reg = /([^\u0020-\u007E\u00A0-\u00BE\u2E80-\uA4CF\uF900-\uFAFF\uFE30-\uFE4F\uFF00-\uFFEF\u0080-\u009F\u2000-\u201f\u2026\u2022\u20ac\r\n])|(\s)/g ,
indexArr = reg.exec(str);
if(str.match(reg)) {
str = str.replace(reg, '');
}
return str;
},
getPageIndex:function(curPage){
var pagePath = curPage.route; //当前页面url
if (pagePath.indexOf('/') != 0) {
pagePath = '/' + pagePath;
}
var index=0;
if(this.globalData.custum_data){
var itemList = this.globalData.custum_data.data;
itemList = JSON.parse(itemList);
for(var i in itemList){
var item=itemList[i]
if(pagePath.indexOf(item.weappurl)!=-1){
index=i;break;
}
}
}else{
var itemList=this.def_list;
for(var i in itemList){
var item=itemList[i]
if(pagePath.indexOf(item.weappurl)!=-1){
index=i;break;
}
}
}
return index;
},
//---promise的使用get----
promiseGet:function(url,data){
if(url.indexOf("http")==-1) url=this.globalData.setting.url +url;
return new Promise((resolve, reject) => {
data.isShowLoading && wx.showLoading();
wx.request({
url,
method: 'GET',
header: {"content-type": "application/x-www-form-urlencoded" },
data:data.data,
success(res) {
data.isShowLoading && wx.hideLoading();
resolve(res);
},
fail(err) { data.isShowLoading && wx.hideLoading(); reject(err); }
})
})
},
// 判断是否登录
isLogin() {
return new Promise(function(resolve, reject) {
let user_info = getApp().globalData.userInfo;
if (user_info == null || user_info.mobile == undefined || user_info.mobile == "" || user_info.mobile == null) {
wx.navigateTo({
url: '/pages/togoin/togoin',
})
return false;
} else {
resolve(user_info);
};
});
},
});