placeOrder.vue
13 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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
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
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
<template>
<view class="container">
<Navbar title="确认订单" canBack></Navbar>
<!-- <u-navbar title="确认订单" autoBack :safeAreaInsetTop="true" placeholder fixed></u-navbar> -->
<view class="orderCss">
<!-- <view class="orderTopBarCss">
<u-icon name="car" color="#fff" size="20"></u-icon>
<view class="text-white">
站内配送
</view>
</view> -->
<view class="addressBarCss" @click="selectAddress">
<view class="leftCss">
<u-icon name="map" size="25"></u-icon>
</view>
<view class="centerCss w50" v-if="hasAds">
<view class="margin-top">
联系人:{{ adsObj.name || "" }}
</view>
<view class="text-gray margin-top-sm text-sm w100 overflow-one-lines">
详细地址:{{ adsObj.address || "" }}
</view>
</view>
<view class="centerCss" v-else>
请选择地址
</view>
<view class="rightCss">
<u-icon name="arrow-right" size="20"></u-icon>
</view>
</view>
<view class="shopCardCss">
<view class="flex align-center">
<u-icon name="/static/images/home/shopTitle.png" size="20"></u-icon>
<view class="margin-left-xs">
{{ gasDetail.fSsqymc || "" }}
<!-- 利民液化气供应站 -->
</view>
</view>
<view class="flex justify-between margin-top">
<view class="">
<u-image width="80px" height="80px" :src="gasDetail.image"></u-image>
</view>
<view class="flex flex-direction justify-between margin-left-sm">
<view class="">
{{ gasDetail.fMc }}
<!-- 15KG 液化石油气 -->
</view>
<view class="text-sm text-gray">
描述:{{ gasDetail.fMs || "" }}
</view>
<view class="themeColor text-lg text-bold">
¥{{ gasDetail.fJg }}
</view>
</view>
<view class="flex align-end">
<u-number-box v-model="gasNumber" @change="gasNumberChange"></u-number-box>
</view>
</view>
<view class="flex justify-between align-center margin-top">
<view class="">
订单备注
</view>
<view class="text-gray">
<u-input inputAlign="right" maxlength="30" v-model="orderBody.mjly" border="none" clearable
placeholder="请填写您的备注信息"></u-input>
</view>
</view>
</view>
<view class="moneyCardCss">
<view class="flex justify-between">
<view class="">
商品总金额
</view>
<view class="themeColor">
¥{{ totalPrice }}
</view>
</view>
<view class="flex justify-between margin-top">
<view class="text-gray">
商品金额
</view>
<view class="">
¥{{ gasDetail.fJg }}
</view>
</view>
<!-- <view class="flex justify-between margin-top">
<view class="text-gray">
气瓶押金
</view>
<view class="">
¥0.00
</view>
</view> -->
</view>
<view class="bomBarCss">
<view class="themeColor themeFs">
¥{{ totalPrice }}
</view>
<view class="" @click="submitOrder">
<u-button color="#EA5504">提交订单</u-button>
</view>
</view>
</view>
</view>
</template>
<script>
import {mergeRecursive} from "@/utils/ruoyi";
import storage from '@/utils/storage'
import {mapGetters} from 'vuex'
import {dd_zflx, dd_fkfs, dd_psfs, dd_zffs, dd_ddly, sys_sf} from "@/utils/enums";
export default {
components: {},
props: {},
data() {
return {
orderBody: {
// fBz: "",
// fDdje: "",
// fPsdz: "",
// fQyid: "",
// fCzid: "",
ddly: dd_ddly.XSXD.code,
zffs: "",
psfs: dd_psfs.PS.code,
mjly: "",
hydzId: "",
ddlx: null,
sfhy: sys_sf.Y.code,
xqList: [],
zflx: "",
openId: null
},
adsObj: {
name: "",
address: ""
},
qplist: {
qplxId: "",
sl: 1
},
totalPrice: 0,
qpid: "",
gasDetail: {},
gasNumber: 1,
hasAds: false,
adsId: ""
}
},
onLoad(data) {
if (data.qpid) {
this.qpid = data.qpid;
this.qplist.qplxId = data.qpid;
}
if (data.adsId) {
this.adsId = data.adsId;
}
},
async onShow() {
await this.getGasDetail();
await this.getAdsDetail();
// this.$store.dispatch('GetDefaultAds').then(async (res) => {
// console.log("是否默认地址",res);
// if(res === 'Default'){
// }
// }).catch(e => {
// console.log("查询地址错误", e);
// });
},
computed: {
// ...mapGetters({
// adsId: 'adsId'
// })
},
methods: {
async getGasDetail() {
let query = {
id: this.qpid
}
const result = await this.$api.memberApi.getwQplxDetail(query);
let {
code,
value
} = result;
if (code === 200) {
this.gasDetail = value;
// this.orderBody.fCzid = this.gasDetail.fSsczid;
// this.orderBody.fQyid = this.gasDetail.fSsqyid;
// this.orderBody.fDdje = this.gasDetail.fJg;
this.totalPrice = this.gasDetail.fJg;
let JsonParse = JSON.parse(this.gasDetail.fTp);
this.gasDetail.image = await this.$getPhotoUrl(JsonParse[0].response.fileId);
this.gasDetail = {
...this.gasDetail
};
console.log('气瓶详情', JSON.parse(JSON.stringify(this.gasDetail)));
}
},
async getAdsDetail() {
let that = this;
let formData = {
current: 1,
size: 99
}
const result = await this.$api.memberApi.getwHydzList(formData);
let {
code,
value
} = result;
if (code === 200) {
let data = value.records;
const defaultAddress = data.find(item => item.fSfmrdz === 'y' || item.id === that.adsId);
if (defaultAddress) {
console.log("默认地址", defaultAddress);
let area = defaultAddress.fLxrsf + defaultAddress.fLxrs + defaultAddress.fLxrq + defaultAddress
.fLxrjd
that.$set(that.orderBody, "hydzId", defaultAddress.id);
that.$set(that.adsObj, "name", defaultAddress.fLxr);
that.$set(that.adsObj, "address", area);
// that.orderBody.hydzId = defaultAddress.id;
// that.adsObj.name = defaultAddress.fLxr;
// that.adsObj.address = area;
that.hasAds = true;
} else {
that.orderBody.hydzId = "";
that.adsObj.name = "";
that.adsObj.address = "";
that.hasAds = false;
}
}
},
gasNumberChange(e) {
let number = e.value;
let price = this.gasDetail.fJg;
this.qplist.sl = number;
this.totalPrice = this.$calcUtil.ride(price, number)
},
selectAddress() {
uni.navigateTo({
url: '/pages/mine/appList/addressManagement/addressManagement?qpid=' + this.qpid
})
},
async submitOrder() {
this.orderBody.xqList[0] = this.qplist;
console.log("提交数据", this.orderBody);
if (!this.orderBody.hydzId) {
uni.$u.toast('未选择配送地址');
return false
}
this.$modal.confirm('确认提交订单?', '提示').then(async () => {
console.log('支付---------》')
let rData = {};
let openid= uni.getStorageSync('openId');
if (!openid){
uni.$u.toast('APP暂不支持在线下单,请前往微信公众号进行在线下单。');
return false
}
// 判断环境
this.orderBody.zffs = dd_zffs.WX_PAY.code;
this.orderBody.zflx = dd_zflx.JSAPI.code;
this.orderBody.openId = uni.getStorageSync('openId');
// this.orderBody.openId = "oH7LG54_Y49mVunw2FLXzUCxHWlM";
console.log('H5环境---------》')
console.log('H5环境rData---------》', this.orderBody)
//#ifdef APP-PLUS
this.orderBody.zffs = dd_zffs.WX_PAY.code;
this.orderBody.zflx = dd_zflx.APP.code;
console.log('app环境rData---------》', this.orderBody)
uni.$u.toast('APP暂不支持在线下单,请前往微信公众号进行在线下单。');
return false
//#endif
console.log('orderBody---------》', this.orderBody)
const result = await this.$api.memberApi.savewDd(this.orderBody);
let {
code,
value
} = result;
if (code === 200) {
console.log('value--->', value);
//在这里唤起支付
this.handlePayment(value); // 处理支付逻辑
}
}).catch(() => {
console.log("取消");
});
},
handlePayment(paymentData) {
// 支付参数对象
const paymentParams = {
appId: paymentData.payment.appId,
timeStamp: paymentData.payment.timeStamp,
nonceStr: paymentData.payment.nonceStr,
package: paymentData.payment.packageValue,
signType: paymentData.payment.signType,
paySign: paymentData.payment.paySign
};
// 判断环境
// #ifdef H5
this.handleH5Payment(paymentParams, paymentData);
// #endif
// #ifdef APP-NVUE
this.handleAppPayment(paymentParams, paymentData);
// #endif
},
//app端支付
handleAppPayment(paymentParams, paymentData) {
// 假设APP提供了名为`invokeWechatPay`的方法来处理支付
uni.invoke('invokeWechatPay', paymentParams, (res) => {
if (res.err_msg === 'success') {
console.log('支付成功', paymentParams);
uni.navigateTo({
url: "/pages/home/orderSuccessful?datas=" + JSON.stringify({ddid: paymentData.ddid})
});
} else {
console.error('支付失败', res.err_msg);
}
});
},
//h5端支付
handleH5Payment(paymentParams, paymentData) {
if (typeof WeixinJSBridge == "undefined") {
if (document.addEventListener) {
document.addEventListener('WeixinJSBridgeReady', () => {
this.onBridgeReady(paymentParams, paymentData);
}, false);
} else if (document.attachEvent) {
document.attachEvent('WeixinJSBridgeReady', this.onBridgeReady(paymentParams, paymentData));
document.attachEvent('onWeixinJSBridgeReady', this.onBridgeReady(paymentParams, paymentData));
}
} else {
this.onBridgeReady(paymentParams, paymentData);
}
},
onBridgeReady(paymentParams, paymentData) {
WeixinJSBridge.invoke(
'getBrandWCPayRequest',
paymentParams,
res => {
if (res.err_msg == "get_brand_wcpay_request:ok") {
// 支付成功
console.log('支付成功', paymentParams);
// 可以跳转到支付成功的页面
uni.navigateTo({
url: "/pages/home/orderSuccessful?datas=" + JSON.stringify({ddid: paymentData.ddid})
});
} else {
// 支付失败
console.error('支付失败', res.err_msg);
}
}
);
}
}
}
</script>
<style lang="scss" scoped>
.orderCss {
// margin: 10px;
.orderTopBarCss {
background: #EA5504;
height: 40px;
border-radius: 10px 10px 0 0;
display: flex;
justify-content: center;
align-items: center;
}
.addressBarCss {
position: relative;
display: flex;
justify-content: space-between;
align-items: center;
border-radius: 0 0 10px 10px;
background: #ffffff;
padding: 10px 10px 20px 10px;
.leftCss {
width: 10%;
}
.centerCss {
width: 80%;
min-height: 50px;
margin-left: 5px;
display: flex;
flex-direction: column;
justify-content: center;
align-items: flex-start;
}
.rightCss {
width: 10%;
}
}
.addressBarCss {
background-color: #fff;
position: relative;
}
.addressBarCss:before {
position: absolute;
right: 0;
bottom: 0;
left: 0;
height: 5px;
background: repeating-linear-gradient(-45deg, #A82831, #A82831 20%, transparent 0, transparent 25%, #254A81 0, #254A81 45%, transparent 0, transparent 50%);
background-size: 200px;
content: "";
}
.shopCardCss {
margin: 10px;
margin-top: 10px;
padding: 20px 10px;
border-radius: 15px;
background: #ffffff;
}
.moneyCardCss {
margin: 10px;
padding: 20px 10px;
border-radius: 15px;
background: #ffffff;
}
.bomBarCss {
position: absolute;
width: 100%;
bottom: 0;
left: 0;
padding: 0 20px;
background: #fff;
height: 50px;
display: flex;
justify-content: space-between;
align-items: center;
}
/deep/ .bomBarCss .u-button {
border-radius: 10px !important;
width: 120px;
}
}
</style>