{
    template:'${tmpl}',
    data:function(){
       var businessLicensePic = (rule, value, callback) => {
         if (this.form.businessLicensePic=="" || this.form.businessLicensePic==null) {
           callback(new Error('请上传营业执照'));
         } else {
           callback();
         }
       };
       var identityCardPic = (rule, value, callback) => {
         if (!this.form.identityCardPic && this.form.applierType=="person") {
           callback(new Error('请上传身份证明'));
         } else {
           callback();
         }
       };
       var codeDocument = (rule, value, callback) => {
         if (!this.form.codeDocument && this.form.copyrightType=='rjzz') {
           callback(new Error('请上传软件源码'));
         } else {
           callback();
         }
       };
       var instructionBookDocument = (rule, value, callback) => {
         if (!this.form.instructionBookDocument && this.form.copyrightType=='rjzz') {
           callback(new Error('请上传说明文档'));
         } else {
           callback();
         }
       };
       var specimenPic = (rule, value, callback) => {
         if (!this.form.specimenPic && this.form.copyrightType!='rjzz') {
           callback(new Error('请上传样本照片'));
         } else {
           callback();
         }
       };
       var registrationDocument = (rule, value, callback) => {
         if (!this.form.registrationDocument) {
           callback(new Error('请上传登记申请表'));
         } else {
           callback();
         }
       };
        return {
          bizCode:"crfreesubmit",
          refbizcode:'',
          action:"",
          d:{},
          showadd:true,
          form:{
            showStatus:false,
            orderNum:"",
            copyrightType:"rjzz",
            compositionType:"",
            statusName:"",
            statusProgress:"",
            applierType:"ent",
            applyName:"",
            mobile:"",
            totalSum:"",
            nclServiceCharge:"",
            nclTotalPublicExpense:"",
            invoiceTaxes:"",
            totalPlatformCost:"",
            identityCardPic :"",
            businessLicensePic:"",
            specimenPic:"",
            registrationDocument:"",
            codeDocument:"",
            instructionBookDocument:"",
            applyDocument:"",
            customerContact:"",
            customerMobile:""
          },
          rules:{
            customerContact:[
              {required: true, message: '请输入联系人'}
            ],
            customerMobile:[
              {required: true, message: '请输入联系电话'}
            ],
            applierType: [
              { required: true, message: '请选择申请人类型' }
            ],
            copyrightType:[
              {required: true, message: '请选择版权类型'}
            ],
            compositionType: [
              {required: true, message: '请选择作品类型' }
            ],
            businessLicensePic:[
              {validator: businessLicensePic,trigger: 'blur'}
            ],
            identityCardPic:[
              { validator: identityCardPic,trigger: 'blur'}
            ],
            codeDocument:[
              { validator: codeDocument,trigger: 'blur'}
            ],
            instructionBookDocument:[
              { validator: instructionBookDocument,trigger: 'blur'}
            ],
            specimenPic:[
              { validator: specimenPic,trigger: 'blur'}
            ],
            registrationDocument:[
              { validator: registrationDocument,trigger: 'blur'}
            ],
            applyName: [
              {required: true, message: '请输入申请人'}
            ],
            mobile:[
              {required: true, message: '请输入申请人电话'}
            ],
          },
          selectCopyRight:[],
          selectOrder:[],
          selectIds:[],
          crstatus:"",
        }
    },
    computed: Vuex.mapState({
      count:state=>state.count,
      headStyle:function(){
        return {"background-color":"white"};
      }
    }),
    created:function(){

    },
    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;
        });
        /*隐藏折叠*/
        var el=this.$refs.refcollapse.$el;
        $(el).hide();
    },
    methods:{
      getDefaultQuery(){
        return {
          "orderSourceType":"2",
          "isHooked":0,
          "itemType":"ic",
          "orderStatus":"4",
        };
      },
      onRefColFormater(row,column,cellvalue,index){
        return cellvalue;
      },
      seltoolbarclick(selectedRows,key){
         console.log("selectedRows..........................");
         console.log(selectedRows);
         this.selectedOrder=selectedRows;
         if(this.selectedOrder && this.selectedOrder.length==1){
            var selorder=this.selectedOrder[0];
            var itemNum=selorder.itemOrderNum;
            if(this.selectCopyRight.length!=itemNum){
              this.$alert('选择关联的版权服务数量必须与订单产品数量'+"相同", '提示', {
                 confirmButtonText: '确定',
                 callback: action => {
                 }
               });
               return;
            }
            /*开始挂接*/
            var oid=selorder.id;
            var cids="";
            var calidarray=[];
            var s = new Set();
            this.selectCopyRight.forEach(c=>{
              calidarray.push(c.id);
            });
            cids=calidarray.join(",");

            var x={
              "oid":oid,
              "cids":cids,
              "orderNum":selorder.orderNum,
            };
            console.log(x);
            this.$root.postReq("/web/copyrightinfoCtl/hookOrder",x).then(d=>{
              if(d.status==0){
                 this.$message({"type":"success","message":'关联订单成功。'});
                 this.$refs.reforderdlg.refreshData();
                 this.$refs.grid.fetchData();
                 this.$refs.reforderdlg.close();
              }else {
                 this.$message.error('关联订单失败！');
                 this.$refs.reforderdlg.close();
              }
            });

         }else{
           if(!this.selectedOrder){
             this.$alert('至少选择一条订单进行关联', '提示', {
                confirmButtonText: '确定',
                callback: action => {

                }
              });
           }else{
             this.$alert('最多选择一条订单进行关联', '提示', {
                confirmButtonText: '确定',
                callback: action => {

                }
              });
           }

         }
      },
      onColFormater(row,column,cellvalue,index){
        if(column.property=="created_at"){
            var date = new Date(row["created_at"]);
            var time= date.toLocaleString();
            return time;
        }
        return cellvalue;
       },
      changeStatus(ids,status){
        var that=this;
        if(!status){
          this.$message.warning(`请选择版权进度`);
          return;
        }
        this.$root.postReq("/web/copyrightinfoCtl/changeStatus",{ids:ids,status:status}).then(function(d){
          if(d.code=="1"){
            that.$message({
              type: 'success',
              message: '状态成功!'
            });
            that.dialogFormVisible = false;
            that.$refs.grid.fetchData();
          }else{
            that.$message.warning(`操作失败，请刷新页面后重新操作`);
          }
        }).catch(function(e){
          that.$message.warning(`操作失败，请刷新页面后重新操作`);
        });
      },
      newtmarch(){
        this.showadd=false;
        this.$refs.refnav.hideback();
        var el=this.$refs.refcollapse.$el;
        $(el).show();
        this.form={
          orderNum:"",
          copyrightType:"rjzz",
          compositionType:"",
          statusName:"",
          statusProgress:"",
          applierType:"ent",
          applyName:"",
          mobile:"",
          totalSum:"",
          nclServiceCharge:"",
          nclTotalPublicExpense:"",
          invoiceTaxes:"",
          totalPlatformCost:"",
          identityCardPic :"",
          businessLicensePic:"",
          specimenPic:"",
          registrationDocument:"",
          codeDocument:"",
          instructionBookDocument:"",
          applyDocument:"",
          customerContact:"",
          customerMobile:""
        };
        this.$refs.card.changeButtonState();
        this.$refs.grid.showDlgForm();
        return;
      },
      toolbarclick(key,b,selectedRows){
        if(key=="editStatus"){
          this.selectIds=[];
          this.crstatus="";
          if(!selectedRows || selectedRows.length<1){
            this.$message.warning(`请选择至少一行记录`);
            return false;
          }else{
            var ids = [];
            for(var i=0;i<selectedRows.length;i++){
              ids.push(selectedRows[i].id);
              if(selectedRows[i].status!="2" ){
                this.$message.warning(`存在未关联订单的版权服务`);
                return false
              }
            }
            this.selectIds=ids;
            this.dialogFormVisible=true;
          }
        }
        if(key=="mynew"){

        }
        if(key=="copy"){
          var that=this;
          if(selectedRows==null || selectedRows.length!=1){
            this.$message.warning(`请选择一行记录`);
            return false;
          }else{
            this.$root.getReq("/web/copyrightinfoCtl/copy",{"id":selectedRows[0].id}).then(function(d){

              that.$refs.grid.hideDlgForm();
              that.$refs.grid.fetchData();
            }).catch(function(e){
              that.$message.warning(`操作失败，请刷新页面后重新操作`);
            });
          }
          return;
        }
        if(key=="myBack"){
          var that=this;

          if(!selectedRows || selectedRows.length<1){
            this.$message.warning(`请选择至少一行记录`);
            return false;
          }else{
            var ids = [];
            for(var i=0;i<selectedRows.length;i++){
              ids.push(selectedRows[i].id);
              if(selectedRows[i].statusProgress!="WAITARTIFICIALEXAMINE" ){
                that.$message.warning(`只能撤销等待人工审核状态的档案`);
                return false
              }
            }
            this.$root.postReq("/web/copyrightinfoCtl/changeStatus",{ids:ids,status:"AWAITCHECK"}).then(function(d){
              if(d.code=="1"){
                that.$message({
                  type: 'success',
                  message: '撤销成功!'
                });
                that.$refs.grid.fetchData();
              }else{
                that.$message.warning(`操作失败，请刷新页面后重新操作`);
              }
            }).catch(function(e){
              that.$message.warning(`操作失败，请刷新页面后重新操作`);
            });
          }
        }
        if(key=="mycheck"){
          var that=this;
          if(!selectedRows || selectedRows.length<1){
            this.$message.warning(`请选择至少一行记录`);
            return false;
          }else{
            var ids = [];
            for(var i=0;i<selectedRows.length;i++){
              ids.push(selectedRows[i].id);
              if(selectedRows[i].status!="2" ){
                that.$message.warning(`审核失败，存在未关联订单的档案`);
                return false
              }
              if(selectedRows[i].statusProgress!="AWAITCHECK" && selectedRows[i].statusProgress!="AUDITFAIL" ){
                that.$message.warning(`只能审核未提交以及审核不通过状态的档案`);
                return false
              }

            }
            this.$root.postReq("/web/copyrightinfoCtl/changeStatus",{ids:ids,status:"WAITARTIFICIALEXAMINE"}).then(function(d){
              if(d.code=="1"){
                that.$message({
                  type: 'success',
                  message: '审核成功!'
                });
                that.$refs.grid.fetchData();
              }else{
                that.$message.warning(`操作失败，请刷新页面后重新操作`);
              }
            }).catch(function(e){
              that.$message.warning(`操作失败，请刷新页面后重新操作`);
            });
          }
        }
        if(key=="hookorder"){
          var that=this;
          if(selectedRows==null || selectedRows.length<1){
            this.$message.warning(`请选择记录`);
            return false;
          }
          console.log(selectedRows);
          var crtype=selectedRows[0].copyrightType;
          var applier=selectedRows[0].applyName;
          for(var i=0;i<selectedRows.length;i++){
            if(selectedRows[i].status!="1"){
              this.$message.warning(`关联失败，请检查档案状态`);
              return false;
            }
            if(selectedRows[i].copyrightType!=crtype){
              this.$message.warning(`关联失败，版权类型必须一致`);
              return false;
            }
            if(selectedRows[i].applyName!=applier){
              this.$message.warning(`关联失败，申请人必须一致`);
              return false;
            }
          }
          this.selectCopyRight=selectedRows;
          this.$refs.reforderdlg.show();

        }

      },
      onDlgFormClick(type,b){
        console.log(type);
        console.log(b);
        if(type=="cancel"){
           /*this.$refs.refnav.showback();*/
           this.showadd=true;
           var el=this.$refs.refcollapse.$el;
           $(el).hide();
           return;
        }
        if(type=="mysave"){
          if(this.form.applierType==""||this.form.copyrightType==""||this.form.applyName==""||this.form.mobile==""||this.form.customerContact==""||
        this.form.customerMobile==""||this.form.registrationDocument==""){
            this.$message.warning(`尚有信息未完善`);
            return;
          }
          if(this.form.copyrightType=="zpzz"){
            if(this.form.compositionType==""||this.form.specimenPic==""){
              this.$message.warning(`尚有信息未完善`);
              return;
            }
          }
          if(this.form.copyrightType=="rjzz"){
            if(this.form.codeDocument==""||this.form.instructionBookDocument==""){
              this.$message.warning(`尚有信息未完善`);
              return;
            }
          }
          if(this.form.applierType!="person"&&this.form.businessLicensePic==""){
            this.$message.warning(`尚有信息未完善`);
            return;
          }
          if(this.form.applierType=="person"&&this.form.identityCardPic==""){
            this.$message.warning(`尚有信息未完善`);
            return;
          }
          this.copyRightSave();
          this.$refs.refnav.showback();
          this.showadd=true;
          var el=this.$refs.refcollapse.$el;
          $(el).hide();
        }
      },
      rowClick(row,key,t,e){
        console.log(key);
        console.log(row);
        if(key=="myedit" || key=="mydetail"){
          this.$refs.refnav.hideback();
          var el=this.$refs.refcollapse.$el;
          $(el).show();
          this.showadd=false;
          this.form = row;
          this.$refs.card.changeButtonState();
          this.$refs.grid.showDlgForm();
        }
        if(key=="doc1"){
          window.open("http://gsb-zc.oss-cn-beijing.aliyuncs.com/ic201811081632%E7%89%88%E6%9D%83%E7%99%BB%E8%AE%B0%E7%94%B3%E8%AF%B7%E8%A1%A8.docx");
        }
      },
      setKey(name,flag){
        console.log(name);
        console.log(flag);
        name=name.substring(name.length-5);
        var myDate = new Date();
        var key = "copyright_"+myDate.getMonth()+myDate.getTime()+myDate.getMilliseconds()+name.split(".")[1];
        console.log(this.$refs[flag]);
        this.$refs[flag].d.key = key;
      },
      error(e){
        console.log(e);
      },
      uploadsuccess(obj){
        var that=this;
        if(obj.flag=="yyzz"){
          that.$root.showMask();
          this.$root.getReq("/web/orderCtl/pic2pdf",{"key":obj.key}).then(function(d){
            if(d.status==0){
              that.form.businessLicensePic=d.data.url;
            }else{
              that.form.businessLicensePic="";
              that.$root.hideMask();
              that.$message.warning(`上传失败请重新上传`);
              return false;
            }
            that.$root.hideMask();
          }).catch(function(e){
            that.form.businessLicensePic="";
            that.$root.hideMask();
            that.$message.warning(`上传失败请重新上传`);
            return false;
          })
        }
        if(obj.flag=="sfz"){
          that.$root.showMask();
          this.$root.getReq("/web/orderCtl/pic2pdf",{"key":obj.key}).then(function(d){

            if(d.status==0){
              that.form.identityCardPic=d.data.url;
            }else{
              that.form.applier.identityCardPic="";
              that.$root.hideMask();
              that.$message.warning(`上传失败请重新上传`);
              return false;
            }
            that.$root.hideMask();
          }).catch(function(e){
            that.form.applier.identityCardPic="";
            that.$root.hideMask();
            that.$message.warning(`上传失败请重新上传`);
            return false;
          })
        }
        if(obj.flag=="rjym"){
          that.form.codeDocument=obj.result;
        }
        if(obj.flag=="smwd"){
          that.form.instructionBookDocument=obj.result;
        }
        if(obj.flag=="ybtp"){
          that.form.specimenPic=obj.result;
        }
        if(obj.flag=="djwd"){
          that.form.registrationDocument=obj.result;
        }

      },
      copyRightSave:function(){
        if(this.form.status=="2"){
          this.$message.warning(`保存失败，该档案已关联订单`);
          return false;
        }
        var that=this;
        this.$refs["form"].validate((valid) => {
          if(valid){
            var obj = this.form;
            console.log(obj);
            console.log("aaaaaaaaaaaaaaaaaaaaaaaa");
            this.$root.postReq("/web/copyrightinfoCtl/createOrEdit",obj).then(function(d){
              console.log(d);
              if(d.code=="1"){
                that.$message({"type":"success","message":'保存成功'});
                that.$root.hideMask();
                that.$refs.grid.hideDlgForm();
                that.$refs.card.changeButtonState();
                that.$refs.grid.fetchData();
              }else{
                that.$message.warning(`保存失败`);
              }

            })
          }
        })
      },
    },

    vname:"gsb-crfreesubmit"
}
