<template>
  <div v-loading="loading">
    <div class="white-box">
      <el-form ref="form" :model="form" label-width="100px" style="">
        <el-form-item label="标题" style="width: 500px;">
          <el-input v-model="form.title"></el-input>
        </el-form-item>
        <el-form-item label="发送给" style="width: 500px;">
          <el-input v-model="form.toUserName"></el-input>
        </el-form-item>
        <el-form-item label="内容">
          <editor id="contentEditor" :cloud-channel="editorRootUrl" ref="contentEditor" v-model="form.content"
                  :init="editorOptions"></editor>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit" :loading="submitButtonStat">提交</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import Editor from 'nix-tinymce'
import {fullEditor, textEditor, EDITOR_ROOT_URL} from '@/utils/editor'
import network from '@/utils/network'
import tool from '@/utils/tool'

export default {
  name: 'message_edit',
  components: {
    'editor': Editor
  },
  mounted () {
    this.loading = false
  },
  data () {
    return {
      form: {
        title: '',
        toUserName: null,
        content: '',
      },
      loading: false,
      submitButtonStat: false,
      editorRootUrl: EDITOR_ROOT_URL,
      editorOptions: textEditor,
    }
  },
  methods: {
    onSubmit () {
      this.submitButtonStat = true
      let path = 'message/add'
      network.postData(path, this.form).then(response => {
        this.$message({
          message: response,
          type: 'success'
        })
        this.submitButtonStat = false
        this.$router.go(-1)
      }).catch(() => {
        this.submitButtonStat = false
      })
    },
  }
}
</script>

<style scoped>

</style>