 <!-- 查询监察 -->
<template>
  <app-container>
    <search-area :need-clear="false" :need-search-more="false" :size="size" type="default" search-more-type="default" @search="search">
      <!--一般查询条件-->
      <search-item>
        <el-input v-model.trim="listQuery.superviseContent" :size="size" placeholder="监察内容" clearable/>
      </search-item>
      <search-item>
        <el-date-picker
          v-model="timeRange"
          size="small"
          type="datetimerange"
          range-separator="至"
          value-format="yyyy-MM-dd HH:mm:ss"
          start-placeholder="申请开始时间"
          end-placeholder="申请结束时间"/>
      </search-item>
      <search-item>
        <el-date-picker
          v-model="timeRange1"
          size="small"
          type="datetimerange"
          range-separator="至"
          value-format="yyyy-MM-dd HH:mm:ss"
          start-placeholder="审核开始时间"
          end-placeholder="审核结束时间"/>
      </search-item>
      <search-item>
        <el-date-picker
          v-model="timeRange2"
          size="small"
          type="datetimerange"
          range-separator="至"
          value-format="yyyy-MM-dd HH:mm:ss"
          start-placeholder="监察开始时间"
          end-placeholder="监察结束时间"/>
      </search-item>
      <search-item>
        <el-select v-model="listQuery.checkStatus" placeholder="审核情况" size="small" clearable>
          <el-option v-for="item in checkStateList" :key="'checkState_'+item.value" :label="item.name" :value="item.value"/>
        </el-select>
      </search-item>
    </search-area>
    <case-list-table :list-query="listQuery" :list="list" :total="total" :columns="columns" :list-loading="listLoading" common-columns="" @changePage="changePage">
      <template slot="operations">
        <el-table-column label="操作" align="center">
          <template slot-scope="scope">
            <el-button type="text" size="small" @click.stop="goDetail(scope.row)">详情</el-button>
          </template>
        </el-table-column>
      </template>
    </case-list-table>
  </app-container>
</template>

<script>
import AppContainer from '@/components/layout/AppContainer'
import SearchArea from '@/components/SearchArea/SearchArea'
import SearchItem from '@/components/SearchArea/SearchItem'
import CaseListTable from '@/views/caseManage/caseCommon/caseListTable'
import { getAllMonitorList } from '@/api/caseMonitor'
import { getcheckStatus } from '@/api/allDict'

export default {
  name: 'SearchMonitor',
  components: { AppContainer, SearchArea, SearchItem, CaseListTable },
  data() {
    return {
      list: [],
      total: 0,
      timeRange: [], // 申请时间范围
      timeRange1: [], // 审核时间范围
      timeRange2: [], // 监察时间范围
      listLoading: true, // 列表加载动画
      listQuery: {
        superviseContent: '', // 监察内容
        applyStartTime: '', // 申请开始时间
        applyEndTime: '', // 申请结束时间
        checkStartTime: '', // 审核开始时间
        checkEndTime: '', // 审核结束时间
        superviseStartTime: '', // 监察开始时间
        superviseEndTime: '', // 监察结束时间
        checkStatus: '', // 审核情况
        offset: 1,
        limit: 20,
        sort: '',
        order: ''
      }, // 筛选条件
      columns: [
        {
          text: '申请人',
          value: 'applyPersonName',
          align: 'center'
        },
        {
          text: '事件标题',
          value: 'title',
          align: 'center'
        },
        {
          text: '监察内容',
          value: 'superviseContent',
          align: 'center'
        },
        {
          text: '申请时间',
          value: 'applyTime',
          width: 90,
          align: 'center'
        },
        {
          text: '处理状态',
          value: 'caseStatus',
          align: 'center'
        },
        {
          text: '审核人',
          value: 'checkPersonName',
          align: 'center'
        },
        {
          text: '审核时间',
          value: 'checkTime',
          width: 90,
          align: 'center'
        },
        {
          text: '审核情况',
          value: 'checkStatus',
          align: 'center'
        },
        {
          text: '审核驳回原因',
          value: 'checkRejectReason',
          align: 'center'
        },
        {
          text: '监察状态',
          value: 'superviseStatus',
          align: 'center'
        },
        {
          text: '监察人',
          value: 'supervisePersonName',
          align: 'center'
        },
        {
          text: '监察时间',
          value: 'superviseTime',
          width: 90,
          align: 'center'
        },
        {
          text: '监察结果',
          value: 'superviseResult',
          align: 'center'
        }
      ], // 显示列
      checkStateList: [], // 审核状态
      size: 'small'
    }
  },
  created() {
    this.fetchCheckStateList()
    this.fetchData()
  },
  methods: {
    search() {
      this.fetchData(false)
    },
    // 获取数据
    fetchData(isNowPage = true) {
      this.listLoading = true
      if (!isNowPage) { // 是否显示当前页，否则跳转第一页
        this.listQuery.offset = 1
      }
      this.listLoading = true
      this.handleTimeRanges()
      getAllMonitorList(this.listQuery).then(response => {
        if (response.code === 200) {
          // response.data.rows = [
          //   {
          //     'id': '1',
          //     'applyPersonName': '张三',
          //     'reporterPhone': '15652360420',
          //     'caseStatus': '处理中',
          //     'superviseContent': '监察内容',
          //     'title': '申请监察',
          //     'eorcName': '咨询',
          //     'caseTypeName': '咨询',
          //     'caseDetailTypeName': '垃圾处理',
          //     'checkPersonName': '王',
          //     'applyTime': '2020-04-12 00:00:00',
          //     'checkTime': '2020-03-12 00:00:00',
          //     'superviseTime': '2020-03-12 00:00:00',
          //     'checkStatus': '审核通过',
          //     'checkRejectReason': '-',
          //     'supervisePersonName': '张三',
          //     'superviseStatus': '未监察',
          //     'superviseResult': '已监督完成'
          //   }
          // ]
          this.list = response.data.rows
          this.total = response.data.total
          this.listLoading = false
        }
      })
    },
    // 任务办理
    goDetail(row) {
      this.$router.push({
        path: '/caseDetail/' + row.caseId,
        query: {
          showProcess: false
        }
      })
    },
    // 监察状态
    fetchCheckStateList() {
      getcheckStatus().then(repsonse => {
        this.checkStateList = repsonse.data
      })
    },
    // 处理时间问题
    handleTimeRanges() {
      // 处理申请时间
      if (this.timeRange && this.timeRange.length === 2) {
        this.listQuery.applyStartTime = this.timeRange[0]
        this.listQuery.applyEndTime = this.timeRange[1]
      } else {
        this.listQuery.applyStartTime = ''
        this.listQuery.applyEndTime = ''
      }
      // 处理申请时间
      if (this.timeRange1 && this.timeRange1.length === 2) {
        this.listQuery.checkStartTime = this.timeRange1[0]
        this.listQuery.checkEndTime = this.timeRange1[1]
      } else {
        this.listQuery.checkStartTime = ''
        this.listQuery.checkEndTime = ''
      }
      // 监察申请时间
      if (this.timeRange2 && this.timeRange2.length === 2) {
        this.listQuery.superviseStartTime = this.timeRange2[0]
        this.listQuery.superviseEndTime = this.timeRange2[1]
      } else {
        this.listQuery.superviseStartTime = ''
        this.listQuery.superviseEndTime = ''
      }
    },
    // 更换页码等
    changePage(listQuery) {
      this.listQuery = listQuery
      this.fetchData()
    }
  }
}
</script>
