 <!-- 查询督办 -->
<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.urgeContent" :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-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 { getAllSuperviseList } from '@/api/caseSupervise'
import { getcheckStatus } from '@/api/allDict'

export default {
  name: 'SearchSupervise',
  components: { AppContainer, SearchArea, SearchItem, CaseListTable },
  data() {
    return {
      list: [],
      total: 0,
      timeRange: [], // 时间范围
      listLoading: true, // 列表加载动画
      listQuery: {
        urgeContent: '', // 事件标题
        checkStatus: '',
        startTime: '',
        endTime: '',
        offset: 1,
        limit: 20,
        sort: '',
        order: ''
      }, // 筛选条件
      columns: [
        {
          text: '申请人',
          value: 'applyPersonName',
          align: 'center'
        },
        {
          text: '事件标题',
          value: 'title',
          align: 'center'
        },
        {
          text: '督办内容',
          value: 'urgeContent',
          align: 'center'
        },
        {
          text: '处理状态',
          value: 'caseStatus',
          align: 'center'
        },
        {
          text: '督办类型',
          value: 'urgeType',
          align: 'center'
        },
        {
          text: '申请时间',
          value: 'applyTime',
          width: 90,
          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: 'urgePersonName',
          align: 'center'
        },
        {
          text: '督办时间',
          value: 'urgeTime',
          width: 90,
          align: 'center'
        },
        {
          text: '督办状态',
          value: 'urgeStatus',
          align: 'center'
        },
        {
          text: '督办结果',
          value: 'urgeResult',
          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
      if (this.timeRange && this.timeRange.length >= 2) {
        this.listQuery.startTime = this.timeRange[0]
        this.listQuery.endTime = this.timeRange[1]
      } else {
        this.listQuery.startTime = ''
        this.listQuery.endTime = ''
      }
      getAllSuperviseList(this.listQuery).then(response => {
        if (response.code === 200) {
          // response.data.rows = [
          //   {
          //     'id': '1',
          //     'applyPersonName': '张三',
          //     'title': '事件1',
          //     'caseStatus': '处理中',
          //     'urgeContent': '督办内容',
          //     'applyTime': '2020-01-01 00:00:00',
          //     'urgeType': '申请督办',
          //     'checkPersonName': '王',
          //     'checkStatus': '未督办',
          //     'checkTime': '-',
          //     'checkRejectReason': '-',
          //     'urgeStatus': '未督办',
          //     'urgeTime': '-',
          //     'urgeResult': '-'
          //   }
          // ]
          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
      })
    },
    // 更换页码等
    changePage(listQuery) {
      this.listQuery = listQuery
      this.fetchData()
    }
  }
}
</script>
