{
  template:'${tmpl}',
  data:function(){
    return {
      dialogTableVisible:false,
      step:"1",
      isRead:false,
      steps:[
        {title:"填写基本信息"},
        {title:"填写申请人信息"},
        {title:"确认订单信息"},
      ],
      form:{
        finishCountry:"中国",
        finishCity:"北京",
        appearCountry:"中国",
        appearCity:"北京",
        opusInditeKind:"yc",
        publishStatus:"1",
        fileUrl:"",
        publishedCityName:"北京",
        obtainMode:"ys",
        rightOwnMode:"grzp",
        rightScope:"1"
      },
      apply:{
        countryName:"中国"
      },
      showtypenum:false,
      order:{},
      qrcode:"",
      qrCodeJumpUrl:"",
      pay:{
        offlinePayDocument:"",
        paymentPlatformType:"wx"
      },
      opusCreateDate:"",
      payconfirm:false,
      d:{},
      cr_type:[
         {
          value: '自然人',
          label: '自然人'
         },{
          value: '企业法人',
          label: '企业法人'
         },{
          value: '机关法人',
          label: '机关法人'
         },{
          value: '事业单位法人',
          label: '事业单位法人'
         },{
          value: '社会团体法人',
          label: '社会团体法人'
         },{
          value: '其他组织',
          label: '其他组织'
         },{
          value: '其他',
          label: '其他'
         },
      ],
      cr_province:[
        {
          value: '北京',
          label: '北京'
         },{
          value: '上海',
          label: '上海'
         },{
          value: '天津',
          label: '天津'
         },{
          value: '内蒙古',
          label: '内蒙古'
         },{
          value: '山西',
          label: '山西'
         },{
          value: '河北',
          label: '河北'
         }
      ],
      
      cr_certificateType:[
        {
          value: '居民身份证',
          label: '居民身份证'
         },{
          value: '军官证',
          label: '军官证'
         },{
          value: '营业执照',
          label: '营业执照'
         },{
          value: '护照',
          label: '护照'
         },{
          value: '企业法人营业执照',
          label: '企业法人营业执照'
         },{
          value: '组织机构代码证书',
          label: '组织机构代码证书'
         },{
          value: '事业单位法人证书',
          label: '事业单位法人证书'
         },{
          value: '社团法人证书',
          label: '社团法人证书'
         },{
          value: '其他有效证件',
          label: '其他有效证件'
         }
      ],
      cr_sign_info:[{
        value: '本名',
        label: '本名'
      },{
        value: '别名',
        label: '别名'
      },{
        value: '署名',
        label: '署名'
      }],
      cr_entType:[{
        value: '国有企业',
        label: '国有企业'
      },{
        value: '集体企业',
        label: '集体企业'
      },{
        value: '私营企业',
        label: '私营企业'
      },{
        value: '港澳台商投资企业',
        label: '港澳台商投资企业'
      },{
        value: '外商投资企业',
        label: '外商投资企业'
      },{
        value: '股份有限公司',
        label: '股份有限公司'
      }
      ],
      tradeKey:"",
      interval:null,
      action:"",
      descTypeName:"原创",
      isPublish:"已发表",
      rangeType:"1",
      rules: {
        name: [
          {required: true, message: '请输入作品名称'}
        ],
        compositionType: [
          {required: true, message: '请输入作品著作权分类名称' }
        ],
        compositionTypeDesc:[
          { required: true, message: '请输入作品著作权分类说明' }
        ],
        opusDesc:[
          { required: true, message: '请输入作品创作性质说明' }
        ],
        opusCreateDate: [
          {required: true, message: '请选择作品创作完成日期'}
        ],
        finishCountry: [
          {required: true, message: '请选择创作完成国家'}
        ],
        finishCity: [
          {required: true, message: '请选择创作完成城市'}
        ],
        appearDate: [
          {required: true, message: '请选择首次发表日期'}
        ],
        appearCountry: [
          {required: true, message: '请选择首次发表国家'}
        ],
        appearCity: [
          {required: true, message: '请选择首次发表城市'}
        ],
        ownPartDesc: [
          {required: true, message: '请输入权利归属方式说明'}
        ],
        emedium: [
          {required: true, message: '请输入电子介质'}
        ],
        ecount: [
          {required: true, message: '请输入件数'}
        ],
        pmedium: [
          {required: true, message: '请输入纸介质'}
        ],
        pcount: [
          {required: true, message: '请输入张数'}
        ],
      },
      rules2: {
        type: [
          {required: true, message: '请输入类别'}
        ],
        name: [
          {required: true, message: '请输入名称' }
        ],
        countryName:[
          { required: true, message: '请输入国籍' }
        ],
        applyProvince: [
          {required: true, message: '请输入省份' }
        ],
        applyCity: [
          {required: true, message: '请输入城市'}
        ],
        certificateType: [
          {required: true, message: '请输入证件类型'}
        ],
        certificateCode: [
          {required: true, message: '请输入证件号码'}
        ],
        entType: [
          {required: true, message: '请输入企业类别'}
        ],
        authorName: [
          {required: true, message: '请输入作者'}
        ],
        authorSign: [
          {required: true, message: '请输入作者署名'}
        ],
        sign_info: [
          {required: true, message: '请输入署名情况'}
        ],
        customerContact: [
          {required: true, message: '请输入联系人'}
        ],
        mobile: [
          {required: true, message: '请输入联系电话'}
        ],
      },
      tradeKey:"",
      interval:null,
    }
  },
  mounted:function(){
    var that = this;
    var that = this;
    var orderNum = this.$store.state.queryParam;
    console.log("orderNumorderNumorderNumorderNum");
    console.log(orderNum);
    this.orderNum = orderNum;
    if (!orderNum) {
      this.$message.warning(`订单参数错误`);
      this.$router.push("/autosubmitorder");
      return;
    }
    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;
  });
  this.getOrderDetail();
  },
  created:function(){

  },
  methods:{
    getOrderDetail: function() {
      var orderNum = this.orderNum;
      var that = this;
      this.$root.getReq("/web/orderCtl/getWorksOrderDetailByOrderNum", { orderNum: orderNum }).then(function (d) {
        console.log("/web/orderCtl/getWorksOrderDetailByOrderNum.............>s");
        console.log(d);
        if (d && d.code == "1") {
          that.form = d.data.copyright;
          that.apply = d.data.apply;
          that.order = d.data.order;
          that.form.remark = d.data.order.remark;
        }
      });
    },
    chooseTypeNum:function(){
      this.showtypenum=true;
    },
    closetn:function(){
      this.showtypenum=false;
    },
    submittn:function(){
      this.showtypenum=false;
      this.form.typeNum=this.typenum1+"-"+this.typenum2;
    },
    tobefore(){
      this.step=Number(this.step)-1;
      this.step=this.step.toString();
    },
    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;
    },
    uploadsuccess(obj){
      console.log("this.form.fileUrl");
      console.log(obj.result);
      this.form.fileUrl=obj.result;
      console.log(this.form.fileUrl);
    },
    error(err){
      this.$message.warning(`上传失败，请重新上传`);
      console.log(err);
    },
    uploadsuccess2(result,obj){
      console.log(result);
      console.log(12345678765432);
      console.log(obj);
      if(obj.flag=="zfpz"){
        this.pay.offlinePayDocument=result;
      }
    },
    submitForm(formName) {
      var that=this;
      if(formName=="form" || formName=="apply"){
        this.$refs[formName].validate((valid) => {
          if (valid) {
            var date1 = new Date(that.form.opusCreateDate);
            var date2 = new Date(that.form.appearDate);
            that.opusCreateDate= date1.toLocaleString().split(" ")[0];
            that.appearDate= date2.toLocaleString().split(" ")[0];
            that.step=Number(that.step)+1;
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      }
      if (formName == "save") {
        this.$root.showMask();
        if (this.order.orderStatus == "2") {
          this.$message.warning("该订单已取消，无法修改");
          this.getOrderDetail();
          that.$root.hideMask();
          return
        }
        console.log(this.form);
        var tm = { orderNum: this.order.orderNum, reqtype: "2" };
        var tmpApply = this.apply;
        tmpApply.orderNum = this.order.orderNum;
        tmpApply.remark = this.form.remark;
        var customer = {
          orderNum: this.order.orderNum, customerContact: this.apply.customerContact, mobile: this.apply.mobile
        };
        var obj = { tm: tm, apply: tmpApply, customer: customer, copyright: this.form };
        console.log(obj);
        that.$root.postReq("/web/orderCtl/updateOrderDetailByOrderNum", obj).then(function (d) {
          if (d.code == "1") {
            that.$message.success(`修改成功`);
            that.getOrderDetail();
          } else if (d.code = "-100" && d.msg) {
            console.log(d.msg);
            that.$message.warning(d.msg);
            that.getOrderDetail();
          } else {
            that.$message.warning("操作失败");
          }
          that.$root.hideMask();
        }).catch(function (e) {
          that.$root.hideMask();
        });
      }
  },
    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:0.01,desc:"订单支付",orderNum:this.order.orderNum}).then(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;
      this.showtypenum=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.$router.push("/autosubmitorder");
                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.$router.push("/autosubmitorder");
      });
    }
  },
  computed:{
    headStyle:function(){
      return {"background-color":"white"};
    }
  },
  vname:"gsb-worksorderdetail"
}
