<template>
  <!-- 添加或修改网站栏目对话框 -->
  <div class="app-container">
    <el-form ref="form" :model="form" :rules="rules" label-width="100px">
      <el-row :gutter="20">
        <el-col :span="6">
          <el-form-item label="栏目编号" prop="code">
            <el-input v-model="form.code" placeholder="请输入栏目编号" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="栏目名称" prop="catgName">
            <el-input v-model="form.catgName" placeholder="请输入栏目名称" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="栏目类型" prop="catgType">
            <el-select v-model="form.catgType" placeholder="请选择通告栏目类型" >
              <el-option
                v-for="dict in dict.type.category_type"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="排序" prop="sort">
            <el-input v-model="form.sort" placeholder="请输入排序" />
          </el-form-item>
        </el-col>
      </el-row>



    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="cancel">取 消</el-button>
    </div>
  </div>
</template>

<script>
import {addCategory} from "@/api/busi/category";
export default {
  name: "categoryForm",
  dicts: ['category_type'],
  data(){
    return{
      //弹出层标题
      title:"",
      //表单参数
      form:{
        code:"",
        catgName:"",
        catgType:"",
      },
      //列表页入参
      query:{},
      //表单校验规则
      rules:{
        code: [
          { required: true, trigger: "blur", message: "请输入栏目编号" }
        ],
        catgName: [
          { required: true, trigger: "blur", message: "请输入栏目名称" }
        ],
        catgType: [
          { required: true, trigger: "blur", message: "请选择栏目类型" }
        ],
      }
    }
  },
  created() {
    this.query = this.$route.query
  },

  methods:{

    /**确定按钮*/
    submitForm(){
      if (this.query.catgLevel){
        this.form.catgLevel = this.query.catgLevel
      }
      if (this.query.parentId){
        this.form.parentId = this.query.parentId
      }
      addCategory(this.form).then((res) => {
        if (res.code == 200){
          this.$modal.msgSuccess("保存成功");
          this.cancel();
        }
      });
    },

    /**取消按钮*/
    cancel(){
      this.reset();
      //关闭当前页面
      this.$store.dispatch("tagsView/delView", this.$route);
      // 调用全局挂载的方法，关闭当前页
      this.$router.go(-1)
    },

    /**表单重置*/
    reset(){

    }

  }
}
</script>

<style scoped>

</style>
