orderPay.vue 12.5 KB
<template>
  <div>
    <div class="car-wrap">
      <div class="carBG" :class="carWrapBG | formateColor">
        <p class="carNumber">{{carNumber}}</p>
        <p class="payFee">{{(arrearageActFee/100).toFixed(2)}}元</p>
      </div>
    </div>

    <ul class="fee-wrap">
      <li>
        <span>待缴金额</span>
        <span>{{(arrearageActFee/100).toFixed(2)}}</span>
      </li>
      <li>
        <span>优惠金额</span>
        <span>{{(arrearageDiscFee/100).toFixed(2)}}</span>
      </li>
      <li>
        <span>应付金额</span>
        <span>{{(arrearageActFee/100).toFixed(2)}}</span>
      </li>
    </ul>
    <div style="padding: 20px 18px">
      <div class="toPay" @click="toPay">{{clientBrowser}}支付</div>
    </div>

    <div v-if="appOrderTimeout.length>0">
      <p class="tip">
        温馨提示:
      </p>
      <p style="color: #666;padding: 0 18px;">
        {{appOrderTimeout}}
      </p>
    </div>



  </div>
</template>

<script>
// import CryptoJS from '../utils/AES.js'
// let Base64 = require('js-base64').Base64

import {aliPay, getOpenId, vxPayQuery, bankH5Pay, queryParkingRecordPageByCarNumbers} from '@/api/orderPay/orderPay'

