<template>
  <el-dialog
    :title="title"
    :visible.sync="modalIsShow"
    width="520px"
    :modal="false"
    append-to-body
    custom-class="side-dialog"
    @open="visibleChange"
  >
    <v-editor
      v-model="editCont"
      placeholder="请输入"
      :enable-formula="false"
    ></v-editor>

    <div slot="footer">
      <el-button type="primary" @click="confirm">保存</el-button>
      <el-button type="danger" plain @click="cancel">返回</el-button>
    </div>
  </el-dialog>
</template>

<script>
export default {
  name: "ModifyRichText",
  props: {
    content: {
      type: [Object, String],
      default() {
        return {};
      },
    },
    title: {
      type: String,
      default: "",
    },
  },
  data() {
    return {
      modalIsShow: false,
      editCont: "",
    };
  },
  methods: {
    visibleChange() {
      this.editCont = this.content || { sections: [] };
    },
    cancel() {
      this.modalIsShow = false;
    },
    open() {
      this.modalIsShow = true;
    },
    confirm() {
      this.$emit("modified", this.editCont);
      this.cancel();
    },
  },
};
</script>
