<template>
  <app-container>
    <search-area :need-clear="true" :need-search-more="false" type="seperate" search-more-type="default" @search="fetchData" @clear="clearInput">
      <!--一般查询条件-->
      <search-item>
        <el-input v-model.trim="listQuery.caseId" placeholder="事件编号" clearable/>
      </search-item>
      <search-item/>
      <search-item>
        <el-input v-model.trim="listQuery.title" placeholder="事件标题" clearable/>
      </search-item>
      <search-item>
        <el-input v-model.trim="listQuery.description" placeholder="事件内容" clearable/>
      </search-item>
      <search-item>
        <el-input v-model.trim="listQuery.reporterPhone" placeholder="联系方式" clearable/>
      </search-item>
      <search-item>
        <el-select v-model="listQuery.applyState" placeholder="状态" clearable>
          <el-option v-for="item in applyStateList" :key="'applyState_'+item.value" :label="item.name" :value="item.value"/>
        </el-select>
      </search-item>
    </search-area>
    <normal-table :data="list" :head="tableOption.head" :query="listQuery" :total="total" :columns="columns" :list-loading="listLoading" :options="tableOption.options" :tools-option="tableOption.toolsOption" @change="changePage">
      <template slot="columns">
        <el-table-column label="操作" align="center" width="100">
          <template slot-scope="scope">
            <el-button type="text" size="small" @click.stop="goDetail(scope.row)">详情</el-button>
          </template>
        </el-table-column>
      </template>
    </normal-table>
  </app-container>
</template>

<script>
import NormalTable from '@/components/NomalTable'
import AppContainer from '@/components/layout/AppContainer'
import SearchArea from '@/components/SearchArea/SearchArea'
import SearchItem from '@/components/SearchArea/SearchItem'
import { getDelayState } from '@/api/allDict'
import { delayList } from '@/api/caseDelay'
export default {
  name: 'DelayList',
  components: { SearchItem, SearchArea, AppContainer, NormalTable },
  data() {
    return {
      listQuery: {
        caseId: '', // 事件编号
        title: '', // 事件标题
        description: '', // 事件内容
        reporterPhone: '', // 联系方式
        applyState: '', // 申请状态
        offset: 1,
        limit: 20,
        sort: 'applyTime',
        order: 'desc'
      }, // 筛选条件
      columns: [
        {
          text: '事件标题',
          value: 'title',
          align: 'center'
        },
        {
          text: '延期时间',
          value: 'delayTime',
          align: 'center',
          width: 160
        },
        {
          text: '申请说明',
          value: 'applyReason',
          align: 'center'
        },
        {
          text: '申请人',
          value: 'applyUserName',
          align: 'center'
        },
        {
          text: '申请时间',
          value: 'applyTime',
          align: 'center',
          width: 160
        },
        {
          text: '状态',
          value: 'applyStateName',
          align: 'center'
        },
        {
          text: '审核人',
          value: 'approveUserName',
          align: 'center'
        },
        {
          text: '审核时间',
          value: 'approveTime',
          align: 'center',
          width: 160
        },
        {
          text: '审核驳回理由',
          value: 'rejectReason',
          align: 'center'
        }
      ], // 显示列
      list: [], // 列表数据
      total: 0, // 数据总数
      listLoading: true, // 列表加载动画
      tableOption: {
        head: {
          show: false, // 是否需要标题栏，
          text: '数据列表' // 标题名称
        },
        options: {
          needIndex: false // 是否需要序号列
        },
        toolsOption: {
          selectColumns: false, // 是否需要筛选列
          refresh: false // 是否需要刷新按钮
        }
      }, // 表格属性
      applyStateList: []
    }
  },
  created() {
    this.fetchData()
    this.fetchApplyStateList()
  },
  methods: {
    fetchData() {
      this.listLoading = true
      delayList(this.listQuery).then(res => {
        this.list = res.data.rows
        this.total = res.total
        this.listLoading = false
      })
    },
    fetchApplyStateList() {
      getDelayState().then(res => {
        this.applyStateList = res.data
      })
    },
    // 页数发生变化后的操作，可能是页码变化，可能是每页容量变化，此函数必写
    changePage(val) {
      if (val && val.size) {
        this.listQuery.limit = val.size
      }
      if (val && val.page) {
        this.listQuery.offset = val.page
      }
      this.fetchData()
    },
    // 重置后的操作， 若不需要显示重置按钮则不需要写
    clearInput() {
      this.listQuery = {
        caseId: '', // 事件编号
        title: '', // 事件标题
        description: '', // 事件内容
        reporterPhone: '', // 联系方式
        applyState: '',
        offset: 1,
        limit: 20,
        sort: 'applyTime',
        order: 'desc'
      }
    },
    // 查看详情
    goDetail(row) {
      this.$router.push({
        path: '/caseDetail/' + row.caseId,
        query: {
          showProcess: false
        }
      })
    }
  }
}
</script>

<style scoped>

</style>