export default {
  name: 'orderPay',
  data() {
    return {
      carWrapBG: 0,
      carNumber: '',
      arrearageActFee: 0,
      arrearageDiscFee: 0,
      arrearageActFee: 0,
      parkingData: [], //  在停数据
      historyList: [], // 历史欠费数据
      clientBrowser: '', // 客户端
      paySrcType: '', //支付的类型   101 是本次   103是历史欠费
      orderId: '',  //支付的订单
      webAppCode: '', // 微信code
      appOrderTimeout: '', // 超时描述
    }
  },
  created() {

    this.carWrapBG = this.$route.query.carColor //车牌颜色
    this.carNumber = this.$route.query.carNumber
    this.arrearageTotalFee = this.$route.query.arrearageTotalFee // 应收
    this.arrearageDiscFee = this.$route.query.arrearageDiscFee // 优惠
    this.arrearageActFee = this.$route.query.arrearageActFee // 实收
    this.clientBrowser = this.$utils.clientBrowser() //支付方式
    this.paySrcType = this.$route.query.paySrcType // 实收
    this.orderId = this.$route.query.ordeID
    console.log(this.orderId)
    this.appOrderTimeout = this.$route.query.appOrderTimeout
    if (this.clientBrowser == "微信") {
      this.webAppCode = this.getCode();
    }

  },
  mounted() {

  },
  methods: {
    getCode() {
      var appID = this.$utils.myVxAppId;
      var code = this.getUrlParam('code');
      var local = window.location.href;
      if (code == null || code === '') {
        window.location.href = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' + appID + '&redirect_uri=' + encodeURIComponent(local) + '&response_type=code&scope=snsapi_userinfo&state=1#wechat_redirect'
      } else {
        return code;
      }
    },
    getUrlParam(name) {
      var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)');
      var r = window.location.search.substr(1).match(reg)
      if (r != null) return unescape(r[2])
      return null
    },
    toPay() {
      let me = this
      let _order = []

      console.log(this.orderId)
      if (this.paySrcType == 103) {
        this.orderId = JSON.parse(this.orderId)
        this.orderId.forEach(item => {
          _order.push({
            orderId: item
          })
        })
        this.orderId = []
        this.orderId = _order
      }

      if (this.clientBrowser == '微信') { // 微信支付
        let _openId = sessionStorage.getItem('openIdData')
        if (_openId) {
          me.vxPay(_openId, this.orderId)
        } else {
          //第一步获取openid
          var codeParams = {
            code: this.webAppCode,
            appId: this.$utils.myVxAppId
          };
          getOpenId(codeParams).then(res => {
            if (res.code == 0) {
              me.vxPay(res.data, this.orderId)
              sessionStorage.setItem('openIdData', res.data)
            } else if (res.code == 40163) { //code been used, hints[重复code问题]
              this.$msgbox('提示', '请重新扫码重复code问题')
              console.log(res.message);
            } else {
              this.$msgbox('提示', '请重新扫码')
            }
          })
        }
      }
    },
    vxPay(openIdData, orderIdData) {
      let vm = this
      var wxParams = {};
      wxParams.orderId = orderIdData;
      wxParams.backType = 2,
      wxParams.orgId = this.$utils.myOrgId,
      wxParams.payType = 4;// 1:支付宝 2:微信 3:银联 10:H5   4微信公众号
      wxParams.terminalSource = 7;//请求端来源 1: 任你停 2:pda 3:微信公共号 7:H5扫码 10页面支付
      wxParams.carNumber = this.carNumber;
      wxParams.paySrcType = this.paySrcType;//101停车支付
      wxParams.recordArreaInfos = JSON.stringify(orderIdData);
      wxParams.openId = openIdData;
      wxParams.appId = this.$utils.myVxAppId;
      vxPayQuery(wxParams).then(res => {
        if (res.code == 0) { //
          if (res.data) {
            var data = res.data;
            console.log(JSON.stringify(data));
            if (typeof WeixinJSBridge === 'undefined') { // 微信浏览器内置对象。参考微信官方文档
              if (document.addEventListener) {
                document.addEventListener('WeixinJSBridgeReady', vm.onBridgeReady(data), false)
              } else if (document.attachEvent) {
                document.attachEvent('WeixinJSBridgeReady', vm.onBridgeReady(data))
                document.attachEvent('onWeixinJSBridgeReady', vm.onBridgeReady(data))
              }
            } else {
              console.log('准备调用微信支付')
              vm.onBridgeReady(data)
            }
          } else {
            this.$msgbox('提示', '没有找到返回值')
          }
        } else {
          console.log(res.message);
          this.$msgbox('提示', res.message)
        }
      })
    },
    onBridgeReady(params) {
      let me = this
      console.log('调用微信支付WeixinJSBridge')
      WeixinJSBridge.invoke(
        'getBrandWCPayRequest', params,
        //
        // 'getBrandWCPayRequest', { // 下面参数内容都是后台返回的
        //   'appId': data.appId, // 公众号名称,由商户传入
        //   'timeStamp': data.timeStamp, // 时间戳
        //   'nonceStr': data.nonceStr, // 随机串
        //   'package': data.package, // 预支付id
        //   'signType': data.signType, // 微信签名方式
        //   'paySign': data.paySign // 微信签名
        // },
        function (res) {
          // 使用以上方式判断前端返回,微信团队郑重提示:res.err_msg将在用户支付成功后返回ok,但并不保证它绝对可靠。
          if (res.err_msg === 'get_brand_wcpay_request:ok') {
            console.log('成功')
            var salt = me.$utils.myCommonSalt(32);
            let wxparams = {
              pageNum: 1,
              pageSize: 10000,
              parkState: 10,
              terminalSource: 7,
              carNumber: me.carNumber,
              app_id: me.$utils.myVarAppid,
              deviceInfo: me.$utils.myDeviceInfo,
              salt: salt,
              sign_type: "md5",
              token: '',
            }
            wxparams.sign = me.$utils.signObject(wxparams)
            queryParkingRecordPageByCarNumbers(wxparams).then(response => {
              console.log(response)
              me.parkList = response.data.dataList

              // alert(JSON.stringify(me.parkList))
              // alert(me.parkList.length)
              if (me.parkList.length == 0) {
                me.$router.push({
                  path: 'parkRecord',
                  query: {
                    carNumber: me.carNumber,
                    carNumberColor: me.carWrapBG,
                    parkFlag: 0 //  0表示在停    1表示历史
                  }
                })

              } else {
                me.parkingData = me.parkList.filter(item => {
                  return item.parkState == '10'
                })
                console.log(me.parkingData)
                me.historyList = me.parkList.filter(item => {
                  return item.parkState == '20'
                })
                console.log(me.historyList)

                if (me.historyList.length > 0) {
                  MessageBox.confirm('', {
                    message: '您当前有历史欠费 是否立即补缴?',
                    title: '温馨提示',
                    confirmButtonText: '去补缴',
                    cancelButtonText: '取消'
                  }).then(action => {
                    if (action == 'confirm') {     //确认的回调
                      console.log('确定');
                      me.$router.push({
                        path: 'parkRecord',
                        query: {
                          carNumber: me.carNumber,
                          carNumberColor: me.carWrapBG,
                          parkFlag: 1 //  0表示在停    1表示历史
                        }
                      })
                    }
                  }).catch(err => {
                    if (err == 'cancel') {     //取消的回调
                      console.log('取消');
                    }
                  });
                } else {

                  if (me.paySrcType == 101) {  //缴费了本次
                    me.$router.push({
                      path: 'parkRecord',
                      query: {
                        carNumber: me.carNumber,
                        carNumberColor: me.carWrapBG,
                        parkFlag: 0 //  0表示在停    1表示历史
                      }
                    })
                  } else {
                    MessageBox.confirm('', {
                      message: '您当前有在停订单 是否立即支付?',
                      title: '温馨提示',
                      confirmButtonText: '去支付',
                      cancelButtonText: '取消'
                    }).then(action => {
                      if (action == 'confirm') {     //确认的回调
                        console.log('确定');
                        me.$router.push({
                          path: 'parkRecord',
                          query: {
                            carNumber: me.carNumber,
                            carNumberColor: me.carWrapBG,
                            parkFlag: 0 //  0表示在停    1表示历史
                          }
                        })
                      }
                    }).catch(err => {
                      if (err == 'cancel') {     //取消的回调
                        console.log('取消');
                      }
                    });
                  }

                }
              }

            })

          } else {
            console.log('失败')
            this.$msgbox('提示', '支付失败')
            me.$router.go(-2);
          }
        }
      )
    },
  },
  filters: {}
}
</script>

