coupon.js
2.64 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
// coupon.js
const xnService = require('../../service/service.js');
const util = require('../../utils/util.js');
var app = getApp()
Page({
/**
* 页面的初始数据
*/
data: {
dataList: [],
isEnd: false,
isLoading: false,
tip: ""
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.getList();
},
getList() {
let _this = this;
var memberId = app.getMemberId();
var vm = {
memberIdList: [memberId] ,
pageSize: 0,
status:'unuse',
isUsefulEndOut:false
}
console.log(vm);
_this.setData({
isLoading: true,
tip: "查询中"
})
xnService.promotionCouponEntityFind(vm, function (data) {
_this.setData({
isLoading: false,
tip: ''
})
if (data.firstErrorMessage) {
_this.setData({
isEnd: true,
tip: data.firstErrorMessage
})
} else {
if (data.result && data.result.length > 0) {
var dataList = data.result;
// 优惠券
let ids = [];
for (let i = 0; i < dataList.length; i++) {
ids.push(dataList[i].couponDefinitionId);
dataList[i].usefulStart = util.formatDay(dataList[i].usefulStart);
dataList[i].usefulEnd = util.formatDay(dataList[i].usefulEnd);
// dataList[i].debit = dataList[i].debit.toFixed(2);
// dataList[i].credit = dataList[i].credit.toFixed(2);
// dataList[i].balance = dataList[i].balance.toFixed(2);
}
xnService.promotionCouponDefinitionFind({ ids: ids, pageSize: 0 }, function (coupon) {
let couponList = coupon.result;
for (let j = 0; j < dataList.length; j++) {
for (let k = 0; k < couponList.length; k++) {
if (dataList[j].couponDefinitionId == couponList[k].id) {
dataList[j].couponDefinition = couponList[k];
dataList[j].couponDefinition.profitQuantityFixed = dataList[j].couponDefinition.profitQuantity.toFixed(2);
break;
}
}
}
_this.setData({
dataList: _this.data.dataList.concat(dataList)
})
});
} else {
_this.setData({
isEnd: true,
tip: "暂无优惠券"
})
}
}
});
},
// 下拉刷新
onPullDownRefresh: function () {
let _this = this;
_this.setData({
dataList: [],
isEnd: false,
isLoading: false,
tip: ""
})
this.getList();
wx.stopPullDownRefresh()
}
})