<template>
  <el-form :disabled="disabled" :model="formOption" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
    <el-form-item label="内容标题" prop="title">
      <el-input v-model="formOption.title"></el-input>
    </el-form-item>
    <el-form-item label="一级分类" prop="type">
      <el-select v-model="formOption.type" placeholder="请选择分类">
      </el-select>
    </el-form-item>
    <el-form-item label="二级分类" prop="tag" required>
      <el-select v-model="formOption.tag" placeholder="请选择标签">
      </el-select>
<!--      <el-input v-model="formOption.tag"></el-input>-->
    </el-form-item>
    <el-form-item label="编辑内容" prop="note">
      <Tinymce v-model="formOption.note" ref="tinymce"></Tinymce>
    </el-form-item>
    <el-form-item v-if="!disabled">
      <el-button @click="resetForm('ruleForm')">取消</el-button>
      <el-button type="primary" @click="submitForm('ruleForm')">保存</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
  import Tinymce from "@/components/Tinymce";


  export default {
    name: "modifyDialog",
    components: {Tinymce},
    inject:["contentManage"],
    props: {
      formOption: {},
      disabled: {
        type: Boolean,
        default: false
      }
    },
    data () {
      return {
        rules: {
          title: [
            { required: true, message: '请输入内容标题', trigger: 'blur' }
          ],
          type: [
            { required: true, message: '请选择分类', trigger: 'blur' }
          ],
          note: [
            { required: true, message: '请输入内容', trigger: 'blur' }
          ],
        },
      }
    },
    methods: {
      /* 编辑 */
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            this.contentManage.modifyChange(this.formOption)
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      resetForm() {
        this.contentManage.closeChange()
      },
    }
}
</script>

<style scoped>

</style>