<style scoped lang="scss">
  .car-wrap {
    padding: 7px 7px;
    background: #FFF;
  }

  .carBG {
    width: 100%;
    height: 130px;
  }

  .carBlue {
    background: url("../../assets/images/blueBG.png") no-repeat;
    background-size: 100% 100%;
  }

  .carYellow {
    background: url("../../assets/images/yellowBG.png") no-repeat;
    background-size: 100% 100%;
  }

  .carGreen {
    background: url("../../assets/images/greenBG.png") no-repeat;
    background-size: 100% 100%;
  }

  .carWhite {
    background: url("../../assets/images/whiteBG.png") no-repeat;
    background-size: 100% 100%;
  }

  .carBlack {
    background: url("../../assets/images/blackBG.png") no-repeat;
    background-size: 100% 100%;
  }

  .carNumber {
    padding: 20px 0 10px;
    font-size: 30px;
    color: #fff;
    text-align: center;
  }

  .payFee {
    font-size: 24px;
    color: #FF7B7B;
    text-align: center;
  }

  .fee-wrap {
    background: #FFF;
    padding: 0 18px;
    > li {
      display: flex;
      justify-content: space-between;
      height: 30px;
      line-height: 30px;
      border-bottom: 1px solid #EAEAEA;
      &:last-child {
        border-bottom: 0;
      }
    }

  }

  .toPay {
    width: 100%;
    height: 44px;
    margin: 0 auto;
    line-height: 44px;
    text-align: center;
    background: linear-gradient(180deg, #3885D9 0%, #4194EF 100%);
    border-radius: 4px;
    border: 1px solid #0D72E2;
    font-size: 20px;
    color: #FFF;
    cursor: pointer;
  }

  .tip {
    padding-left: 40px;
    background: url("../../assets/images/tip.png") no-repeat 18px center;
    background-size: 16px 16px;
    color: #666;
  }
</style>