Blame view

pages/moneyRecharge/moneyRecharge.vue 7.44 KB
4b045f7c   刘淇   江阴初始化项目
1
  <template>
3b7af3a2   chenbiao   add 我的钱包 接口联调
2
3
4
5
6
7
8
  	<view>
  
  		<view class="rechargeTop">
  			<view class="toDetail uni-list-cell-pd uni-right" @click="detailCell">明细 ></view>
  			<view class="rechargeNum uni-center">¥{{acctBalance | toFixed2 }}</view>
  		</view>
  
00a21ab7   chenbiao   add 余额明细 接口联调
9
  		<uni-section title="充值金额(元)" type="line" padding>
3b7af3a2   chenbiao   add 我的钱包 接口联调
10
11
12
  			<uni-grid :column="3" :highlight="true" :showBorder="false" :square="false" @change="change">
  				<uni-grid-item v-for="(item, index) in ListData" :index="index" :key="index">
  					<view class="grid-item-box" style="background-color: #fff;">
b398dc4a   chenbiao   add 我的钱包 接口联调
13
14
15
  						<view class="text" :class="currentIndex==index?'itemActive':''">
  							{{item.rechargeCode | ortherToFixed}}
  						</view>
3b7af3a2   chenbiao   add 我的钱包 接口联调
16
17
18
  					</view>
  				</uni-grid-item>
  			</uni-grid>
00a21ab7   chenbiao   add 余额明细 接口联调
19
20
21
  			<view class="uni-list-cell-pd" v-show="isShowInput">
  				<input class="payInut" type="number" v-model="rechargeNum" @input="checkNum" :maxlength="maxlength"
  					placeholder=" 请输入金额">
b398dc4a   chenbiao   add 我的钱包 接口联调
22
  			</view>
3b7af3a2   chenbiao   add 我的钱包 接口联调
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
  		</uni-section>
  
  		<view class="uni-list-cell-pd">
  			温馨提示:暂不支持退款,请谨慎选择充值金额!
  		</view>
  		<view class="border-bg"></view>
  
  		<view class="order-title">
  			支付方法
  		</view>
  		<view class="order-line"></view>
  
  		<view class="orderwaysview">
  			<image src="../../static/orderInfo/orderinfo-wechat.png" class="orderways"></image>
  			<view class="order-info" style="margin-left: 8px;">
  				微信支付
  			</view>
  			<image src="../../static/orderInfo/orderinfo-sel.png" class="orderwaysSel"></image>
  		</view>
  
  		<button @click="payClick" class="button-sp-area" type="primary" plain="true">确认充值</button>
  
  	</view>
4b045f7c   刘淇   江阴初始化项目
46
47
48
  </template>
  
  <script>
