<template>
  <basic-container>
    <avue-crud
      :option="option"
      :table-loading="loading"
      :data="data"
      :page.sync="page"
      ref="crud"
      @search-change="searchChange"
      @current-change="currentChange"
      @size-change="sizeChange"
      @refresh-change="refreshChange"
      @search-reset="searchReset"
      @on-load="onLoad"
    >
      <!--      <template slot="menu" slot-scope="{row}">-->
      <!--        <el-button size="small" type="text" @click="seeDetail(row)">查看</el-button>-->
      <!--      </template>-->
      <template slot-scope="{ row }" slot="menu">
        <el-button
          type="text"
          size="small"
          @click.stop="updateRow(row)"
        ><i class="el-icon-share"></i>处理
        </el-button>
      </template>
    </avue-crud>
    <!-- 新增、编辑 -->
    <!--    <el-drawer :title="drawerTitle" :visible.sync="viewDrawer" size="60%">-->
    <!--      <div>-->
    <!--        <el-row :gutter="20">-->
    <!--          <el-col :span="12"><span>咨询部门：</span>{{ lookData.consultDeptName }}</el-col>-->
    <!--          <el-col :span="12"><span>咨询题目：</span>{{ lookData.consultTopic }}</el-col>-->
    <!--        </el-row>-->
    <!--        <el-row :gutter="20">-->
    <!--          <el-col :span="12"><span>咨询内容：</span>{{ lookData.consultContent }}</el-col>-->
    <!--          <el-col :span="12"><span>联系电话：</span>{{ lookData.consultPhone }}</el-col>-->
    <!--        </el-row>-->
    <!--        <el-row :gutter="20">-->
    <!--          <el-col :span="12"><span>咨询日期：</span>{{ lookData.consultTime }}</el-col>-->
    <!--        </el-row>-->
    <!--      </div>-->
    <!--    </el-drawer>-->
  </basic-container>
</template>

<script>
import {dateFormat} from '@/util/date'
import Tinymce from "@/components/Tinymce";
import {getList, consultMailboxInfoUpdate} from '@/api/manage/mailbox'

const classStatus = {
  0: '未处理',
  1: '已处理',
}
const initPages = {
  pageSize: 10,
  currentPage: 1,
  total: 100,
}
const classEnumStatus = Object.keys(classStatus).map((item) => ({
  label: classStatus[item], value: Number(item)
}))
const columnList = [
  // {
  //   label: "咨询部门",
  //   prop: "consultDeptName",
  //   search: true,
  // },
  {
    label: "咨询题目",
    prop: "consultTopic",
    search: true,
  },
  {
    label: "咨询人",
    prop: "consultName",
    search: true,
  }, {
    label: "创建人",
    prop: "createUser",
    hide: true,
  }, {
    label: "创建部门",
    prop: "createDept",
    hide: true,
  }, {
    label: "修改人",
    prop: "updateUser",
    hide: true,
  },
  {
    label: "咨询内容",
    prop: "consultContent",
    search: false,
  },
  {
    label: "意见内容",
    prop: "opinionContent",
    search: false,
  },
  {
    label: "联系电话",
    prop: "reply_content",
    search: true,
  },
  {
    label: "咨询日期",
    prop: "consultTime",
    type: 'datetime',
    searchSpan: 8,
    searchRange: true,
  },
  {
    label: "处置情况",
    prop: "disposalSituation",
    search: true,
  },
  {
    label: "是否处理",
    prop: "status",
    type: "select",
    dicData: classEnumStatus,
    search: true,
  },
]
const rules = {
  name: [
    {required: true, message: '请输入内容标题', trigger: 'blur'}
  ],
  type: [
    {required: true, message: '请选择分类', trigger: 'blur'}
  ],
  content: [
    {required: true, message: '请输入内容', trigger: 'blur'}
  ],
}
export default {
  name: "index",
  components: {
    Tinymce
  },
  mounted() {
  },
  data() {
    return {
      applTime: '',
      loading: false,
      viewDrawer: false,
      drawerTitle: '新增内容',
      formOption: {},
      query: {},
      rules: Object.assign({}, rules),
      data: [],
      lookData: {},
      page: Object.assign({}, initPages),
    }
  },
  computed: {
    option() {
      return {
        height: "auto",
        tip: false,
        searchShow: true,
        searchMenuSpan: 6,
        border: true,
        index: true,
        indexLabel: "序号",
        selection: false,
        viewBtn: true,
        addBtn: false,
        editBtn: false,
        delBtn: false,
        columnBtn: false,
        menuWidth: 150,
        // labelWidth: 151,
        dialogClickModal: false,
        dialogType: "drawer",
        dialogFullscreen: true,
        column: columnList,
      }
    }
  },
  methods: {
    dateFormat,
    updateRow(row) {
      const _this = this
      let h = this.$createElement;
      this.$prompt("回复信件", // "请核对信息后",
        {
          distinguishCancelAndClose: true,
          confirmButtonText: "完 成",
          cancelButtonText: "取 消",
          center: true,
          inputType: "textarea",
          inputPlaceholder: "处理内容",
          beforeClose: async function (action, instance, done) {
            if (action === 'confirm') {
              const disposalSituation = instance.inputValue
              if (!disposalSituation) {
                this.$message({type: "info", message: "请输入处理内容"});
              } else {
                let resData = await consultMailboxInfoUpdate({id: row.id, disposalSituation, status: 1})
                if (resData.data.code === 200) {
                  this.$message({type: "success", message: "操作成功"});
                  done()
                  _this.onLoad();
                }
              }
            } else {
              done()
            }
          }
        }
      )
    },
    look(row) {
      this.drawerTitle = '查看'
      this.lookData = JSON.parse(JSON.stringify(row))
      this.formOption = JSON.parse(JSON.stringify(row))
      this.viewDrawer = true
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
      this.viewDrawer = false
    },
    searchReset() {
      this.query = {};
      this.onLoad();
    },
    searchChange(params, done) {
      console.log(params);
      if (params.applTime) {
        var val = JSON.parse(JSON.stringify(params.applTime))
        params.applTimeStart = val[0] + " 00:00:00";
        params.applTimeEnd = val[1] + " 23:59:59";
        delete params.applTime
      }
      this.query = params;
      console.log(this.query);
      this.page.currentPage = 1;
      this.onLoad();
      done();
    },
    currentChange(val) {
      this.page.currentPage = val
    },
    sizeChange(val) {
      this.page.currentPage = 1
      this.page.pageSize = val
    },
    refreshChange() {
      this.page.currentPage = 1;
      this.onLoad()
    },
    /* 表格方法 */
    onLoad() {
      return new Promise(async (resolve, reject) => {
        this.loading = true;
        let params = {
          current: this.page.currentPage,
          size: this.page.pageSize,
          ...this.query,
        }
        let resData = await getList(params)
        if (resData.data.code === 200) {
          const {current, records, total, size} = resData.data.data
          this.data = records;
          this.page.total = total;
          this.loading = false;
        }
        resolve()
      })
    },
    seeDetail() {
    }
  }
}
</script>

<style scoped>

</style>
