<template>
  <div class="edit-gutter">
    <el-form
      ref="modalFormComp"
      :key="modalForm.id"
      :model="modalForm"
      :rules="rules"
      label-width="120px"
    >
      <el-form-item prop="content" label="描述内容：">
        <el-input
          v-model="modalForm.content"
          placeholder="请输入描述内容"
          clearable
        ></el-input>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
const initModalForm = {
  id: "",
  content: "",
};

export default {
  name: "EditGutter",
  props: {
    instance: {
      type: Object,
      default() {
        return {};
      },
    },
  },
  data() {
    return {
      modalForm: { ...initModalForm },
      rules: {
        content: [
          {
            required: true,
            message: "请输入描述内容",
            trigger: "change",
          },
        ],
      },
    };
  },
  mounted() {
    this.initData(this.instance);
  },
  methods: {
    initData(val) {
      this.modalForm = this.$objAssign(initModalForm, val);
    },
    async submit() {
      const valid = await this.$refs.modalFormComp.validate().catch(() => {});
      if (!valid) return;

      const data = this.$objAssign(this.instance, this.modalForm);
      this.$emit("modified", data);
    },
  },
};
</script>
