Selaa lähdekoodia

精度&优惠券支付

panhui 4 vuotta sitten
vanhempi
commit
9c55417411
2 muutettua tiedostoa jossa 65 lisäystä ja 41 poistoa
  1. 15 0
      src/main/nine-space/src/mixins/common.js
  2. 50 41
      src/main/nine-space/src/views/Submit.vue

+ 15 - 0
src/main/nine-space/src/mixins/common.js

@@ -83,6 +83,21 @@ export default {
                 return '';
             }
         },
+        accAdd(arg1, arg2) {
+            var r1, r2, m;
+            try {
+                r1 = arg1.toString().split('.')[1].length;
+            } catch (e) {
+                r1 = 0;
+            }
+            try {
+                r2 = arg2.toString().split('.')[1].length;
+            } catch (e) {
+                r2 = 0;
+            }
+            m = Math.pow(10, Math.max(r1, r2));
+            return (arg1 * m + arg2 * m) / m;
+        },
         checkLogin() {
             if (this.isLogin) {
                 return Promise.resolve();

+ 50 - 41
src/main/nine-space/src/views/Submit.vue

@@ -58,7 +58,6 @@
 
 <script>
 const path = require('path');
-import { add } from 'mathjs';
 import product from '../mixins/product';
 import { mapState } from 'vuex';
 let inWeixin = /micromessenger/i.test(navigator.userAgent);
@@ -97,10 +96,10 @@ export default {
         money() {
             let money = 0;
             if (this.info.price && !this.couponInfo) {
-                money = add(this.info.price, money);
+                money = this.accAdd(this.info.price, money);
             }
             if (this.gas && (!this.couponInfo || this.couponInfo.needGas)) {
-                money = add(money, this.gas);
+                money = this.accAdd(money, this.gas);
             }
 
             return money;
@@ -169,46 +168,56 @@ export default {
             this.$http
                 .post(url)
                 .then(res => {
-                    this.$toast.clear();
-                    this.orderId = res.id;
-                    this.$router.replace('/submit?orderId=' + res.id);
-                    this.$nextTick(() => {
-                        if (this.payType === 'ALIPAY') {
-                            document.location.replace(path.resolve(this.$baseUrl, 'payOrder/alipay?id=' + res.id));
-                        } else if (this.payType === 'WEIXIN') {
-                            if (this.inWeixin) {
-                                this.$toast.loading('加载中');
-                                this.$http
-                                    .post('/payOrder/weixin', { id: res.id, openId: localStorage.getItem('openId') })
-                                    .then(res => {
-                                        console.log({
-                                            ...res,
-                                            package: res.package || res.packageValue
-                                        });
-                                        let _this = this;
-                                        wx.chooseWXPay({
-                                            ...res,
-                                            package: res.package || res.packageValue,
-                                            timestamp: res.timeStamp,
-                                            success(res) {
-                                                _this.$toast.success('支付成功');
-                                                setTimeout(() => {
-                                                    _this.$router.replace('/orders');
-                                                }, 1000);
-                                            },
-                                            fail(e) {
-                                                console.log(e);
-                                                _this.$toast('支付失败,请稍后再试');
-                                            }
+                    if (this.money) {
+                        this.$toast.clear();
+                        this.orderId = res.id;
+                        this.$router.replace('/submit?orderId=' + res.id);
+                        this.$nextTick(() => {
+                            if (this.payType === 'ALIPAY') {
+                                document.location.replace(path.resolve(this.$baseUrl, 'payOrder/alipay?id=' + res.id));
+                            } else if (this.payType === 'WEIXIN') {
+                                if (this.inWeixin) {
+                                    this.$toast.loading('加载中');
+                                    this.$http
+                                        .post('/payOrder/weixin', {
+                                            id: res.id,
+                                            openId: localStorage.getItem('openId')
+                                        })
+                                        .then(res => {
+                                            console.log({
+                                                ...res,
+                                                package: res.package || res.packageValue
+                                            });
+                                            let _this = this;
+                                            wx.chooseWXPay({
+                                                ...res,
+                                                package: res.package || res.packageValue,
+                                                timestamp: res.timeStamp,
+                                                success(res) {
+                                                    _this.$toast.success('支付成功');
+                                                    setTimeout(() => {
+                                                        _this.$router.replace('/orders');
+                                                    }, 1000);
+                                                },
+                                                fail(e) {
+                                                    console.log(e);
+                                                    _this.$toast('支付失败,请稍后再试');
+                                                }
+                                            });
                                         });
-                                    });
-                            } else {
-                                document.location.replace(
-                                    path.resolve(this.$baseUrl, 'payOrder/weixin_h5?id=' + res.id)
-                                );
+                                } else {
+                                    document.location.replace(
+                                        path.resolve(this.$baseUrl, 'payOrder/weixin_h5?id=' + res.id)
+                                    );
+                                }
                             }
-                        }
-                    });
+                        });
+                    } else {
+                        this.$toast.success('支付成功');
+                        setTimeout(() => {
+                            this.$router.replace('/orderDetail?id=' + res.id);
+                        }, 1000);
+                    }
                 })
                 .catch(e => {
                     if (e) {