chargeDetail.js
6.36 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
import { equityApi } from "../../../../api/api"
const baseUrl = 'https://img02.glsx.com.cn/weapp/resource/equity-h5-new/mini/'
Page({
data: {
curIndex:0,
checkedItem: 0,
isOpen:false,
selectedItem:null,
imageUrl:baseUrl,
listData:[]
},
bindInput(e){
this.setData({
rechageNum:e.detail.value
})
},
changeMumberType(e) {
let {selectedItem,listData} = this.data
const {index} = e.currentTarget.dataset
selectedItem = listData[index].denominationList[0]
this.setData({curIndex:index,selectedItem,checkedItem:0})
},
checkedMumberType(e){
const {item,index} = e.currentTarget.dataset
let richText = decodeURIComponent(item.buysNotes)
richText = richText.replace(/\<span/g, '<span class="rich_text"')
this.setData({checkedItem:index,selectedItem:item,richText})
},
toCheckMember() {
const SID = wx.$util.getSessionId()
if (!SID) {
return
}
equityApi.checkOpenMember().then(res => {
let flag = false
if(res.code==0&&res.data){
flag = true
}
this.setData({
isOpen: flag
})
wx.$eventbus.off('EQUITYGOODS')
})
},
getChargeDetail(query){
let para ={
brandName:query.brandName,
supplier:query.supplier
}
equityApi.chargeData(para).then(res => {
let {selectedItem,curIndex,checkedItem,richText} = this.data
if(!res){
wx.redirectTo({
url: "/packageEquity/pages/allEquity/allEquity?showToast=1",
});
return
}
if(res.length){
res.forEach(item=>{
item.denominationList.map(el=>{
if(el.noMemberPrice){
el.diffPraice = wx.$util.decimal(el.noMemberPrice-el.salesPrice,2)
}else{
el.diffPraice = 0
}
return el
})
})
}
if(!query.id){
selectedItem = res[0].denominationList[0]
}else{
for(let i = 0;i<res.length;i++){
if(res[i].productName==query.productName){
curIndex = i
}
for(let j = 0;j<res[i].denominationList.length;j++){
if(res[i].denominationList[j].id==query.id){
checkedItem = j
selectedItem = res[i].denominationList[j]
}
}
}
}
richText = decodeURIComponent(selectedItem.buysNotes)
richText = richText.replace(/\<span/g, '<span class="rich_text"')
this.setData({
listData:res,
query,
selectedItem,
checkedItem,
curIndex,
richText,
showLogin:false
})
})
},
toCoupons(){
wx.$router.go('packageMine.order.index', {
title:'我的订单'
})
},
toOpenPage(){
this.modalOnCancel()
let str = `?memberType=${1}` + `&index=${0}` + `&item=${null}`+`&page=business&getPackage=1`
wx.navigateTo({
url: '/packageEquity/pages/open/open'+str
})
// wx.navigateTo({
// url: '/packageEquity/pages/open/open?page=business'
// })
},
toMemberPage(){
this.toOpenPage()
},
toRecharge(){
const isLogin = this.checkLogin()
if(!isLogin){
return
}
if(!this.data.rechageNum){
wx.$util.showToast('请输入充值账号')
return
}
const { noMemberPrice, salesPrice } = this.data.selectedItem;
let diffPrice = 0
if (noMemberPrice) {
diffPrice = wx.$util.decimal(noMemberPrice - salesPrice, 2);
}
this.setData({
showModal:true,
diffPrice
})
},
modalOnCancel(){
this.setData({
showModal:false,
})
},
comfirmBuyItem(){
wx.$util.showLoading()
let para = {
supplier: this.data.query.supplier
}
equityApi.getOrderCode(para).then(res=>{
this.getPayParam(res)
this.modalOnCancel()
})
},
// 获取支付参数
getPayParam(orderCode) {
if (!orderCode) {
return
}
const { selectedItem,rechageNum } = this.data
let para = {
orderCode,
goodsId: selectedItem.id,
rechargeNumber:rechageNum,
goodsQuality: 1,
// payMannerId: 19,
paySource: 3
}
equityApi.payGoodsOrder(para).then(res => {
wx.hideLoading()
this.handlePay(res)
})
},
// 处理支付
handlePay(payData) {
const { timeStamp, nonceStr, packages, signType, paySign } = payData;
let self = this
wx.requestPayment({
timeStamp: timeStamp,
nonceStr: nonceStr,
package: packages,
signType: signType,
paySign: paySign,
success() {
//跳转商品详情
// wx.$util.showToast('支付成功')
let {query,selectedItem,rechageNum} = self.data
let obj = {
...query,
...selectedItem,
rechageNum,
}
const temp = JSON.stringify(obj)
wx.navigateTo({
url:'/packageEquity/pages/chargeWait/chargeWait?query='+temp
})
},
fail() {
}
})
},
// 设置标题名称
setNaviTitle(title) {
wx.setNavigationBarTitle({
title
})
},
onLoad(options){
const query =options?JSON.parse(decodeURIComponent(options.param)):this.data.query
this.getChargeDetail(query)
this.setNaviTitle(query.brandName)
wx.$eventbus.on('EQUITYGOODS',(data)=>{
this.toCheckMember()
})
},
onShow(){
this.toCheckMember()
},
// 检测是否已经登录
checkLogin(){
const sessionId = wx.$util.getSessionId()
let flag = true
if(!sessionId){
flag = false
this.setData({
showLogin:true
})
}
return flag
},
loginCallBack(data){
if(data){
this.toCheckMember()
}
}
})