xuqiang 4 lat temu
rodzic
commit
c3126b613f
1 zmienionych plików z 61 dodań i 49 usunięć
  1. 61 49
      src/main/pc-space/src/views/Submit.vue

+ 61 - 49
src/main/pc-space/src/views/Submit.vue

@@ -2,25 +2,28 @@
     <div>
         <el-dialog center title="支付订单" :visible.sync="show" width="680px">
             <div class="page" v-loading="loading">
-                <div>选择兑换券</div>
-                <div class="coupon" @click="choose(list2)">
-                    <div class="coupon-top">
-                        <div class="text1">{{ list2.name }}</div>
-                        <div class="text2">
-                            <span>兑换券编码</span>
-                            <span>{{ list2.id }}</span>
+                <div v-if="list2">
+                    <div>选择兑换券</div>
+                    <div class="coupon" @click="choose(list2)">
+                        <div class="coupon-top">
+                            <div class="text1">{{ list2.name }}</div>
+                            <div class="text2">
+                                <span>兑换券编码</span>
+                                <span>{{ list2.id }}</span>
+                            </div>
+                        </div>
+                        <div class="coupon-bottom">
+                            <span>有效期至:{{ list2.expiration }}</span>
+                            <span v-if="!list2.limited">规定商品可用</span>
                         </div>
-                    </div>
-                    <div class="coupon-bottom">
-                        <span>有效期至:{{ list2.expiration }}</span>
-                        <span v-if="!list2.limited">规定商品可用</span>
-                    </div>
 
-                    <img v-if="chooseId === list2.id" class="icon" src="../assets/icon_gouxuan_pre.png" alt="" />
-                    <img v-else class="icon" src="../assets/icon_gouxuan_huise.png" alt="" />
-                    <el-empty v-if="empty" description="暂无兑换券哦~" />
+                        <img v-if="chooseId === list2.id" class="icon" src="../assets/icon_gouxuan_pre.png" alt="" />
+                        <img v-else class="icon" src="../assets/icon_gouxuan_huise.png" alt="" />
+                        <el-empty v-if="empty" description="暂无兑换券哦~" />
+                    </div>
+                    <div @click="all">查看更多</div>
                 </div>
-                <div @click="all">查看更多</div>
+
                 <div class="info">
                     <div class="price">
                         <span class="text1">应付金额</span>
@@ -101,16 +104,18 @@
 <script>
 import vueQrcode from '@chenfengyuan/vue-qrcode';
 import resolveUrl from 'resolve-url';
-import pageableTable from '../mixins/pageableTable';
+// import pageableTable from '../mixins/pageableTable';
 import { mapState } from 'vuex';
 import { add } from 'mathjs';
 export default {
-    mixins: [pageableTable],
+    // mixins: [pageableTable],
     data() {
         return {
             show: false,
             show2: false,
-            url: '/userCoupon/all',
+            // url: '/userCoupon/all',
+            chooseId: '',
+            empty: false,
             payMethods: 'WEIXIN',
             list2: [],
             list3: [],
@@ -158,40 +163,39 @@ export default {
 
             return money;
         },
-        ...mapState(['couponInfo'])
-    },
-    beforeRouteLeave(to, from, next) {
-        console.log(to);
-        if (to.path !== '/couponList') {
-            this.$store.commit('setCouponInfo', null);
-        }
-        next();
+        ...mapState(['couponInfo', 'userInfo'])
     },
     mounted() {
-        this.getData();
+        if (this.isLogin) {
+            this.add();
+        }
     },
     methods: {
+        add() {
+            this.$http
+                .post(
+                    '/userCoupon/all',
+                    {
+                        query: {
+                            userId: this.userInfo.id
+                        }
+                    },
+                    {
+                        body: 'json'
+                    }
+                )
+                .then(res => {
+                    this.list2 = res[0];
+                    this.list3 = res;
+                });
+        },
         IdFn(e) {
-            console.log(e);
             this.list2 = e;
             this.show2 = false;
         },
         all() {
-            console.log(111);
             this.show2 = true;
         },
-        beforeData() {
-            return {
-                query: {
-                    userId: this.userInfo.id
-                }
-            };
-        },
-        setList(list) {
-            this.list2 = list[0];
-            this.list3 = list;
-            console.log(this.list2);
-        },
         choose(info) {
             console.log(info);
             this.chooseId = info.id;
@@ -202,18 +206,26 @@ export default {
             // if (this.payMethods === 'DCEP') {
             //     this.wait();
             // }
+            let url = '/order/create?collectionId=' + this.$route.query.id + '&qty=1';
+            if (this.couponInfo) {
+                url += '&couponId=' + this.couponInfo.id;
+            }
             this.$http
-                .post('/order/create?collectionId=' + this.$route.query.id + '&qty=1')
+                .post(url)
                 .then(res => {
-                    console.log(res);
-                    this.status = res.status;
-                    this.id = res.id;
-                    console.log(this.id);
-                    console.log(this.payUrl);
+                    if (this.money) {
+                        this.status = res.status;
+                        this.id = res.id;
+                    } else {
+                        this.$message.success('支付成功');
+                        setTimeout(() => {
+                            this.$router.replace('/collectionorder');
+                        }, 1000);
+                    }
                 })
                 .catch(e => {
                     if (e) {
-                        this.$toast(e.error);
+                        this.$message.error(e.error);
                     }
                 });
         },