<template>
  <div>
    <el-form ref="form" :rules="rules"  :model="form" label-width="120px">
      <el-form-item
          label="分类名称："
          prop="name"
      >
        <el-input v-model="form.name"  maxlength="50" placeholder="请输入分类名称"></el-input>
      </el-form-item>
      <el-form-item
          label="父级名称："
          prop="pid"
      >
      <el-cascader
      v-model="form.pid"
      :options="Categorylist"
      :props="{
                checkStrictly: true,
                value:'id',
                label:'name',
                children:'children',
              }" 
      clearable></el-cascader>
    </el-form-item>

      <el-form-item label="排序：" prop="sort">
        <el-input v-model.number="form.sort"  placeholder="输入排序" ></el-input>
      </el-form-item>
      <el-form-item label="seo-标题：" prop="seo_title">
        <el-input v-model="form.seo_title" maxlength="50" placeholder="输入标题" ></el-input>
      </el-form-item>
      <el-form-item label="seo-关键字：" prop="seo_keywords">
        <el-input  type="textarea" v-model="form.seo_keywords"  maxlength="30"
        show-word-limit  placeholder="输入关键字" ></el-input>
      </el-form-item>
      <el-form-item label="seo-描述：" prop="seo_description">
        <el-input  type="textarea" v-model="form.seo_description" maxlength="80"
        show-word-limit  placeholder="输入描述" ></el-input>
      </el-form-item>
      <el-form-item>
        <div style="text-align: center">
          <el-button type="primary" @click="onSubmit" :disabled="Isdisabled" :loading="isloading">保存</el-button>
          <el-button style="color: #5075FC " @click="closeDlg">取消</el-button>
        </div>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
export default {
  props: {
    CategoryDataForm: {
      type: Object,
      default: () => {}
    },
    isloading:{
      type:Boolean,
      default: true
    },
    closeDlg:{
      type:Function
    }
  },
  data() {
    return {
      form: {
        name: '',
        pid:"",
        icon:"",
        sort:"",
        is_links:"",
        hidden:"",
        pid:[0]
      },
      Categorylist: [],
      Isdisabled: false,
      rules: {
        label: [
          { required: true, message: '分类名称必填' },
        ],
        sort: [
          { pattern: /^[0-9]\d*$/, message: '排序值格式错误' },
        ]
      }
    }
  },
  mounted() {
    if(this.CategoryDataForm) {
      this.form = Object.assign({} , this.CategoryDataForm)
    }
    this.getRecursionCategory()
  },
  methods: {
    closeDlg() {
      console.log("edit提交")
      this.$emit('closeDlg',1)
    },
    onSubmit() {
      let that = this
      that.$refs['form'].validate((valid) => {
        if (valid) {
          this.$emit('CategorySubmitClick', this.form)
        }
      })
    },
    getRecursionCategory(){
      let _t= this
      let parames = {}
      this.$api.news.categoryList(parames).then(res=>{
                if(res.code==200){
          
                  _t.Categorylist = res.data
                }else{
                    this.$message.error("查询失败")
                }
            })
    },
    
  }
}
</script>
<style>
.el-cascader-node>.el-radio{
  margin-top:25px;
}
</style>
