<template>
  <div class="editor">
    <el-form :model="formData" size="medium" label-width="100px">
      <el-row>
        <el-col :span="12">
          <!--            <el-form-item label="详情标题" prop="title">-->
          <el-form-item label="详情标题">
            <el-input v-model="formData.title" placeholder="请输入详情标题" clearable :style="{width: '100%'}">
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :offset="1" :span="22">
          <Editor ref="editor" v-model="formData.content" :height="500"/>
          <!--            <CodeEdit ref="codeEdit" v-model="formData.content" :height="500"/>-->
          <!--            <CustomEditor v-model="formData.content" :height="500"/>-->
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24" class="save">
          <el-form-item size="large">
            <el-button type="primary" @click="save">保存</el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
  </div>
</template>

<script>
import { getDetails, updateDetails } from '../../../api/sist/navigation'
import Editor from '@/views/utils/tinymce/Tinymce'
export default {
  name: 'articleEdit',
  components: {
    Editor
  },
  data() {
    return {
      formData: {
        title: '',
        content: ''
      }
    }
  },
  created() {
    let refId = this.$route.params && this.$route.params.refId;
    let navId = this.$route.params && this.$route.params.navId;
    this.handleUpdateDetails(refId)
  },
  methods:{
    handleUpdateDetails(id) {
      this.formData = {
        id: id,
        title: '',
        content: ''
      }
      getDetails(id).then(res => {
        if (res.data){
          this.formData = res.data
        }
      })
    },
    save() {
      let that = this
      updateDetails(this.formData).then(res => {
        that.msgSuccess('修改成功')
        that.close()
      })
    },
    close() {
      this.$store.dispatch("tagsView/delView", this.$route);
      this.$router.push({path: "/sist/navigation/", query: {t: Date.now()}})
    },
  }
}
</script>

<style scoped lang="scss">
.save {
  //text-align: center;
  margin-top: 20px;
}
.editor{
  margin-top: 20px;
}
</style>