3b7af3a2   chenbiao   add 我的钱包 接口联调
49
50
51
52
  	export default {
  		data() {
  			return {
  				acctBalance: '0.00',
e7895736   chenbiao   add 支付 接口联调
53
  				wxopenId: '',
b398dc4a   chenbiao   add 我的钱包 接口联调
54
  				ListData: [],
3b7af3a2   chenbiao   add 我的钱包 接口联调
55
  				currentIndex: 0,
49201aa2   chenbiao   add 我的钱包 微信支付 接口联调
56
  				rechargeFee: 0,
62cee34d   chenbiao   add
57
  				isShowInput: false,
b398dc4a   chenbiao   add 我的钱包 接口联调
58
  				rechargeNum: '',
00a21ab7   chenbiao   add 余额明细 接口联调
59
  				maxlength: 6 //默认一个长度 
3b7af3a2   chenbiao   add 我的钱包 接口联调
60
61
62
  			}
  		},
  		onLoad() {
e7895736   chenbiao   add 支付 接口联调
63
64
65
66
67
  			uni.setStorageSync("wxCode", '')
  			this.getCode();
  			this.recharge();
  			this.rechargeList();
  			
3b7af3a2   chenbiao   add 我的钱包 接口联调
68
69
70
  
  		},
  		mounted() {
b398dc4a   chenbiao   add 我的钱包 接口联调
71
  
93c5ecb3   chenbiao   add 添加filter.js 设...
72
  		},
e7895736   chenbiao   add 支付 接口联调
73
74
75
  		onShow() {
  		 
  		},
3b7af3a2   chenbiao   add 我的钱包 接口联调
76
  		methods: {
e7895736   chenbiao   add 支付 接口联调
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
  			getCode() {
  				uni.login({
  					provider: 'weixin',
  					success: function(loginRes) {
  						console.log('获取微信code-loginRes.code: ' + loginRes.code);
  						uni.setStorageSync("wxCode", loginRes.code)
  
  					}
  				});
  			},
  			getOpenID() {
  				let that = this;
  				let code = uni.getStorageSync("wxCode");
  				console.log(code)
  				let data = {
  					appId: that.$common.hs_wxPay_appId,
  					// appId:"wxadb8caee05ab2981",
  					code: code,
  
  				};
  				that.$myRequest({
  					url: that.$common.getOpenIdByCode,
  					method: 'POST',
  					data: data
  				}).then(res => {
  
  
  					let data = res.data;
  					that.wxopenId = data.openid;
  					console.log(data.openid)
  					that.wxPayOrder()
  				})
  			},
3b7af3a2   chenbiao   add 我的钱包 接口联调
110
111
112
113
114
115
116
117
118
119
120
121
122
123
  			recharge() {
  				let that = this;
  				that.$myRequest({
  					url: that.$common.walletAccount,
  					method: 'POST',
  					data: that.$common.requestSign()
  				}).then(res => {
  
  					console.log(res)
  					let data = res.data;
  					that.acctBalance = data.acctBalance;
  
  				})
  			},
b398dc4a   chenbiao   add 我的钱包 接口联调
124
125
126
127
128
129
130
  			rechargeList() {
  				let that = this;
  				that.$myRequest({
  					url: that.$common.rechargeList,
  					method: 'POST',
  					data: that.$common.requestSign()
  				}).then(res => {
3b7af3a2   chenbiao   add 我的钱包 接口联调
131
  
b398dc4a   chenbiao   add 我的钱包 接口联调
132
133
134
  					console.log(res)
  					let data = res.data;
  					that.ListData = data;
49201aa2   chenbiao   add 我的钱包 微信支付 接口联调
135
  					that.rechargeFee = that.ListData[0].rechargeCode
3b7af3a2   chenbiao   add 我的钱包 接口联调
136
  
b398dc4a   chenbiao   add 我的钱包 接口联调
137
138
139
140
  				})
  			},
  			change(e) {
  				let that = this;
3b7af3a2   chenbiao   add 我的钱包 接口联调
141
142
  				let {
  					index
b398dc4a   chenbiao   add 我的钱包 接口联调
143
144
145
146
147
148
149
  				} = e.detail;
  				that.currentIndex = index;
  
  				if (that.ListData[index].rechargeCode == -1) {
  					console.log('1')
  					that.isShowInput = true;
  					that.rechargeNum = ''
00a21ab7   chenbiao   add 余额明细 接口联调
150
151
  				} else {
  					that.isShowInput = false;
49201aa2   chenbiao   add 我的钱包 微信支付 接口联调
152
  					that.rechargeFee = that.ListData[index].rechargeCode;
b398dc4a   chenbiao   add 我的钱包 接口联调
153
  				}
00a21ab7   chenbiao   add 余额明细 接口联调
154
  
3b7af3a2   chenbiao   add 我的钱包 接口联调
155
  			},
00a21ab7   chenbiao   add 余额明细 接口联调
156
157
158
159
160
161
162
163
164
165
166
  			checkNum(e) {
  				let value = e.detail.value;
  				let dot = value.indexOf('.'); //包含小数点
  				let reg = /^[0-9]+$/; //正整数
  				if (dot > -1) {
  					this.maxlength = dot + 3; //长度是小数点后两位
  					if (value.length > dot + 3) {}
  				}
  				if (reg.test(value)) { //如果是正整数不包含小数点
  					this.maxlength = 6;
  				}
b398dc4a   chenbiao   add 我的钱包 接口联调
167
  
00a21ab7   chenbiao   add 余额明细 接口联调
168
169
170
171
172
  			},
  
  			detailCell() {
  				uni.navigateTo({
  					url: '../rechargeDetail/rechargeDetail'
49201aa2   chenbiao   add 我的钱包 微信支付 接口联调
173
  
00a21ab7   chenbiao   add 余额明细 接口联调
174
  				});
49201aa2   chenbiao   add 我的钱包 微信支付 接口联调
175
176
  			},
  			payClick() {
e7895736   chenbiao   add 支付 接口联调
177
178
179
180
181
182
183
  				
  				let that = this;
  				that.getOpenID()
  				
  				
  			},
  			wxPayOrder(){
49201aa2   chenbiao   add 我的钱包 微信支付 接口联调
184
185
186
  				let that = this;
  				let payMoney;
  				if (that.isShowInput) {
b0da1bac   刘淇   钱包充值 其他金额时候乘以100
187
  					payMoney = that.rechargeNum*100;
49201aa2   chenbiao   add 我的钱包 微信支付 接口联调
188
189
190
  				} else {
  					payMoney = that.rechargeFee;
  				}
e7895736   chenbiao   add 支付 接口联调
191
  				console.log(that.wxopenId)
49201aa2   chenbiao   add 我的钱包 微信支付 接口联调
192
  				let data = {
e7895736   chenbiao   add 支付 接口联调
193
  					openId: that.wxopenId,
49201aa2   chenbiao   add 我的钱包 微信支付 接口联调
194
195
196
  					rechargeType: '2',
  					acctType: '1',
  					paySrcType: '204',
e7895736   chenbiao   add 支付 接口联调
197
  					payType: '12',
49201aa2   chenbiao   add 我的钱包 微信支付 接口联调
198
199
200
201
202
203
204
205
206
  					realPayMoney: payMoney,
  					rechargeFee: payMoney,
  				};
  				console.log(data)
  				that.$myRequest({
  					url: that.$common.publicUnifiedOrder,
  					method: 'POST',
  					data: that.$common.requestSign(data)
  				}).then(res => {
999ea060   刘淇   我的钱包 充值
207
208
209
210
211
  
  
            var mydata = res.data;
            console.log(mydata);
  					that.MakeWxPay(mydata)
e7895736   chenbiao   add 支付 接口联调
212
  				
49201aa2   chenbiao   add 我的钱包 微信支付 接口联调
213
214
215
216
  				})
  			},
  			// 调用微信支付
  			MakeWxPay(mydata) {
999ea060   刘淇   我的钱包 充值
217
  				console.log(mydata)
49201aa2   chenbiao   add 我的钱包 微信支付 接口联调
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
  				var me = this;
  				uni.requestPayment({
  					provider: 'wxpay',
  					timeStamp: mydata.timeStamp,
  					//随机字符串,长度为32个字符以下
  					nonceStr: mydata.nonceStr,
  					//统一下单接口返回的 prepay_id 参数值,提交格式如:prepay_id=xx。
  					package: mydata.package,
  					signType: mydata.signType,
  					paySign: mydata.paySign,
  					success: function(res) {
  						console.log('success:' + JSON.stringify(res));
  
  					},
  					fail: function(err) {
  						console.log('fail:' + JSON.stringify(err));
  						uni.showModal({
  							title: '提示',
  							content: '支付失败/取消',
  							showCancel: false,
  							success: function(res) {
  								if (res.confirm) {
  									console.log('支付失败');
  								}
  							}
  						});
  					}
  				});
  			},
  
3b7af3a2   chenbiao   add 我的钱包 接口联调
248
249
  		}
  	}
