{
    template:'${tmpl}',
    data:function(){
        return {
          d:{},
          action:"",
          order:{},
          orderNum:"",
          pay:{
            offlinePayDocument:"",
            paymentPlatformType:"wx"
          },
          payconfirm:false,
          tradeKey:"",
          interval:null,
          qrcode:"",
        }
    },
    computed: Vuex.mapState({
      count:state=>state.count,
      headStyle:function(){
        return {"background-color":"white"};
      }
    }),
    created:function(){

    },
    mounted:function(){
        var that=this;
        this.orderNum = this.$store.state.queryParam;
        this.getorder();
        this.$root.postReq("/web/uploadCtl/getOssConfig","").then(function(d){
          that.d["key"]="key";
          that.d["Bucket"]=d.Bucket;
          that.d["OSSAccessKeyId"]=d.OSSAccessKeyId;
          that.d["Signature"]=d.Signature;
          that.d["policy"]=d.policy;
          that.d["success_action_status"]=d.success_action_status;
          that.action=d.url;
      });

    },
    methods:{
      getorder(){
        var that=this;
        var orderNum=this.orderNum;
        if(orderNum){
          this.$root.getReq("/web/orderCtl/findOneByOrderNum",{orderNum:this.orderNum}).then(function(d){
              console.log("dddw");
              console.log(d);
              if(d && d.orderNum){
                that.order=d;
              }
          });
        }else{
          this.$router.push("/autosubmitorder");
        }
      },
      orderdetail:function(){
        if(this.order && this.order.orderNum){
          this.$store.state.queryParam=this.order.orderNum;
          this.$router.push("/autosubmitorderdetail");
        }

      },
      again:function(){
        this.$router.push("/automaticsubmit");
      },
      setKey(name,flag){
        console.log(name);
        console.log(flag);
        name=name.substring(name.length-5);
        var myDate = new Date();
        var key = "zc_"+Math.round(Math.random()*500)+myDate.getMonth()+myDate.getTime()+myDate.getFullYear()+myDate.getDate()+myDate.getHours()+myDate.getMinutes()+myDate.getSeconds()+myDate.getMilliseconds()+name.replace(" ","");
        console.log(this.$refs[flag]);
        this.$refs[flag].d.key = key;
      },
      uploadsuccess2(result,obj){
        console.log(result);
        console.log(12345678765432);
        console.log(obj);
        if(obj.flag=="zfpz"){
          this.pay.offlinePayDocument=result;
        }
      },
      error(err){
        this.$message.warning(`上传失败，请重新上传`);
        console.log(err);
      },
      wxPay:function(){
        if(this.pay.paymentPlatformType=="offline"){
          this.payconfirm=true;
          return;
        }
        var amount = Number(this.order.totalSum);
        if(this.order.totalSum){
          this.payconfirm=true;
          if(!this.order.orderNum){
            return;
          }
          this.$root.postReq("/web/tradeCtl/createUnifiedOrder2",{amount:amount,desc:"订单支付",orderNum:this.order.orderNum}).then(d=>{
            console.log("createUnifiedOrder");
            console.log(d);
            if(d.data){
              var o={id:this.order.id,payQr:d.data.qrurl,payQrCreateTime:new Date().getTime(),payOrderNum:d.data.tradekey};
              this.$root.getReq("/web/orderCtl/orderUpdate",o).then(dd=>{
                console.log("dd");
                console.log(dd);
                if(dd.code=='1'){
                  this.qrcode=d.data.qrurl;
                  this.tradekey=d.data.tradekey+"_"+new Date().getTime();
                  this.checkPayState();
                }
              });

            }else{
              this.$message.warning(`获取微信支付码失败`);
            }
          });
        }

      },
      closePayConfirm(){
        this.payconfirm=false;
        var self = this;
        if(this.tradekey){
          var ts=this.tradekey.split("_");
          var tradeKey=ts[0];
          self.tradeKey="";
          window.clearInterval(self.interval);
        }
      },
      checkPayState(){
        console.log("==================================================");
        var self=this;
        var userinfo = this.$store.state.currentUser;
        if(this.tradekey!=""){
          var ts=this.tradekey.split("_");
          var tradeKey=ts[0];
          var startTime=Number(ts[1]);
          setTimeout(function(){
            var inth= setInterval(function () {

              if(self.tradekey=="")
              {
                console.log("结束");
                window.clearInterval(inth);
                return;
              }
              console.log(self.order.orderNum);
              self.$root.getReq("/web/orderCtl/findOneByOrderNum",{orderNum:self.order.orderNum}).then(d=>{
                console.log("findOneByOrderNum");
                console.log(d);
                if(d && d.orderStatus=="4"){
                  self.order=d;
                  self.payOrderNum="";
                  self.tradekey="";
                  window.clearInterval(inth);
                  self.getorder();
                  return;
                }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.wxPay();
                    });
                  }
                }
              });
            },10000);
            self.interval = inth;
          },5000)
        }
      },
      orderUpdate(){
        if(!this.order.id){
          return
        }
        var self =this;
        var obj =this.pay;
        console.log("this.order");
        console.log(this.order.id);
        obj["id"]=this.order.id;
        obj["orderStatus"]="64";
        console.log(obj);
        this.$root.getReq("/web/orderCtl/orderUpdate",obj).then(d=>{
          console.log("d");
          console.log(d);
          self.getorder();
        });
      }
    },
    vname:"gsb-autosubmitpay"
}
