myOrder.js
1.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
// pages/tab/mine/components/myOrder/myOrder.js
import { ORDER_STATUS, OrderStatusTypes } from "~/constants/mine.js";
Component({
/**
* 组件的初始数据
*/
data: {
orderList: Object.freeze(
Object.values(ORDER_STATUS).filter(
(item) => item.type == OrderStatusTypes.MY_ORDER
)
),
},
/**
* 组件生命周期
*/
lifetimes: {
attached() {
// 获取订单状态对应的图片
this.getOrderNumberList();
},
},
pageLifetimes: {
show: function() {
// 页面被展示时执行
this.getOrderNumberList();
}
},
/**
* 组件的方法列表
*/
methods: {
goOrder(e) {
// 直接使用 ORDER_LIST 中的索引作为 tabIndex
const item = e.currentTarget.dataset.item;
wx.p.router.go("/packageMine/pages/order/index/index", {
tab: item,
});
},
getOrderNumberList() {
const loginStatus = !wx.p.isLogin;
if (loginStatus) return;
const userInfo = wx.p.storage.get("userInfo") || {};
let { merchantId, channelSource,phone } = userInfo;
const params = {
merchantId,
pageSize: 1,
currentPage: 1,
scoreSource: channelSource,
phone
};
const orderList = this.data.orderList;
orderList.forEach((item) => {
const p = { ...params, requestType: item.requestType };
wx.p.api.mineApi[item.requestMethod](p).then((data) => {
if(data.total){
item.___count = data.total;
this.setData({
orderList,
});
}
});
});
},
},
});