<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"
    >
    </avue-crud>
  </basic-container>
</template>

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

const initPages = {
  pageSize: 10,
  currentPage: 1,
  total: 100,
}
const classEnum = {
  "1": '一般投诉',
  "2": '较难投诉',
  "3": '困难投诉',
  "4": '特殊投诉',
}
const classIsDeleted = {
  0: '否',
  1: '是',
}
const classStatus = {
  0: '未发布',
  1: '发布',
  2: '关闭'
}
const classEnumList = Object.keys(classEnum).map((item) => ({
  label: classEnum[item], value: item
}))
const classEnumDeleted = Object.keys(classIsDeleted).map((item) => ({
  label: classIsDeleted[item], value: Number(item)
}))
const classEnumStatus = Object.keys(classStatus).map((item) => ({
  label: classStatus[item], value: Number(item)
}))
const columnList = [
  {
    label: "投诉标题",
    prop: "complaintTitle",
    search: true
  },
  {
    label: "投诉对象",
    prop: "complaintObject",
    search: true
  },
  {
    label: "联系方式",
    prop: "complaintPhone",
    search: true
  },
  {
    label: "投诉类型",
    prop: "complaintType",
    type: "select",
    dataType: "number",
    dicData: classEnumList,
    display: false,
    search: true
  },
  {
    label: "是否处理",
    prop: "status",
    type: "select",
    dicData: classEnumStatus,
    search: true,
  },
  {
    label: "是否删除",
    prop: "isDeleted",
    type: "select",
    dicData: classEnumDeleted,
    search: false,
  },
  {
    label: "是否已读",
    prop: "isRead",
    type: "select",
    dicData: classEnumDeleted,
    search: true,
  },
  {
    label: "创建时间",
    prop: "complaintTime",
    type: 'datetime',
    searchSpan: 8,
    searchRange: 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
  },
  created() {
    // this.seeDetail({id: '1783485236359442433'})
  },
  data() {
    return {
      applTime: '',
      loading: false,
      viewDrawer: false,
      drawerTitle: '新增内容',
      formOption: {},
      query: {},
      rules: Object.assign({}, rules),
      data: [],
      lookData: {},
      classEnum,
      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: 140,
        labelWidth: 151,
        dialogClickModal: false,
        dialogType: "drawer",
        dialogFullscreen: true,
        column: columnList,
      }
    }
  },
  methods: {
    dateFormat,
    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(row) {
      return new Promise(async (resolve, reject) => {
        let params = {
          id: row.id
        }
        let resData = await getInfo(params)
        if (resData.data.code === 200) {
          this.drawerTitle = '查看'
          this.lookData = JSON.parse(JSON.stringify(resData.data.data))
          this.formOption = JSON.parse(JSON.stringify(resData.data.data))
          this.viewDrawer = true
        }
      })
    }
  }
}
</script>

<style scoped>

</style>
