{
    template:'${tmpl}',
    data(){
        return {
          orderNum:"",
          order:{},
          qrcode:"http://gsb-zc.oss-cn-beijing.aliyuncs.com/empty2018082212365411225525855.jpg",
          payOrderNum:"",
          data:{},
        }
    },
    computed: Vuex.mapState({
      count:state=>state.count,
      headStyle:function(){
        return {"background-color":"white"};
      }
    }),
    mounted:function(){
      var orderNum=this.$router.history.current.query.code;
      this.orderNum=orderNum;
      var that=this;
      this.$root.getReq("/web/orderCtl/findOneByOrderNum",{"orderNum":orderNum}).then(function(d){
        that.order=d;
        if(d.orderStatus!="1"){
          that.qrcode="";
          that.payOrderNum="";
          return false;
        }
        /*that.$root.postReq("/web/tradeCtl/createOrderPaid",d).then(dd=>{
          var data=dd.data;
          if(dd==null || data==null){
            console.log("aaaaaa");
          }else if(data.return_code=="notPay"){
            console.log(d);
            that.qrcode=d.payQr;
            that.payOrderNum=d.payOrderNum+"_"+d.payQrCreateTime;
            that.checkPayState();
          }else{
            that.qrcode=data.qrurl;
            that.payOrderNum=data.tradekey+"_"+new Date().getTime();
            that.checkPayState();
          }
        }).catch(e=>{
          console.log(e);
        });*/
      }).catch(function(e){
        console.log(e);
      });
    },
    methods:{
      orderPay(){
          var that=this;
          console.log("!!!!!!!!!!!!!!!!!!");
          this.$root.showMask();
          var userinfo = this.$store.state.currentUser;
          console.log(userinfo);
          console.log(this.order);
          var obj={order:this.order,user:userinfo};
          this.$root.postReq("/web/orderCtl/orderPay",obj).then(d=>{
            var wxpayParam = d.wxpayParam;
            if(d && wxpayParam && wxpayParam.nonceStr){
              wx.chooseWXPay({
                timestamp: wxpayParam.timeStamp,
                nonceStr: wxpayParam.nonceStr,
                package:wxpayParam.package,
                signType: wxpayParam.signType,
                paySign: wxpayParam.paySign,
                success: function (res) {
                  console.log("支付成功");
                  if(res.errMsg=="chooseWXPay:ok"){
                    /*var o={orderNum:that.order.orderNum,payUser:userinfo,out_trade_no:d.out_trade_no,aaa:res};
                    that.$root.postReq("/web/orderCtl/createOrderTrade",o).then(dd=>{
                      console.log(dd);
                      if(dd.order){
                        that.order=dd.order;
                      }
                    });*/
                    that.getPaidOrder({orderNum:that.order.orderNum});
                  }else{
                    console.log("支付失败");
                  }

                },
                complete:function(res){
                  that.$root.hideMask();
                }
              });
            }else{
              that.$root.hideMask();
            }
          })
      },
      getPaidOrder(obj){
        var that=this;
        that.$root.showMask();
        var inth= setInterval(function () {
          that.$root.getReq("/web/orderCtl/getPaidOrder",obj).then(dd=>{
            if(dd && dd.id){
              that.order=dd;
              clearInterval(inth);
              that.$root.hideMask();
            }
          });
        },3000);

      },
      checkPayState(){
        var self=this;
        var userinfo = this.$store.state.currentUser;
        if(this.payOrderNum!=""){
          var ts=this.payOrderNum.split("_");
          var tradeKey=ts[0];
          var startTime=Number(ts[1]);
          console.log(this.payOrderNum);
          setTimeout(function(){
            var inth= setInterval(function () {
              if(self.payOrderNum=="")
              {
                console.log("结束");
                window.clearInterval(inth);
                return;
              }
              self.$root.postReq("/web/tradeCtl/checkOrderPayState",{orderNum:self.order.orderNum,payOrderNum:tradeKey,payUser:userinfo}).then(d=>{
                console.log(d);
                 if(d.order){
                    self.$root.showMask();
                    self.order=d.order;
                    self.payOrderNum="";
                    self.$root.hideMask();
                 }else if(d.result.trade_state=="CLOSED" || d.result.trade_state=="REVOKED" || d.result.trade_state=="PAYERROR"){
                   self.payOrderNum="";
                   clearInterval(inth);
                   self.$message.warning(`支付超时，请刷新页面后重新支付`);
                 }else{
                   var passTime=(new Date().getTime()-startTime)/1000;
                   var p=Math.round((passTime/300)*100);
                   console.log("passed seconds "+passTime);
                   if(passTime>300){
                     self.payOrderNum="";
                     clearInterval(inth);
                     self.$root.postReq("/web/tradeCtl/closeOrder",{idkey:tradeKey}).then(d=>{
                       self.$message.warning(`支付超时，请刷新页面后重新支付`);
                     });
                   }
                 }
              });
            },10000);
          },5000)
        }
      },
      toMobileMain(){
        this.$router.push({path:"/products/mobilemain",query:{from:"mobile"}});
      },
    },

    vname:"gsb-orderpay"
}
