
<template>
  <div class="el-classreg_show_pay_mobile_1">
    <div class="classreg_show_reging_mobile_2">
      <div class="class-monery-info">
          <span class="sp1">支付金额(¥)：<i>{{Number(datas.realPrice)}}元</i></span>
      </div>
      <span class="class-monery-tip"><i>*</i>提示：付款前请确认金额无误。</span>
      <ul class="m-ul1">
          <span class="title">选择支付方式</span>
          <!--<li ><img src="../../theme-chalk/src/images/zfb-icon.png" alt=""></li>-->
          <li class="active"><img src="../../theme-chalk/src/images/wepay-icon.png" alt=""></li>
          <!--<li><img src="../../theme-chalk/src/images/yl-icon.png" alt=""></li>-->
      </ul>
      <span class="twn-btns">
          <a href="javascript:void(0)" @click="toPay"  class="a1">确认并支付</a>
          <!--<a href="javascript:void(0)" class="a2">暂不支付</a>-->
      </span>
    </div>
  </div>
</template>

<script>

   import formMixin from "../../../src/mixins/formMixin";
  import lenye_base from "lenye_base";
  import $ from "fy-kit";
  import { Toast } from "vant";
import wx from "weixin-jsapi";
export default {
  name: 'ElClassregShowPayMobile1',
  mixins: [formMixin],
  model: {},
  data(){
    return {
      orderId:'',
      datas:{}
    }
   },
    components: {
    [Toast.name]: Toast,
  },
   created() {



      this.orderId = $.util.urlParams("orderId");
   },
   mounted() {
     this.init();
   },
   computed: {},
   methods: {
     init(){
       //
       $.util.ajax(
          lenye_base.base_data.getapiUrl() +
            "/orderform-service/api2/ordOrderform/queryById.do",
          lenye_base.base_data.getformatting({
            orderId:this.orderId,
          })
        ).then(res=>{
          if(res.success=='1'){
            this.datas = res.data;
          }
        })
     },
       isPay(){
      $.util.ajax(
          lenye_base.base_data.getapiUrl() +
            "/orderform-service/api/ordOrderform/queryOrderStatus.do",
          lenye_base.base_data.getformatting({
            orderId:this.orderId,
          })
        ).then(res=>{
          if(res.success=='1'){
            //Toast.success("支付成功！")
          }
        })
    },
     toPay(){
      $.util.ajax(
          lenye_base.base_data.getapiUrl() +
            "/orderform-service/api/ordOrderform/queryWxpayJsapi.do",
          lenye_base.base_data.getformatting({
            orderId: this.orderId,

          })
        ).then(res=>{
          if(res.success=='1' &&  res.data.status === "0"){
             WeixinJSBridge.invoke(
              "getBrandWCPayRequest",
              {
                appId: res.data.appid,
                paySign: res.data.sign,
                timeStamp: res.data.time_stamp,
                nonceStr: res.data.nonce_str,
                package: "prepay_id=" + res.data.prepay_id,
                signType: "MD5",
              },
               (res)=> {
                if (res.err_msg == "get_brand_wcpay_request:ok") {
                  this.isPay();
                  Toast.success("支付成功")
                  setTimeout(()=>{
                    history.go(-1);
                  },2000);

                } else if (res.err_msg == "get_brand_wcpay_request:cancel") {
                  Toast.fail("已取消支付")
                } else if (res.err_msg == "get_brand_wcpay_request:fail") {
                  Toast.fail("支付失败")
                }
              }
            );
          }else{
            Toast.fail(res.message);
          }
        })
    },
   },
};
</script>

