<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <!--        <el-input v-model="query.content" clearable placeholder="发布内容" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />-->
        <el-input v-model="query.title" clearable placeholder="标题" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <el-select v-model="query.status" style="width: 185px;" clearable placeholder="请选择审核状态" @keyup.enter.native="crud.toQuery">
          <el-option
            v-for="item in dict.information_status"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
        <date-range-picker
          v-model="query.releaseTime"
          start-placeholder="创建时间"
          end-placeholder="结束时间"
          class="date-item"
        />
        <rrOperation :crud="crud" />
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="1300px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
          <el-form-item label="标题">
            <el-input v-model="form.title" :disabled="true" style="width: 500px;" />
          </el-form-item>
          <el-form-item label="内容" prop="content">
            <!--            <WangEditor :disabled="istrue" v-model="form.content" style="width: 1000px;" />-->
            <Toolbar
              style="border-bottom: 1px solid #ccc"
              :editor="editor"
              :default-config="toolbarConfig"
              :mode="mode"
            />
            <Editor
              v-model="form.content"
              style="height: 1000px; overflow-y: hidden;"
              :default-config="editorConfig"
              :mode="mode"
              @onCreated="onCreated"
            />
          </el-form-item>
          <!--          <el-form-item label="是否有效">-->
          <!--            <el-input v-model="form.isValid" style="width: 370px;" />-->
          <!--          </el-form-item>-->
          <el-form-item label="审批状态" prop="status">
            <el-switch
              v-model="form.status"
              active-color="#13ce66"
              active-value="01"
              inactive-value="02"
              inactive-color="#ff4949"
            />
          </el-form-item>
          <el-form-item label="有效状态" prop="isValid">
            <el-switch
              v-model="form.isValid"
              active-color="#13ce66"
              active-value="1"
              inactive-value="0"
              inactive-color="#ff4949"
            />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <!--        <el-table-column prop="id" label="主键" />-->
        <el-table-column prop="title" label="发布标题" />
        <!--        <el-table-column prop="content" label="发布内容(需发布的信息内容)" />-->
        <el-table-column prop="status" label="审核状态">
          <template slot-scope="scope">
            {{ dict.label.information_status[scope.row.status] }}
          </template>
        </el-table-column>
        <!--        <el-table-column prop="approvalUser" label="审批人" />-->
        <!--        <el-table-column prop="requestUser" label="发起人" />-->
        <el-table-column prop="releaseTime" label="发布时间" />
        <!--        <el-table-column prop="approvalTime" label="审批时间" />-->
        <!--        <el-table-column prop="isValid" label="是否有效">-->
        <!--          <template slot-scope="scope">-->
        <!--            {{ dict.label.is_true[scope.row.isValid] }}-->
        <!--          </template>-->
        <!--        </el-table-column>-->
        <el-table-column v-if="checkPer(['admin','dmInformation:edit','dmInformation:del'])" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudDmInformation from '@/api/dmInformation'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'
import dateRangePicker from '@/components/DateRangePicker'
import { Editor, Toolbar } from '@wangeditor/editor-for-vue'

const defaultForm = { id: null, content: null, status: null, approvalUser: null, taskId: null, procInstId: null, requestUser: null, createBy: null, updateBy: null, createTime: null, updateTime: null, releaseTime: null, approvalTime: null, title: null, approvalRemark: null, isHasApproval: null, isValid: null }
export default {
  name: 'DmInformationApprovalOne',
  components: { pagination, crudOperation, rrOperation, udOperation, dateRangePicker, Editor, Toolbar },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  dicts: ['information_status', 'is_true'],
  cruds() {
    return CRUD({ title: '审批内容管理', url: 'api/dmInformation', idField: 'id', sort: 'id,desc', query: { status: '00' }, crudMethod: { ...crudDmInformation }, optShow: {
      add: false,
      edit: true,
      del: false,
      reset: true
    }})
  },
  data() {
    return {
      editor: null,
      toolbarConfig: { },
      editorConfig: { placeholder: '请输入内容...' },
      mode: 'simple', // or 'simple'
      permission: {
        add: ['admin', 'dmInformation:add'],
        edit: ['admin', 'dmInformation:edit'],
        del: ['admin', 'dmInformation:del']
      },
      rules: {
        id: [
          { required: true, message: '主键不能为空', trigger: 'blur' }
        ],
        content: [
          { required: true, message: '发布内容(需发布的信息内容)不能为空', trigger: 'blur' }
        ],
        title: [
          { required: true, message: '发布标题不能为空', trigger: 'blur' }
        ]
      },
      queryTypeOptions: [
        { key: 'content', display_name: '发布内容(需发布的信息内容)' },
        { key: 'status', display_name: '(00-待审核  01-审批通过(已发布） 02-审核未通过)' }
      ]
    }
  },
  beforeDestroy() {
    const editor = this.editor
    if (editor == null) return
    editor.destroy() // 组件销毁时，及时销毁编辑器
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    },
    onCreated(editor) {
      this.editor = Object.seal(editor) // 一定要用 Object.seal() ，否则会报错
      this.editor.disable()
    }
  }
}
</script>
<style src="@wangeditor/editor/dist/css/style.css"></style>
<style scoped>

</style>
