myGiftBox.vue
25.2 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
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
<template>
<div class="my_gift_box">
<!--tab切换-->
<div
class="top_box"
:style="'padding-top: ' + $parent.top.value + 'px'"
>
<img @click="$parent.back" src="static/img/icon_back.png" />
<div class="tabs">
<van-tabs @change="onTap" v-model="active">
<van-tab title="收礼"></van-tab>
<van-tab title="送礼"></van-tab>
</van-tabs>
</div>
<div class="desc" @click="giftRules">规则说明</div>
</div>
<!-- btn按钮筛选 -->
<div class="tab_btn_list">
<van-tabs @change="onStatusFiltering" v-model="btnActive" swipeable>
<van-tab v-for="(item,index) in (active==0?receivingGiftsTab:giveGifTab)" :title="item.name" :key="'tab'+index">
</van-tab>
</van-tabs>
</div>
<!--内容-->
<div class="item_box">
<div
infinite-scroll-immediate-check="true"
v-infinite-scroll="onInfiniteScroll"
infinite-scroll-disabled="loading"
:infinite-scroll-distance="50"
infinite-scroll-throttle-delay="600"
>
<!-- 收礼列表 -->
<receiving-gifts-item
v-show="active != 1 && active == 0"
@onUserInfo="onUserInfo"
@giftInReturn="giftInReturn"
@onReceivingGifts="onReceivingGifts"
:receivingGiftsInfo="receivingGiftsInfo"
:isData=this.receivingGifts.isData
></receiving-gifts-item>
<!-- 送礼列表 -->
<giftGivingItem
@onGiftGiving="onGiftGiving"
@onCancelPayment="onCancelPayment"
@jumpToPay="jumpToPay"
v-show="active != 0 && active == 1"
:giftGivingItem="giftGivingItem"
:isData= this.giftGiving.isData
>
</giftGivingItem>
<!-- 没有更多了 -->
<div v-if="active==0" class="tip_text">{{this.receivingGifts.tipText }}</div>
<div v-else class="tip_text">{{this.giftGiving.tipText }}</div>
</div>
</div>
<!-- 弹出框 -->
<van-popup position="bottom" v-model="actionSheetShow">
<van-picker
show-toolbar
:columns="orderOperation.causes"
:default-index="2"
@cancel="onCancel"
@confirm="confirm"
/>
</van-popup>
</div>
</template>
<script>
// 引入组件
import { Toast, Indicator } from "mint-ui";
import receivingGiftsItem from "@/components/receivingGiftsItem/receivingGiftsItem"; // 收礼列表
import giftGivingItem from "@/components/giftGivingItem/giftGivingItem"; // 送礼列表
export default {
name: "myGiftBox",
data() {
return {
receivingGiftsTab:[ // 收礼tab筛选
{name:'全部',status:0},
{name:'未填写地址',status:1},
{name:'待发货',status:2},
{name:'已完成',status:3},
{name:'已发货',status:4}
],
receivingGiftStatue:null, // 收礼订单状态筛选
giveGifTab:[ // 送礼tab筛选
{name:'全部',status:0},
{name:'可分享',status:1},
{name:'未填写地址',status:2},
{name:'待发货',status:3},
{name:'未领退款',status:4}
],
giveGifStatue:null, // 送礼订单状态筛选
btnActive:0, // 按钮tab状态
active: 0,
receivingGiftsInfo: null, // 收礼列表页数据
loading: false, // 判断是否加载
receivingGifts: {
// 收礼
loading: false, // 加载
pages: 1, // 分页
tipText:null, // 数据加载完提示
isData:null // 是否有赠礼 1 有 0 无
},
giftGivingItem: null, // 送礼列表页数据
giftsRuleUrl: null, // 礼物规则URL
giftGiving: {
// 送礼
loading: false, // 加载
pages: 1, // 分页
tipText:null, // 数据加载完提示
isData:null // 是否有赠礼 1 有 0 无
},
// tipText: null, // 是否已加载完
actionSheetShow: false,
orderOperation: {
// 存取取消订单的信息
causes: [], // 取消原因
item: null //订单id
}
};
},
components: {
receivingGiftsItem,
giftGivingItem
},
created() {
// 收礼订单列表
this.getorderGiftList();
// 送礼订单列表
this.getorderGiveGiftList();
// 赠礼规则
this.orderGiftContent();
// 取消订单原因获取
this.cancelPayment();
// 是否禁用滑动webview(none隐藏,block显示)
this.CNDSWebScrollEnabled();
},
mounted() {
// 配合原生回调
if (this.isCNLive.value) {
// 暴露方法,由APP调用,接受参数
if (this.isiPhone.value) {
window.appPaymentCallback = item => {
this.appPaymentCallback();
};
} else if (this.isAndroid.value) {
window.payFinish = item => {
this.payFinish();
};
}
}
},
methods: {
/**
* tab切换
*/
onTap(active) {
this.active = active;
// 初始化加载状态
this.loading = false;
this.btnActive = 0; // 切换送礼和收礼时;初始化tab默认都为全部
if (active == 0) {
// 收礼订单列表
this.getorderGiftList();
// 调用im是否显示隐藏1显示im聊天弹窗0不显示
this.setGiftBottomVisibleBySwitchTab(0);
} else {
// 调用im是否显示隐藏1显示im聊天弹窗0不显示
this.setGiftBottomVisibleBySwitchTab(1);
// 送礼订单列表
this.getorderGiveGiftList();
}
},
// tab订单状态筛选
onStatusFiltering(name, title){
if(this.active==0){
// 收礼订单列表
this.receivingGiftStatue = name;
this.receivingGifts.tipText = null;
this.receivingGifts.pages = 1
this.getorderGiftList(1);
}else{
// 送礼订单列表
this.giveGifStatue = name;
this.giftGiving.tipText = null;
this.giftGiving.pages = 1;
this.getorderGiveGiftList();
}
},
/**
* 下啦滑动加载更多
*/
onInfiniteScroll() {
if (this.active === 0) {
// 收礼订单列表
this.loading = this.receivingGifts.loading;
this.receivingGifts.pages++;
this.getorderGiftList();
} else {
// 送礼订单列表
this.loading = this.giftGiving.loading;
this.giftGiving.pages++;
this.getorderGiveGiftList();
}
// if (!this.loading) {
// this.tipText = "已经全部加载完毕";
// }
},
/**
* 显示和隐藏聊天
*/
setGiftBottomVisibleBySwitchTab(itme) {
// App内
if (this.isCNLive.value) {
// 调用App,返回按键
if (
window.webkit &&
window.webkit.messageHandlers &&
window.webkit.messageHandlers
.setGiftBottomVisibleBySwitchTab
) {
// App内,iOS销毁WebView
window.webkit.messageHandlers.setGiftBottomVisibleBySwitchTab.postMessage(
{ body: { visible: itme } }
);
} else if (
window.obj &&
window.obj.setGiftBottomVisibleBySwitchTab
) {
// App内,Android销毁WebView
window.obj.setGiftBottomVisibleBySwitchTab(itme);
}
}
},
/**
* 是否禁用滑动webview(none隐藏,block显示)
*/
CNDSWebScrollEnabled(itme) {
// App内
if (this.isCNLive.value) {
// 调用App,返回按键
if (
window.webkit &&
window.webkit.messageHandlers &&
window.webkit.messageHandlers.CNDSWebScrollEnabled
) {
// App内,iOS销毁WebView
window.webkit.messageHandlers.CNDSWebScrollEnabled.postMessage(
{ body: { display: "none" } }
);
} else if (
window.obj &&
window.obj.setGiftBottomVisibleBySwitchTab
) {
// App内,Android销毁WebView
window.obj.CNDSWebScrollEnabled("none");
}
}
},
/**
* 获取收礼礼物列表
*/
getorderGiftList(initPage) {
console.log(this.receivingGifts.pages)
this.receivingGifts.loading = true;
// 加载中提示
Indicator.open("加载中...");
// 获取收礼礼物列表接口
this.http(
"/Api/" + this.getApiVersion().index + "/orderGiftList",
{
uid: this.$route.query.uid, // 用户id
page: this.receivingGifts.pages, // 分页 默认为1 一页20条
type: 1, // 1 收礼列表 2 送礼列表(送礼已废弃)
status:this.receivingGiftStatue// 0或者不传 全部 1 未填地址 2 未发货 3 已完成 4 已发货
},
this.getorderGiftListCallback,
{
method: "post",
initPage
}
);
},
/**
* 获取收礼礼物列表回调
* @param {object} res [服务器返回数据]
* @param {object} ext [扩展参数]
*/
getorderGiftListCallback(res, ext) {
// 加载完成
Indicator.close();
// 返回处理
if (res.code == 200) {
// 解构数据
let { data: datas } = res;
// is_data是否有赠礼 1 有 0 无
this.receivingGifts.isData = datas.is_data
// 页脚等于1的时候会出现数据获取为空
// if(this.receivingGifts.pages==1){
// this.receivingGiftsInfo = datas.list;
// }
// 设置shopFnsDynamic达人动态数据
if (datas.list && datas.list.length) {
// 隐藏加载圈
this.receivingGifts.loading = false;
if (this.receivingGifts.pages > 1) {
this.$set(this, "receivingGiftsInfo", [
...this.receivingGiftsInfo,
...datas.list
]);
} else {
this.$set(this, "receivingGiftsInfo", datas.list);
}
// 判断是否显示没有更多
if(datas.list.length<20){
this.receivingGifts.tipText = "已经全部加载完毕";
}else{
this.receivingGifts.tipText = "";
}
}else{
// this.receivingGifts.pages = 1; // 数据为空时页脚从1开始计算
if(this.receivingGifts.pages==1){
//页脚等于1的时候会出现数据获取为空
this.receivingGiftsInfo = datas.list;
}
console.log(this.receivingGifts.tipText);
}
/* 获取达人动态数据 结束 */
} else if (res.code == 400) {
// 获取达人动态失败
Toast(res.message);
} else {
// 获取优选库精选活动失败
Toast("获取收礼订单列表失败");
}
},
// 跳转到用户详情页
onUserInfo(item) {
// 判断并调用通用跳转
if (typeof this.$parent.gotoDetail === "function") {
// 临时,设置跳转商品详情参数
Object.assign(item, {
type: "43",
to: JSON.stringify({
uid: item.user.uid,
username: item.user.username,
img: item.user.img
}),
shop_type: ""
});
this.$parent.gotoDetail(item);
}
},
// 跳转回赠礼物
giftInReturn(item) {
// 判断并调用通用跳转
if (typeof this.$parent.gotoDetail === "function") {
// 临时,设置跳转商品详情参数
Object.assign(item, {
type: "14",
to: "",
shop_type: ""
});
this.$parent.gotoDetail(item);
}
},
// 收礼商品跳转到详情页
onReceivingGifts(item) {
// 判断并调用通用跳转
if (typeof this.$parent.gotoDetail === "function") {
// 临时,设置跳转商品详情参数
Object.assign(item, {
type: "26",
to: item.id,
shop_type: ""
});
this.$parent.gotoDetail(item);
}
},
// 送礼商品跳转到详情页
onGiftGiving(item) {
// 判断并调用通用跳转
if (typeof this.$parent.gotoDetail === "function") {
// 临时,设置跳转商品详情参数
Object.assign(item, {
type: "36",
to: item.id,
shop_type: ""
});
this.$parent.gotoDetail(item);
}
},
/**
* 获取送礼礼物列表
*/
getorderGiveGiftList() {
this.giftGiving.loading = true;
// 加载中提示
Indicator.open("加载中...");
// 获取送礼礼物列表接口
this.http(
"/Api/" + this.getApiVersion().index + "/orderGiveGiftList",
{
uid: this.$route.query.uid, // 用户id
page: this.giftGiving.pages, // 分页 默认为1 一页20条
type: 1, // 1 收礼列表 2 送礼列表(送礼已废弃)
status: this.giveGifStatue // 0或者不传 全部 1 未填地址 2 未发货 3 已完成 4 已发货
},
this.getorderGiveGiftListCallback,
{
method: "post",
}
);
},
/**
* 获取送礼礼物列表回调
* @param {object} res [服务器返回数据]
* @param {object} ext [扩展参数]
*/
getorderGiveGiftListCallback(res, ext) {
// 加载完成
Indicator.close();
// 返回处理
if (res.code == 200) {
// 解构数据
let { data: datas } = res;
// is_data是否有赠礼 1 有 0 无
this.giftGiving.isData = datas.is_data
// 页脚等于1的时候会出现数据获取为空
// if(this.receivingGifts.pages==1){
// this.giftGivingItem = datas.list;
// }
// 设置giftGivingItem数据
if (datas.list && datas.list.length) {
// 隐藏加载圈
this.giftGiving.loading = false;
if (this.giftGiving.pages > 1) {
this.$set(this, "giftGivingItem", [
...this.giftGivingItem,
...datas.list
]);
} else {
this.$set(this, "giftGivingItem", datas.list);
}
// 判断是否显示没有更多
if(datas.list.length<20){
this.giftGiving.tipText = "已经全部加载完毕";
}else{
this.giftGiving.tipText = "";
}
}else{
// this.giftGiving.pages = 1;// 数据为空时设置分页数为1
if(this.giftGiving.pages==1){
//页脚等于1的时候会出现数据获取为空
this.giftGivingItem = datas.list;
}
// this.tipText = "已经全部加载完毕"; //提示全部加载为空
}
/* 获取送礼订单列表 结束 */
} else if (res.code == 400) {
// 获取送礼订单列表失败
Toast(res.message);
} else {
// 获取送礼订单列表失败
Toast("获取送礼订单列表失败");
}
},
/**
* 赠礼规则url
*/
orderGiftContent() {
// 加载中提示
Indicator.open("加载中...");
// 赠礼规则url列表接口
this.http(
"/Api/" + this.getApiVersion().index + "/orderGiftContent",
{},
this.orderGiftContentCallback,
{
method: "post"
}
);
},
/**
* 赠礼规则url列表接口回调
* @param {object} res [服务器返回数据]
* @param {object} ext [扩展参数]
*/
orderGiftContentCallback(res, ext) {
// 加载完成
Indicator.close();
// 返回处理
if (res.code == 200) {
// 解构数据
let { data: datas } = res;
this.giftsRuleUrl = datas.content;
}
},
// 送礼规则说明
giftRules() {
// 判断并调用通用跳转
if (typeof this.$parent.gotoDetail === "function") {
// 临时,设置跳转商品详情参数
let item = {
type: "44",
to: this.giftsRuleUrl,
shop_type: ""
};
console.log(item);
this.$parent.gotoDetail(item);
}
},
// 取消支付
cancelPayment() {
// 加载中提示
Indicator.open("加载中...");
// 获取送礼礼物列表接口
this.http(
"/Api/" + this.getApiVersion().index + "/cancel_order_group",
{},
this.cancelPaymentCallback,
{
method: "get"
}
);
},
/**
* 取消订单回调获取取消原因数据
* @param {object} res [服务器返回数据]
* @param {object} ext [扩展参数]
*/
cancelPaymentCallback(res, ext) {
// 加载完成
Indicator.close();
// 返回处理
if (res.code == 200) {
// 解构数据
let { data: datas } = res;
// 获取到的数组存到this.causes中去
if (datas.group && datas.group.length > 0) {
this.orderOperation.causes = datas.group;
}
}
},
// 取消支付子组件事件传递
onCancelPayment(item) {
// 隐藏底部聊天弹框
this.setGiftBottomVisibleBySwitchTab(0);
this.actionSheetShow = true; // 显示底部取消订单原因弹框
this.orderOperation.item = item; // 获取当前操作订单ID
},
// 确认,取消订单
confirm(picker, value, index) {
this.actionSheetShow = false;
// Toast(`当前值:${value}, 当前索引:${index}`);
// 调用取消订单原因填写
this.cancelorder(this.orderOperation.item, value);
},
// 取消,取消订单
onCancel() {
this.actionSheetShow = false;
},
// 取消支付填写原因
cancelorder(item, content) {
// 加载中提示
Indicator.open("加载中...");
// 获取送礼礼物列表接口
this.http(
"/Api/" + this.getApiVersion().index + "/cancel_order",
{
id: item.id, // 订单ID
content: content // 取消订单ID
},
this.cancelorderCallback,
{
method: "post",
item
}
);
},
/**
* 取消订单回调获取取消原因数据
* @param {object} res [服务器返回数据]
* @param {object} ext [扩展参数]
*/
cancelorderCallback(res, ext) {
// 加载完成
Indicator.close();
// 返回处理
if (res.code == 200) {
// 取消订单
if (ext.item.status == "0") {
// status=3(订单已经关闭)
this.$set(ext.item, "status", "3");
}
// 解构数据
let { data: datas } = res;
// 获取到的数组存到this.causes中去
if (datas.group && datas.group.length > 0) {
this.causes = datas.group;
}
}
},
// 跳转原声支付
jumpToPay(item) {
// 隐藏底部聊天弹框
this.setGiftBottomVisibleBySwitchTab(0);
// 获取当前操作的支付订单
this.orderOperation.item = item;
// App内
if (this.isCNLive.value) {
// 调用App,返回按键
if (
window.webkit &&
window.webkit.messageHandlers &&
window.webkit.messageHandlers.openAppPayment
) {
// App内,iOS销毁WebView
window.webkit.messageHandlers.openAppPayment.postMessage({
body: { orderNumber: item.orderid }
});
} else if (window.obj && window.obj.jumpToPay) {
// App内,Android销毁WebView
window.obj.jumpToPay(item.orderid);
}
}
},
// ios支付成功回调
appPaymentCallback(item) {
// 取消订单
if (this.orderOperation.item.status == "0") {
// status=1(已支付可分享状态)
this.$set(this.orderOperation.item, "status", "1");
}
},
// 安卓支付成功回调
payFinish() {
// 检测是否已支付
this.cancelorder(this.orderOperation.item);
},
// 安卓调用支付后检测是否已支付
cancelorder(item) {
// 加载中提示
Indicator.open("加载中...");
// 获取送礼礼物列表接口
this.http(
"/Api/" + this.getApiVersion().index + "/isOrderPay",
{
orderId: item.orderid // 订单编号
},
this.cancelorderCallback,
{
method: "post",
item
}
);
},
/**
* 取消订单回调获取取消原因数据
* @param {object} res [服务器返回数据]
* @param {object} ext [扩展参数]
*/
cancelorderCallback(res, ext) {
// 加载完成
Indicator.close();
// 返回处理
if (res.code == 200) {
// 订单支付成功
if (ext.item.status == "0") {
// status=3(订单已经关闭)
this.$set(ext.item, "status", "1");
}
}
}
}
};
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style rel="stylesheet/less" lang="less">
@import "myGiftBox";
</style>