819527061@qq.com
2025-01-07 1fdb81a91f5f4092e927d2d9a7cc9ff4d231fca4
src/components/page/IndexTest.vue
@@ -50,17 +50,54 @@
            </div>
        </div>
      <div class="dialog-box">
        <el-dialog
            title="支付"
            :close-on-click-modal="false"
            :visible.sync="dialogVisible"
            width="100%">
          <div class="dialog-main-box">
            <div class="dialog-main-line">
              <h1>合计费用</h1>
              <h1>{{this.statisticData.price}}元</h1>
            </div>
            <div class="dialog-main-line">
              <h1>停车时长</h1>
              <h1>{{this.statisticData.timeStr}}</h1>
            </div>
            <div class="dialog-main-line-middle">
              <h1>{{this.statisticData.price}}<font>元</font></h1>
            </div>
            <div class="wx-img-box">
              <div class="wx-img-l">
                <img src="../../assets/images/wxIcon.png" alt="">
                <h1>微信支付</h1>
              </div>
              <div class="wx-img-r">
                <img src="../../assets/images/duigouIcon.png" alt="">
              </div>
            </div>
          </div>
          <span slot="footer" class="dialog-footer">
            <el-button type="primary" @click="pay()" :loading="payNowFlag">立 即 支 付</el-button>
          </span>
        </el-dialog>
      </div>
    </div>
