<template>
  <div style="margin-top: 5px">
    <quill-editor
      ref="myTextEditor"
      v-model="content"
      :options="editorOption"
      @change="onEditorChange($event)"
    />
  </div>
</template>

<script>
export default {
  props: ['placeholder'],
  data() {
    return {
      content: '',
      editorOption: {
        // 操作按钮
        modules: {
          toolbar: [
            ['bold', 'italic', 'underline', 'strike'],
            ['blockquote', 'code-block'],
            [{ header: 1 }, { header: 2 }],
            [{ list: 'ordered' }, { list: 'bullet' }],
            [{ script: 'sub' }, { script: 'super' }],
            [{ indent: '-1' }, { indent: '+1' }],
            [{ direction: 'rtl' }],
            [{ size: ['small', false, 'large', 'huge'] }],
            [{ header: [1, 2, 3, 4, 5, 6, false] }],
            [{ font: [] }],
            [{ color: [] }, { background: [] }],
            [{ align: [] }],
            ['clean'],
            ['link', 'image', 'video']
          ]
        },
        placeholderInner: this.placeholder ? this.placeholder : '请输入...'
      }
    }
  },
  methods: {
    onEditorChange({ editor, html, text }) {
      // 富文本编辑器  文本改变时 设置字段值
      this.html = html
      const data = {
        html: this.html,
        content: text
      }
      this.$emit('on-result-change', data)
    },
    _initData(content) {
      this.content = content || ''
    }
  }
}
</script>
<style>
.ql-container {
  height: 300px !important;
}

.ql-snow {
  border: 1px solid #dddee1 !important;
}

.ql-editor.ql-blank::before {
  color: #bbbec4 /* rgba(0,0,0,0.6)*/;
  font-style: normal;
}

.ql-toolbar.ql-snow {
  border-radius: 5px 5px 0 0 !important;
}

.ql-container.ql-snow {
  border-radius: 0 0 5px 5px !important;
  border-top: none !important;
}
</style>
