panhui 4 年之前
父节点
当前提交
a8cefc01f1
共有 1 个文件被更改,包括 67 次插入9 次删除
  1. 67 9
      src/views/Givesubmit.vue

+ 67 - 9
src/views/Givesubmit.vue

@@ -54,6 +54,7 @@
                     <!-- <van-button @click="submit" :disabled="orderId"> 取消 </van-button> -->
                 </div>
                 <div class="btn2" @click="submit">支付GAS费</div>
+                <a id="pay" :href="hrefUrl"></a>
             </div>
         </div>
     </div>
@@ -66,6 +67,7 @@ import { mapState } from 'vuex';
 import product from '../mixins/product';
 // import Driver from '../components/Driver.vue';
 let inWeixin = /micromessenger/i.test(navigator.userAgent);
+let inApp = /#cordova#/i.test(navigator.userAgent);
 export default {
     name: 'Submit',
     mixins: [product],
@@ -80,13 +82,13 @@ export default {
                     icon: require('@assets/svgs/zhifubao.svg'),
                     name: '支付宝',
                     type: 'ALIPAY'
-                },
-                {
-                    icon: require('@assets/svgs/wechat.svg'),
-                    name: '微信',
-                    type: 'WEIXIN'
                 }
                 // {
+                //     icon: require('@assets/svgs/wechat.svg'),
+                //     name: '微信',
+                //     type: 'WEIXIN'
+                // }
+                // {
                 //   icon: require("@assets/svgs/png-decp.svg"),
                 //   name: "DCEP",
                 // },
@@ -96,7 +98,9 @@ export default {
             orderId: 0,
             gas: 1,
             showKeyboard: false,
-            inWeixin
+            hrefUrl: '',
+            inWeixin,
+            inApp
         };
     },
     computed: {
@@ -121,6 +125,7 @@ export default {
         if (this.$route.query.id) {
             this.$http.get('/asset/get/' + this.$route.query.id).then(res => {
                 this.info = res;
+                this.$toast.clear();
                 console.log(this.info);
             });
         }
@@ -136,7 +141,36 @@ export default {
                     this.sets = res.set;
                 });
         },
+        getOrder(next = false) {
+            this.$http.get('/giftOrder/get/' + this.orderId).then(res => {
+                if (this.timer) {
+                    clearTimeout(this.timer);
+                }
+                if (res.status === 'PROCESSING' || res.status === 'FINISH' || res.status === 'CANCELLED') {
+                    this.$dialog
+                        .alert({
+                            title: '提示',
+                            message: res.status === 'CANCELLED' ? '藏品转赠失败' : '藏品转赠成功'
+                        })
+                        .then(() => {
+                            if (res.status === 'CANCELLED') {
+                                this.$router.go(-2);
+                            } else {
+                                this.$router.go(-2);
+                            }
+                            // on close
+                        });
+                } else if (next) {
+                    this.timer = setTimeout(() => {
+                        this.getOrder(next);
+                    }, 1000);
+                }
+            });
+        },
         submit() {
+            if (this.orderId) {
+                return;
+            }
             this.$http
                 .post('/user/verifyTradeCode', {
                     tradeCode: this.password
@@ -148,11 +182,35 @@ export default {
                             toUserId: this.$route.query.toUserId
                         })
                         .then(res => {
+                            this.orderId = res.id;
                             this.$nextTick(() => {
                                 if (this.payType === 'ALIPAY') {
-                                    document.location.replace(
-                                        resolveUrl(this.$baseUrl, 'payOrder/gift/alipay?id=' + res.id)
-                                    );
+                                    // document.location.replace(
+                                    //     resolveUrl(this.$baseUrl, 'payOrder/gift/alipay?id=' + res.id)
+                                    // );
+                                    this.$http
+                                        .get(`/payOrder/gift/${this.inApp ? 'alipay_app' : 'alipay_h5'}?id=${res.id}`)
+                                        .then(res => {
+                                            this.hrefUrl = 'alipays://platformapi/startapp?saId=10000007&qrcode=' + res;
+                                            // window.open(
+                                            //     'alipays://platformapi/startapp?saId=10000007&qrcode=' + res,
+                                            //     '_blank'
+                                            // );
+                                            this.$nextTick(() => {
+                                                document.getElementById('pay').click();
+                                            });
+
+                                            this.$toast.loading({
+                                                message: '加载中...',
+                                                forbidClick: true
+                                            });
+                                            this.getOrder(true);
+                                        })
+                                        .catch(e => {
+                                            if (e.error) {
+                                                this.$toast(e.error);
+                                            }
+                                        });
                                 } else if (this.payType === 'WEIXIN') {
                                     if (this.inWeixin) {
                                         this.$toast.loading('加载中');