</template>
<script>
    export default {
import wx from 'weixin-js-sdk'
export default {
        name: 'dashboard',
        data() {
            return {
                dialogVisible:false,
                payFlag:false,
                payNowFlag:false,
                outParkId:"",
                type:null,
                statisticData:{
                },
@@ -68,11 +105,34 @@
                showFlag2:true,
                status3:0,
                carNo:"",
                code2:""
                code2:"",
                code:""
            }
        },
        created(){
          let ua = window.navigator.userAgent.toLowerCase();
          //判断是不是微信
          if (ua.match(/MicroMessenger/i) == "micromessenger") {
            // 微信
            this.type = 0
          }
          //判断是不是支付宝
          if (ua.match(/AlipayClient/i) == "alipayclient") {
            //支付宝
            this.type = 1
          }
          if(this.type == null){
            this.$message.error("请用微信或支付宝扫描二维码")
            return;
          }
            var url = window.location.href;
            var count = url.split('?').length-1;
            if(count >1){
              this.code = this.getCodeFromUrl(url)
              this.code2 = this.getCode2FromUrl(url)
              window.location.href = "http://hesuancj.cn/#/indexTest?code="+this.code+"&state=STATE&code2="+this.code2
            }
            var cs = url.split('?')[1];
            var cs_arr = cs.split('&');
            var cs={};
@@ -80,24 +140,35 @@
                cs[cs_arr[i].split('=')[0]] = cs_arr[i].split('=')[1]
            }
            //this.outParkId = cs.code;
            this.code2 = cs.code;
            this.$byutil.postData(this, this.$systemconfig.basePath + '/outPark/findByBarrierCode', {code:cs.code}, res => {
                this.statisticData = res.data;
                this.outParkId = this.statisticData.id;
                this.status3 = this.statisticData.status3;
                this.payFlag = false
                if(this.status3==1){
                    this.$message({
                        message: '您有违章未处理,请先处理或联系停车场管理人员',
                        type: 'error',
                        duration:5000,
                    });
                }
            })
          this.code2 = cs.code2;
          this.code = cs.code;
          if(this.code2 == null || this.code2 == ''){
            window.location.href = "http://hesuancj.cn/#/indexTest?code2="+this.code
          }
          if(this.code != null && this.code != '') {
            this.dialogVisible = true
          }else {
            this.dialogVisible = false
          }
          this.$byutil.postData(this, this.$systemconfig.basePath + '/ffzf/outpark/findByBarrierCode2', {code2:cs.code2}, res => {
            this.statisticData = res.data;
            this.outParkId = this.statisticData.id;
            this.status3 = this.statisticData.status3;
            this.oldCarNo = this.statisticData.carNo;
            this.payFlag = false
            if(this.status3==1){
              this.$message({
                message: '您有违章未处理,请先处理或联系停车场管理人员',
                type: 'error',
                duration:5000,
              });
            }
          })
        },
        methods: {
            pay(){
                this.payFlag = true;
                this.payNowFlag = true;
                if(this.status3==1){
                    this.$message({
                        message: '您有违章未处理,请先处理或联系停车场管理人员',
@@ -106,14 +177,11 @@
                    });
                    return;
                }
                this.$byutil.postData(this, this.$systemconfig.basePath + '/ffzf/api/park', {id:this.outParkId}, res => {
                    this.$message({
                        message: '2秒后自动跳转到支付页面,防止内外网数据同步延迟,请稍等',
                        type: 'success',
                        duration:2000,
                    });
                  setTimeout(function(){window.location.href = res.msg;},2000);
                    this.showFlag = false;
                this.$byutil.postData(this, this.$systemconfig.basePath + '/ffzf/api/parkXT', {id:this.outParkId}, res => {
                  if(res.code === 0){
                    this.getCode()
                    this.showFlag = false
                  }
                })
            },
            noCarOut(){
@@ -139,7 +207,116 @@
                }
            },
        }
            GetQueryString(name) {
              var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
              var r = window.location.search.substr(1).match(reg);
              if (r != null) return unescape(r[2]); return null;
            },
            /**
             * 解析微信redirect_uri地址中的code
             */
            getCodeFromUrl (cur_url) {
              let index = cur_url.split('?')[1]
              let paramStr =index.split('&')[0];
              let code =paramStr.split('=')[1];
              return code
            },
            /**
             * 解析微信redirect_uri地址中的code2
             */
            getCode2FromUrl (cur_url) {
              let index = cur_url.split('?')[2]
              let code2 =index.split('=')[1];
              return code2
            },
            getCode(){
              if(this.type == 0 ){
                //微信,获取code
                if(this.code==null||this.code==""){
                  var url = encodeURIComponent("http://hesuancj.cn/#/indexTest?code2="+this.code2);
                  window.location.href ="https://open.weixin.qq.com/connect/oauth2/authorize?" +
                      "appid=wx46e756aed958f895&redirect_uri="+url+"&response_type=code" +
                       "&scope=snsapi_userinfo&state=STATE#wechat_redirect";
                      //"&scope=SCOPE&state=STATE#wechat_redirect";
                }else{
                  this.$byutil.postData(this, this.$systemconfig.basePath + '/ffzf/api/getOpenId', {id:this.outParkId,code:this.code}, res => {
                    if(res.code === 0){
                      var param = res.data;
                      // 点击支付时候调用
                      if (typeof WeixinJSBridge === 'undefined') {
                        if (document.addEventListener) {
                          document.addEventListener('WeixinJSBridgeReady', this.onBridgeReady(param), false)
                        } else if (document.attachEvent) {
                          document.attachEvent('WeixinJSBridgeReady', this.onBridgeReady(param))
                          document.attachEvent('onWeixinJSBridgeReady', this.onBridgeReady(param))
                        }
                      } else {
                        this.onBridgeReady(param)
                      }
                      this.showFlag = false
                    }else {
                      alert('微信支付调起失败!')
                    }
                  })
                }
              }else if(this.type == 1){
                //支付宝,不获取code
                this.$byutil.postData(this, this.$systemconfig.basePath + '/ffzf/api/payByAli', {id:this.outParkId}, res => {
                  if(res.code != 0){
                    alert(res.data)
                    this.showFlag = false
                  }else {
                    this.$message({
                      message: '2秒后自动跳转到支付页面,防止内外网数据同步延迟,请稍等',
                      type: 'success',
                      duration:2000,
                    });
                    setTimeout(function(){window.location.href = res.msg;},2000);
                    this.showFlag = false;
                  }
                })
              }
            },
          onBridgeReady (params) {
            const that = this
            WeixinJSBridge.invoke(
                'getBrandWCPayRequest',
                {
                  appId: params.appId, // 公众号名称,由商户传入
                  timeStamp: params.timeStamp, // 支付签名时间戳,注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
                  nonceStr: params.nonceStr, // 支付签名随机串,不长于 32 位
                  package: params.package, // 统一支付接口返回的prepay_id参数值,提交格式如:prepay_id=\*\*\*)
                  signType: params.signType, // 签名方式,默认为'SHA1',使用新版支付需传入'MD5'
                  paySign: params.paySign // 支付签名
                },
                (res) => {
                  if (res.err_msg === 'get_brand_wcpay_request:ok') {
                    that.queryOrder() // 这里是查询订单是否支付完成,然后执行成功和失败的业务逻辑
                  } else if (res.err_msg === 'get_brand_wcpay_request:fail') {
                    alert('支付失败!')
                  } else if (res.err_msg === 'get_brand_wcpay_request:cancel') {
                    alert('支付取消!')
                  }
                }
            )
          },
          queryOrder() {
            this.$byutil.postData(this, this.$systemconfig.basePath + '/ffzf/outpark/getById', {id: this.outParkId}, res => {
              if (res.code == 0) {
                let outpark = res.data
                if(outpark.status == 1){
                  window.location.href = "http://hesuancj.cn/#/indexOk?code2="+this.code2
                }else {
                  window.location.href = "http://hesuancj.cn/#/indexFail?code2="+this.code2
                }
              }
            })
          }
      }
    }
