cart.js
4.7 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
var t = require("../../utils/network.js");
Page({
data: {
num: 1,
selectnum: [],
ouid: "",
carlist: [],
hasList: !1,
totalPrice: 0,
selected: !1,
totalnum: 0,
ids: ""
},
bindMinus: function(a) {
var e = this, i = a.currentTarget.dataset.index, s = this.data.carlist, c = parseInt(s[i].count), n = s[i].id;
s[i].count > 1 && (c -= 1, t.POST({
url: "Pay/update_car",
header: "application/x-www-form-urlencoded",
params: {
count: c,
id: n
},
success: function(t) {
e.setData({
carlist: s
}), e.getcartlist();
}
})), this.setData({
carlist: s
});
},
bindPlus: function(a) {
var e = this, i = a.currentTarget.dataset.index, s = this.data.carlist, c = parseInt(s[i].count), n = s[i].id;
c += 1, t.POST({
url: "Pay/update_car",
header: "application/x-www-form-urlencoded",
params: {
count: c,
id: n
},
success: function(t) {
e.setData({
carlist: s
}), e.getcartlist(), e.getTotalPrice();
}
});
},
bindManual: function(t) {
var a = t.detail.value;
this.setData({
num: a
});
},
onLoad: function(t) {
this.getTotalPrice();
},
getcartlist: function(a) {
var e = this;
t.GET({
url: "Pay/my_cars",
header: "application/x-www-form-urlencoded",
params: {
ouid: e.data.ouid
},
success: function(t) {
if (t.data.cars) {
var a = [];
a = t.data.cars;
for (var i = 0; i < a.length; i++) a[i].selected = !1;
}
e.setData({
carlist: a
});
}
});
},
selectList: function(t) {
var a = [], e = [], i = t.currentTarget.dataset.index, s = this.data.carlist, c = s[i].selected;
s[i].selected = !c;
for (var n = 0; n < this.data.carlist.length; n++) 1 == this.data.carlist[n].selected && (a.push(this.data.carlist[n].selected),
e.push(this.data.carlist[n].id));
this.setData({
carlist: s,
selected: c,
totalnum: a.length,
ids: e.join(",")
}), this.getTotalPrice();
},
getTotalPrice: function() {
for (var t = this.data.carlist, a = 0, e = 0; e < t.length; e++) t[e].selected && (a += t[e].count * t[e].pprice);
this.setData({
carlist: t,
totalPrice: a.toFixed(2)
});
},
deleteList: function(a) {
var e = this, i = a.currentTarget.dataset.index, s = this.data.carlist;
wx.showModal({
title: "确认删除商品吗",
content: "确定要删除该商品吗?",
success: function(a) {
a.confirm ? t.POST({
url: "Pay/delete_car",
header: "application/x-www-form-urlencoded",
params: {
ouid: e.data.ouid,
id: s[i].id
},
success: function(t) {
s.splice(i, 1), e.data.totalnum, e.setData({
carlist: s,
totalnum: 0,
totalPrice: 0
}), e.getcartlist();
}
}) : a.cancel && console.log("用户点击取消"), e.getTotalPrice();
}
}), s.length ? this.getTotalPrice() : this.setData({
carlist: s
});
},
topay: function() {
0 == this.data.totalnum ? wx.showToast({
title: "你还未选择商品",
icon: "none"
}) : wx.navigateTo({
url: "../my/pay/pay?ids=" + this.data.ids
});
},
onReady: function() {},
onShow: function() {
var t = this;
this.setData({
carlist: [],
totalnum: 0,
totalPrice: 0
}), wx.getStorage({
key: "ouid",
success: function(a) {
wx.showLoading({
title: "加载中..."
}), t.setData({
ouid: a.data
}), t.getcartlist(), wx.hideLoading();
}
});
},
onHide: function() {},
onUnload: function() {},
onPullDownRefresh: function() {},
onReachBottom: function() {},
onShareAppMessage: function() {}
});