4b045f7c   刘淇   江阴初始化项目
250
251
252
  </script>
  
  <style scoped lang="scss">
3b7af3a2   chenbiao   add 我的钱包 接口联调
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
  	.rechargeTop {
  		height: 100px;
  		background: #007AFF;
  		color: #fff;
  		position: relative;
  	}
  
  	.toDetail {
  		/*text-align: right;*/
  
  	}
  
  	.rechargeNum {
  		font-size: 30px;
  	}
  
  	.text {
  		width: 80%;
  		height: 60px;
  		line-height: 60px;
  		margin: 10px auto;
  		border: 1px solid #ccc;
  		text-align: center;
  	}
  
  	.itemActive {
  		background: #f0ad4e;
  	}
  
  	.order-title {
  		font-size: 18px;
  		margin-left: 16px;
  		margin-top: 15px;
  		font-weight: bold;
  		color: #404040;
  	}
  
  	.order-info {
  		font-size: 14px;
  		margin-left: 15px;
  		margin-top: 12px;
  		color: #404040;
  	}
  
  	.order-line {
  		background: #D9D9D9;
  		height: 1px;
  		margin-top: 12px;
  		margin-left: 15px;
  		padding: 0px;
  		overflow: hidden;
  		/* 透明度 */
  		opacity: 0.5;
  	}
  
  	.order-line-bold {
  		background: #FAFAFA;
  		height: 12px;
  		margin-top: 12px;
  		padding: 0px;
  		overflow: hidden;
  	}
  
  	.flex-row-justify-between {
  		display: flex;
  		flex-direction: row;
  		justify-content: space-between;
  	}
  
  	.flex-row-justify-end {
  		display: flex;
  		flex-direction: row;
  		/* 水平对齐*/
  		align-items: baseline;
  
  	}
  
  	.order-discount {
  		color: #C8C7CC;
  		margin-right: 20 upx;
  		/* margin-right: 12px ; */
  		/* margin-top:12px ; */
  
  	}
  
  	.orderwaysview {
  		display: flex;
  		flex-direction: row;
  	}
  
  	.orderways {
  		width: 18px;
  		height: 18px;
  		margin-left: 15px;
  		margin-top: 14px;
  	}
  
  	.orderwaysSel {
  		width: 16px;
  		height: 16px;
  		margin-left: auto;
  		margin-right: 14px;
  		margin-top: 14px;
  		/* justify-content:flex-end; */
  	}
  
  	.button-sp-area {
  		margin: 0 auto;
  		width: 60%;
  		margin-top: 40px;
  
  	}
49201aa2   chenbiao   add 我的钱包 微信支付 接口联调
365
366
  
  	.payInut {
00a21ab7   chenbiao   add 余额明细 接口联调
367
  		display: flex;
49201aa2   chenbiao   add 我的钱包 微信支付 接口联调
368
369
370
371
372
373
374
  		box-sizing: border-box;
  		flex-direction: row;
  		align-items: center;
  		border: 1px solid #DCDFE6;
  		border-radius: 4px;
  		min-height: 36px;
  		padding-left: 10px;
00a21ab7   chenbiao   add 余额明细 接口联调
375
  	}
4b045f7c   刘淇   江阴初始化项目
376
  </style>