</script>
@@ -165,6 +342,39 @@
            padding: 11px 15px;
            font-size: 0.347rem  /* 26/75 */;
        }
    }
    .dialog-box{
      .el-dialog{
        bottom: 0;
        position: fixed;
        left: 0;
        margin: 0;
      }
      .el-dialog__body{
        padding: 2.67vw  /* 20/7.5 */ 5.33vw  /* 40/7.5 */;
      }
      .el-dialog__header{
        width: 100%;
        display: flex;
        justify-content: center;
        align-items: center;
        padding: 1.87vw  /* 14/7.5 */;
        background: rgba(103,201,122,0.1);
      }
      .el-dialog__title{
        font-size: 4vw  /* 30/7.5 */;
      }
      .el-dialog__headerbtn{
        top: 2.67vw  /* 20/7.5 */;
      }
      .dialog-footer{
        display: flex;
        width: 100% !important;
        .el-button{
          width: 100%;
          background: rgba(74,76,89,1);
        }
      }
    }
</style>
@@ -250,4 +460,53 @@
    .weizhang-main-bootom{
        margin-top: 0.333rem  /* 25/75 */;
    }
    .dialog-main-box{
      .dialog-main-line{
        display: flex;
        justify-content: space-between;
        h1{
          font-size: 3.2vw  /* 24/7.5 */;
          color: rgba(0,0,0,0.9);
          line-height: 2;
        }
      }
      .dialog-main-line-middle{
        width: 100%;
        display: flex;
        justify-content: center;
        padding: 2.67vw  /* 20/7.5 */ 0;
        h1{
          font-size: 8vw  /* 60/7.5 */;
          line-height: 2;
          color: rgba(0,0,0,1);
          font{
            font-size: 3.73vw  /* 28/7.5 */;
            margin-left: 0.67vw  /* 5/7.5 */;
          }
        }
      }
      .wx-img-box{
        width: 100%;
        display: flex;
        justify-content: space-between;
        .wx-img-l{
          display: flex;
          img{
            width: 5.33vw  /* 40/7.5 */;
            object-fit: contain;
          }
          h1{
            font-size: 3.47vw  /* 26/7.5 */;
            margin-left: 1.33vw  /* 10/7.5 */;
          }
        }
        .wx-img-r{
          width: 4vw  /* 30/7.5 */;
          height: 4vw  /* 30/7.5 */;
          img{
            width: 100%;
          }
        }
      }
    }
</style>