<template>
  <div class="dashboard-container">
    <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
      <el-form-item label="标题" prop="name">
        <el-input v-model="ruleForm.name"></el-input>
      </el-form-item>
      <el-form-item label="稿件内容" required>
        <el-form-item prop="date1">
          <Editor id="tinymce" v-model="tinymceHtml" :init="init" style="width:100%"></Editor>
        </el-form-item>
      </el-form-item>

      <el-form-item label="上传附件" prop="desc">
        <el-input type="textarea" v-model="ruleForm.desc"></el-input>
      </el-form-item>

      <el-form-item label="描述" prop="desc">
        <el-input type="textarea" v-model="ruleForm.desc"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" size="mini" @click="submitForm('ruleForm')">
          <i class="iconfont">&#xe683;</i>
          <span> 确定</span></el-button>
        <el-button type="primary" size="mini" @click="resetForm('ruleForm')">
          <i class="iconfont">&#xe688;</i>
          <span> 关闭</span>
        </el-button>
      </el-form-item>
    </el-form>

  </div>
</template>
<script>
import tinymce from 'tinymce/tinymce'
// import 'tinymce/themes/modern/theme'
import Editor from '@tinymce/tinymce-vue'
export default {
  data() {
    return {
      ruleForm: {
        name: '',
        region: '',
        date1: '',
        date2: '',
        delivery: false,
        type: [],
        resource: '',
        desc: '',

      },
      rules: {
        name: [
          { required: true, message: '标题名称', trigger: 'blur' },
          { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
        ],
        region: [
          { required: true, message: '请选择活动区域', trigger: 'change' }
        ],
        date1: [
          { type: 'date', required: true, message: '请选择日期', trigger: 'change' }
        ],
        date2: [
          { type: 'date', required: true, message: '请选择时间', trigger: 'change' }
        ],
        type: [
          { type: 'array', required: true, message: '请至少选择一个活动性质', trigger: 'change' }
        ],
        resource: [
          { required: true, message: '请选择活动资源', trigger: 'change' }
        ],
        desc: [
          { required: true, message: '请填写活动形式', trigger: 'blur' }
        ]
      },
      tinymceHtml: '',
      init: {
        language_url: '../../utils/zh_CN.js',
        language: 'zh_CN',
        // skin_url: '../static/skins/lightgray',
        height: 300,
        plugins: 'link lists image code table colorpicker textcolor wordcount contextmenu',
        toolbar:
          'bold italic underline strikethrough | fontsizeselect | forecolor backcolor | alignleft aligncenter alignright alignjustify | bullist numlist | outdent indent blockquote | undo redo | link unlink image code | removeformat',
        branding: false
      }
    };
  },
  methods: {
    editorInit() {

    },
    submitForm(formName) {
      console.log('富文本编辑器', this.tinymceHtml)
      this.$refs[formName].validate((valid) => {
        if (valid) {
          alert('submit!');
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
      this.$router.go(-1)
    }
  },
  mounted() {
    tinymce.init({})
  },
  components: { Editor }
}
</script>

<style scoped lang="scss">
.dashboard {
  &-container {
    margin: 30px;
  }
  &-text {
    font-size: 30px;
    line-height: 46px;
  }
}
</style>