index.vue 1.8 KB
Newer Older
1 2
<template>
    <div>
3
        <headerNav title="收银台"/>
4
        <van-cell-group>
5 6
            <van-cell title="订单商品名" :value="transaction.orderSubject" />
            <van-cell title="价格" :value="transaction.price / 100.0" />
7
        </van-cell-group>
8
        <van-button slot="button" size="small" type="primary" @click="submit(9999)">模拟支付</van-button>
9 10 11 12
    </div>
</template>

<script>
13 14
  import { getTransaction, submitTransaction } from '../../api/pay';
  import pingpp from 'pingpp-js';
15 16 17 18 19 20
  import { Dialog } from 'vant';

  export default {

    data() {
      return {
21 22
        appId: this.$route.query.appId,
        orderId: this.$route.query.orderId,
23
        returnUrl: this.$route.query.returnUrl,
24
        transaction: {},
25 26 27 28
      }
    },

    mounted() {
29
      let response = getTransaction(this.appId, this.orderId);
30
      response.then(data => {
31
        this.transaction = data;
32 33 34 35
      });
    },

    methods: {
36
      submit(payChannel) {
37
        let that = this;
38 39
        submitTransaction(this.appId, this.orderId, payChannel).then(data => {
          pingpp.createPayment(data.invokeResponse, function(result, err) {
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
            if (result === 'success') {
              Dialog.alert({
                title: '系统提示',
                message: '支付成功',
                beforeClose: function (action, done) {
                  // 关闭弹窗
                  done();
                  // 跳转到我的优惠劵
                  that.$router.push(decodeURI(that.returnUrl));
                }
              });
            } else {
              // console.log(err.msg);
              // console.log(err.extra);
              Dialog.alert({
                title: '系统提示',
                message: '支付失败:' + err.msg,
              });
            }
59 60 61 62 63 64 65
          });
        });
      }
    }

  }
</script>