{
    template:'${tmpl}',
    data:function(){
        return {
          form:{
            code:"",
            name:"",
          },
          channeldata:[],
          channelCode:"",
          id:"",
          typedata:[],
          rules:{
            code:[
              {required: true, message:'请输入类别码'}
            ],
            name:[
              {required: true, message:'请输入类别名称'}
            ],
          },
        }
    },
    mounted:function(){
    },
    created:function(){
      var that=this;
      that.$root.postReq("/web/channelCtl/findAllChannel","").then(function(d){
        if(d.code==1){
          that.channeldata=d.data;
          that.channelCode="mryz";
          var obj={channel_code:"mryz"};
          that.$root.postReq("/web/servicetypeCtl/findAllType",obj).then(function(d){
            if(d.code==1){
              that.typedata=d.data;
            }
          });
        }
      });
    },
    methods:{
      channelChange(){
        var that=this;
        var obj={channel_code:this.channelCode};
        that.$root.postReq("/web/servicetypeCtl/findAllType",obj).then(function(d){
          if(d.code==1){
            that.typedata=d.data;
          }
        });
      },
      onColFormater(row,column,cellvalue,index){
        if(column.property=="isEnabled"){
          if(row["isEnabled"]){
            return "是";
          }else{
            return "否";
          }
        }
        return cellvalue;
      },
       toolbarclick(key,b,selectedRows){
         var that=this;
         if(key=="mynew"){
           this.form={
             code:"",
             name:"",
           };
           that.$root.postReq("/web/servicetypeCtl/initNewInstance",obj).then(function(d){
             if(d.status==0){
               that.form.code=d.data.code;
               var obj={channel_code:that.channelCode};
               that.$root.postReq("/web/servicetypeCtl/findAllType",obj).then(function(d){
                 if(d.code==1){
                   that.typedata=d.data;
                 }
               });
             }
           });
           this.$refs.card.changeButtonState();
           this.$refs.grid.showDlgForm();
           return;
         }
       },
       rowClick(row,key,t,e){
         if(key=="myedit"){
           this.form = row;
           this.id= row.pid==0?-1:row.pid;
           this.$refs.card.changeButtonState();
           this.$refs.grid.showDlgForm();
         }
       },
       onDlgFormClick(type,b){
         console.log(type);
         console.log(b);
         if(type=="mysave"){
           this.servicetypeSave();
         }
        },
        servicetypeSave:function(){
          var that=this;
          var tchannelCode=that.channelCode;
          var tid=that.id;
          if(!tchannelCode){
            this.$message.warning(`所属渠道必须选择`);
            return false;
          }
          if(!tid){
            this.$message.warning(`所属分类必须选择`);
            return false;
          }
          this.$refs["form"].validate((valid) => {
            if(valid){
              var obj={pid:tid,channelCode:tchannelCode,code:that.form.code,name:that.form.name};
              this.$root.postReq("/web/servicetypeCtl/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(`保存失败`);
                }
              })
            }
          })

        },
    },

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