{
    template:'${tmpl}',
    data:function(){
      var that=this;
      var validateMethod=function(rule, value, callback){
    
         if(rule.field=="mobile"){
           if(/^1[23456789]\d{9}$/.test(value) == false){
              return  callback(new Error("请输入正确格式的手机号"));
           }else{
              return  callback();
           }
         }
         return callback();
       };
        return {
          loading:false,
          loading1:false,
          loading2:false,
          loading3:false,
          loadingKey: 0,
          sumparams:["totalSum","nclOneCodesNum"],
          multipleSelection: [],
          isSingleSelect:false,
          bizCode:"",
          centerDialogVisible:false,
          activeIndex:"1",
          totalSum:0,
          sfs:[
            {field:'totalSum',label:'订单金额'},
          ],
          form1:{
            title:"",
            taxNum:"",
            email:"",
          },
          form2:{
            title:"",
            taxNum:"",
            companyAddress:"",
            companyMobile:"",
            companyBank:"",
            bankNum:"",
            picUrl:"",
            recipient:"",
            mobile:"",
            city:"",
            address:"",
          },
          rules1:{
            title:[
              { required: true, message: '请输入发票抬头', trigger: 'blur' },
            ],
            taxNum:[
              { required: true, message: '请输入纳税号', trigger: 'blur' },
            ],
            email:[
              { required: true, message: '请输入发票接收邮箱', trigger: 'blur' },
              { type: 'email', message: '请输入正确的邮箱地址', trigger: ['blur', 'change'] }
            ]
          },
          rules2:{
            title:[
              { required: true, message: '请输入发票抬头', trigger: 'blur' },
            ],
            taxNum:[
              { required: true, message: '请输入纳税号', trigger: 'blur' },
            ],
            companyAddress:[
              { required: true, message: '请输入备案地址', trigger: 'blur' },
            ],
            companyMobile:[
              { required: true, message: '请输入备案电话', trigger: 'blur' },
            ],
            companyBank:[
              { required: true, message: '请输入开户银行', trigger: 'blur' },
            ],
            bankNum:[
              { required: true, message: '请输入银行账户', trigger: 'blur' },
            ],
            fileUrl:[
              { required: true, message: '请上传纳税资格证明', trigger: 'blur' },
            ],
            recipient:[
              { required: true, message: '请输入收件人', trigger: 'blur' },
            ],
            mobile:[
              { required: true, message: '请输入手机号', trigger: 'blur' },
              { validator: validateMethod, trigger: 'blur' },
            ],
            address:[
              { required: true, message: '请输入详细地址', trigger: 'blur' },
            ],
          },
          d:{},
          action:"",
          addressInfo:[],
          index:0,
          orderId:"",
          stuff:{},
          showUploadStuff:false,
        }
    },
    mounted:function(){
      var that=this;
      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;
      });

    },
    created:function(){
   
      if(this.codePath.split("/").indexOf("myordermag")>=0){
        this.bizCode="myordermag";
      }else if(this.codePath.split("/").indexOf("myorder")>=0){
        this.bizCode="myorder";
      }else{
        this.bizCode="order";
      }
    },
    methods:{
      error(err){
        this.$message.warning(`上传失败，请重新上传`);
        console.log(err);
      },
      uploadsuccess(obj){
        var that=this;
        if (this.loadingKey == 1) {
          that.loading1 = true;
        }else if (this.loadingKey == 2) {
          that.loading2 = true;
        }else if (this.loadingKey == 3) {
          that.loading3 = true;
        }else if (this.loadingKey == 0){
          that.loading = true;
        }

        if(obj.flag=="yyzz"){
          this.$root.getReq("/web/toolCtl/pic2pdf",{"key":obj.key}).then(function(d){
            that.loading1 = false;
            that.loading2 = false;
            that.loading3 = false;
            that.loading = false;
            if(d.status==0){
              that.stuff.businessLicensePic=d.data.url;
            }else{
              that.stuff.businessLicensePic="";
              
              that.$message.warning(`上传失败请重新上传`);
              return false;
            }
          }).catch(function(e){
            that.stuff.businessLicensePic="";
            that.loading1 = false;
            that.loading2 = false;
            that.loading3 = false;
            that.loading = false;
            that.$message.warning(`上传失败请重新上传`);
            return false;
          })
        }
        if(obj.flag=="sfz"){
          
          this.$root.getReq("/web/toolCtl/pic2pdf",{"key":obj.key}).then(function(d){
            that.loading1 = false;
            that.loading2 = false;
            that.loading3 = false;
            that.loading = false;
            if(d.status==0){
              that.stuff.identityCardPic=d.data.url;
            }else{
              that.stuff.identityCardPic="";
              that.$message.warning(`上传失败请重新上传`);
              return false;
            }
          }).catch(function(e){
            that.stuff.identityCardPic="";
            that.loading1 = false;
            that.loading2 = false;
            that.loading3 = false;
            that.loading = false;
            that.$message.warning(`上传失败请重新上传`);
            return false;
          })
        }
        if(obj.flag=="wts"){
          this.$root.getReq("/web/toolCtl/adjustWTSSize",{"key":obj.key}).then(function(d){
            that.loading1 = false;
            that.loading2 = false;
            that.loading3 = false;
            that.loading = false;
            if(d.status==0){
              that.stuff.sealAuthorizeStuff=d.data.url;
              console.log(d.data.url);
            }else{
              that.$refs[obj.flag][0].result="";
              
              that.$message.warning(`上传失败请重新上传`);
              return false;
            }

          }).catch(function(){
            that.$refs[obj.flag][0].result="";
            that.loading1 = false;
            that.loading2 = false;
            that.loading3 = false;
            that.loading = false;
            that.$message.warning(`上传失败请重新上传`);
            return false;
          });
        }
        if(obj.flag=="yxq"){
          that.loading1 = false;
          that.loading2 = false;
          that.loading3 = false;
          that.loading = false;
          that.stuff.descUrl=obj.result
        }
      },
      setKey(name,flag){
   
        name=name.substring(name.length-5);
        var myDate = new Date();
        var key = "zc_"+flag+Math.round(Math.random()*10000)+myDate.getTime()+myDate.getFullYear()+myDate.getMonth()+myDate.getDate()+".jpg";
       
        this.$refs[flag].d.key = key;
      },
      btnvisbleMethod(row,btn){
        if(btn.key=="invoiceapply"){
          if(row.orderPayStatus=="yfk"&&row.invoiceApplyStatus=="1"&&row.isIinvoice==1){
            return true;
          }else{
            return false;
          }
        }
        if(btn.key=="mydetail"){
          if(row.sveItemCode=="zzsbzc"||row.sveItemCode=="dlrfzzc" || row.sveItemCode=="dbsbzc"){
            return true;
          }else{
            return false;
          }
        }
        if(btn.key=="myicpdetail"){
          if(row.sveItemCode=="CP201910231025EaQM0b"){
            return true;
          }else{
            return false;
          }
        }
        if(btn.key=="myedit"){
          if(row.orderPayStatus=="ddqx" || row.orderPayStatus=="tkclz" || row.orderPayStatus=="ytk"){
            return false;
          }else if(row.sveItemCode=="dlrfzzc"&&(row.orderStatus=="1" || row.orderStatus=="2" || row.orderStatus=="3" || row.orderStatus=="4" || row.orderStatus=="6")){
            return true;
          }else if(row.sveItemCode=="zzsbzc"&& (row.orderStatus=="1" || row.orderStatus=="2" || row.orderStatus=="3" || row.orderStatus=="4" || row.orderStatus=="6")){
            return true;
          }else if(row.sveItemCode=="dbsbzc"&& (row.orderStatus=="1" || row.orderStatus=="2" || row.orderStatus=="3" || row.orderStatus=="4" || row.orderStatus=="6")){
            return true;
          }else{
            return false;
          }
        }
        if(btn.key=="ptsjedit"){
          if(row.orderSource=="ptsj" && row.orderPayStatus=="dfk" && this.currentUser && row.createuser_id==this.currentUser.id){
            return true;
          }else{
            return false;
          }
        }
        if(btn.key=="topay"){
          if(row.orderPayStatus=="dfk"){
            return true;
          }else{
            return false;
          }
        }
        if(btn.key=="cancelorder"){
          if((row.sveItemCode=="dlrfzzc" || row.sveItemCode=="zzsbzc" || row.sveItemCode=="dbsbzc") &&row.orderPayStatus=="dfk"){
            return true;
          }else{
            return false;
          }
        }
       
        if(btn.key=="uploadstuff"){
          if(row.orderPayStatus=="ddqx" || row.orderPayStatus=="tkclz" || row.orderPayStatus=="ytk"){
            return false;
          }else if((row.sveItemCode=="dlrfzzc" || row.sveItemCode=="zzsbzc"|| row.sveItemCode=="dbsbzc") && (row.orderStatus=="1" || row.orderStatus=="2" || row.orderStatus=="3" || row.orderStatus=="4" || row.orderStatus=="6")){
            return true;
          }else{
            return false;
          }
        }
        if(btn.key=="mydelete"){
          if(row.orderPayStatus=="dfk" && row.createuser_id==this.currentUser.id){
            return true;
          }else{
            return false;
          }
        }
        return true;
      },
      onColFormater(row,column,cellvalue,index){
          if(column.property=="created_at"){
            var date = new Date(row["created_at"]);
            var time= date.toLocaleDateString();
       
            return time;
          }
          if(column.property=="customerinfo.name"){
            if(!row.customerinfo){
              return "---";
            }else{
               return row.customerinfo.name;
            }
          }
          if(column.property=="name"){
            if(!row["name"]){
              return "---";
            }else{
              return row.name;
            }
          }
          if(column.property=="nclOneCodesNum"){
            if(!row["nclOneCodesNum"]){
              return "---";
            }else{
              return row.nclOneCodesNum;
            }
          }
          return cellvalue;
        },
      handleSelectionChange:function(val){
         this.multipleSelection = val;
        
       },
      hideUploadStuff(){
        this.stuff={};
        this.showUploadStuff=false;
      },
      uploadStuffs(){
        var obj = this.stuff;
        var that=this;
        this.$root.postReq("/web/orderCtl/uploadStuffs",obj).then(function(d){
         
          if(d && d.code==1){
            that.hideUploadStuff();
            that.$refs.grid.fetchData();
          }else{
            that.$message.warning(d.msg);
          }
        })
      },
      onRowClick(row,key,e){
        if(key=="uploadstuff"){
          if((row.sveItemCode=="dlrfzzc" || row.sveItemCode=="zzsbzc" || row.sveItemCode=="dbsbzc") && (row.orderStatus=="1" || row.orderStatus=="2" || row.orderStatus=="3" || row.orderStatus=="4" || row.orderStatus=="6" )){
       
            var obj={orderNum:row.code};
            var that = this;
            this.$root.getReq("/web/orderCtl/getTmOrderDetail",obj).then(function(d){
              if(d && d.code==1){
                var data = d.data;
                var stuff={};
                var tm_stuffs = data.tmstuffs;
                var order = data.order;
                var customer = data.customerinfo;
                stuff["code"]= order.code;
                stuff["customerType"]= customer.customerType;
                stuff["businessLicensePic"]= customer.businessLicensePic || "";
                stuff["identityCardPic"]= customer.identityCardPic || "";
                stuff["sealAuthorizeStuff"]= "";
                stuff["descUrl"]= "";
                for(var i=0;i<tm_stuffs.length;i++){
                  if(tm_stuffs[i].stuffType=="gzwts"){
                    stuff["sealAuthorizeStuff"]= tm_stuffs[i].stuffUrl || "";
                  }
                  if(tm_stuffs[i].stuffType=="smwj"){
                    stuff["descUrl"]= tm_stuffs[i].stuffUrl || "";
                  }
                }
                that.stuff=stuff;
                that.showUploadStuff=true;
              }
            })
          }
        }
        if(key=="cancelorder"){
          if((row.sveItemCode=="dlrfzzc" || row.sveItemCode=="zzsbzc") &&row.orderPayStatus=="dfk"){
          
            var that=this;
            this.$root.postReq("/web/orderCtl/cancelOrderByCode",{code:row.code}).then(function(d){
              if(d && d.code==1){
                that.$message.success("订单取消成功");
                that.$refs.grid.fetchData();
              }else{
                that.$message.warning(d.msg);
              }
            });
          }
        }
        if(key=="myedit"){
          if(row.orderPayStatus=="ddqx" || row.orderPayStatus=="tkclz" || row.orderPayStatus=="ytk"){
            return 
          }
          if(row.sveItemType=="ip" && (row.orderStatus=="1" || row.orderStatus=="2" || row.orderStatus=="3" || row.orderStatus=="4" || row.orderStatus=="6")){
            this.$root.pushx({
              title:"订单修改",
              name:"/tmOrderEdit",
              params:{
                orderNum:row.code
              }
            });
          }
        }
        if(key=="ptsjedit"){
          if(row.orderSource!="ptsj" || row.orderPayStatus!="dfk" || !this.currentUser || row.createuser_id!=this.currentUser.id){
            return
          }
          this.$root.pushx({
            title:"订单修改",
            name:"/businesstmorder",
            params:{
              orderCode:row.code,sve_item_code:row.sveItemCode,key:"edit"
            }
          });
        }
        if(key=="mydetail"){
          if(row.sveItemType=="ip"){
            this.$root.pushx({
              title:"订单详情",
              name:"/tmOrderDetail",
              params:{
                orderNum:row.code
              }
            });
          }
        }
        if(key=="myicpdetail"){
          this.$root.pushx({
            title:"订单详情",
            name:"/icpOrderDetail",
            params:{
              orderNum:row.code,
              from:this.bizCode
            }
          });
        }
        if(key=="mydelete"){
          var that=this;
          if(row.orderPayStatus!="dfk"){
            this.$message({
              type: 'warning',
              message: '只能删除未付款订单'
            });
           return;
          }else{
            if(row.orderSource=="ptsj"){
              this.$confirm('此操作将删除当前记录, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
              }).then(() => {
                var obj={orderNum:row.code};
                that.$root.postReq("/web/orderCtl/deletePtsjOrder",obj).then(function(d){
                  console.log("dssssssssssssssssss");
                  console.log(d);
                  if(d && d.code==1){
                    that.$message({
                      type: 'success',
                      message: '删除成功!'
                    });
                    that.$refs.grid.fetchData();
                  }else{
                    that.$message.warning(d.msg);
                  }
                }).catch(function(e){
                  console.log(e);
                  that.$message.warning("操作失败");
                })
              })
              
            }else{
              this.$refs.grid.rowClick(row,"delete","",e);
            }
          }

        }
        if(key=="invoiceapply"){
        
          this.centerDialogVisible=true;
          this.orderId=row.id;
          this.totalSum=row.totalSum;
          if(row.customerinfo){
            this.form1.title=row.customerinfo.name;
            this.form1.taxNum=row.customerinfo.code;
            this.form2.title=row.customerinfo.name;
            this.form2.taxNum=row.customerinfo.code;
          }
          
          this.fetchAllAddress();
        }
        if(key=="topay"){
         
          if(row.orderPayStatus=="dfk"){
           
            this.$root.pushx({
              title:"订单支付",
              name:"/orderpay",
              params:{
                orderNum:row.code
              }
            });
          }

        }
       },
      fetchAllAddress(){
        var that=this;
        var obj={};
        that.$root.postReq("/web/useraddrCtl/fetchAllAddress",obj).then(function(d){
     
          if(d.status==0&&d.data.length>0){
            that.addressInfo=d.data;
            that.index=0;
            that.form2.recipient=d.data[0].name;
            that.form2.mobile=d.data[0].mobile;
            that.form2.address=d.data[0].address;
          }
        })
      },
      changeAddress(){
        var num=this.addressInfo.length-1;
        if(this.index==num){
          this.index=0;
        }else{
          this.index=this.index+1;
        }
       
        this.form2.recipient=this.addressInfo[this.index].name;
        this.form2.mobile=this.addressInfo[this.index].mobile;
        this.form2.address=this.addressInfo[this.index].address;
        
      },
      handleSelect(key, keyPath) {
    
       this.activeIndex=key;
     },
      submitInvoiceApply(){
        var that=this;
        this.$refs.form1.validate((valid) => {
          if (valid) {
            var obj={
              order_id:that.orderId,
              invoiceType:"1",
              invoiceHeadUp:that.form1.title,
              taxpayerID:that.form1.taxNum,
              email:that.form1.email
            };
            that.$root.postReq("/web/invoiceapplyCtl/submitInvoice",obj).then(function(d){
              if(d.status==0){
                that.centerDialogVisible=false;
                that.$message({
                    type: 'success',
                    message: '发票申请成功'
                  });
                that.$refs.grid.fetchData();
              }
            })
          }
        })
      },
      submitInvoiceApply2(){
        var that=this;
        this.$refs.form2.validate((valid) => {
          if (valid) {
            var obj={
              order_id:that.orderId,
              invoiceType:"3",
              invoiceHeadUp:that.form2.title,
              taxpayerID:that.form2.taxNum,
              applyAddr:that.form2.companyAddress,
              applytelephone:that.form2.companyMobile,
              bankName:that.form2.companyBank,
              bankNum:that.form2.bankNum,
              taxesCertifyUrl:that.form2.fileUrl,
              recipients:that.form2.recipient,
              mobile:that.form2.mobile,
              address:that.form2.address
            };
            that.$root.postReq("/web/invoiceapplyCtl/submitInvoice",obj).then(function(d){
           
              if(d.status==0){
                that.centerDialogVisible=false;
                that.$message({
                    type: 'success',
                    message: '发票申请成功'
                  });
                  that.$refs.grid.fetchData();
              }
            })
          }
        })
      },
      uploadsuccess2(result,obj){
      
        if(obj.flag=="zfpz"){
          this.form2.fileUrl=result;
        }
      },
      error(err){
        this.$message.warning(`上传失败，请重新上传`);
        console.log(err);
      },
      setKey(name,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(" ","");
       
        this.$refs[flag].d.key = key;
      },

    },
    computed: Vuex.mapState({
      count:state=>state.count,
      headStyle:function(){
        return {"background-color":"white"};
      }
    }),
    vname:"gsb_order"
}
