 <!-- 审核监察 -->
<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-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>
            <el-button type="text" size="small" @click.stop="allow(scope.row)">同意</el-button>
            <el-button type="text" size="small" @click.stop="refuse(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 { monitorCheck, getCheckMonitorList } from '@/api/caseMonitor'

export default {
  name: 'WaitCheckMonitor',
  components: { AppContainer, SearchArea, SearchItem, CaseListTable },
  data() {
    return {
      list: [],
      total: 0,
      timeRange: [], // 时间范围
      timeRange1: [], // 时间范围
      listLoading: true, // 列表加载动画
      listQuery: {
        superviseContent: '', // 事件标题
        applyStartTime: '', // 申请开始时间
        applyEndTime: '', // 申请结束时间
        checkStartTime: '', // 审核开始时间
        checkEndTime: '', // 审核结束时间
        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',
          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'
        // }
      ], // 显示列
      monitorDialogVisible: false,
      monitorForm: {
        caseId: '',
        superviseStatus: '1',
        superviseResult: ''
      },
      monitorRules: {
        superviseResult: [{ required: true, message: '请填写监察结果', trigger: ['change', 'blur'] }]
      },
      size: 'small'
    }
  },
  mounted() {
    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.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 = ''
      }
      getCheckMonitorList(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',
          //     'checkStatus': '未审核',
          //     'superviseTime': '-',
          //     'checkRejectReason': '-'
          //   }
          // ]
          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
        }
      })
    },
    // 监察审核同意
    allow(row) {
      this.$confirm(
        '确定通过吗？',
        '确认操作',
        {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }
      ).then(() => {
        const params = {
          id: row.id,
          checkStatus: '1'
        }
        monitorCheck(params).then(response => {
          if (response.code === 200) {
            this.$message.success('监察审核成功')
            this.fetchData()
          }
        })
      })
    },
    // 不同意
    refuse(row) {
      this.$prompt('', '驳回理由', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        inputErrorMessage: '输入不能为空',
        inputValidator: (value) => {
          if (value) {
            if (value.trim().length < 1) {
              return '输入不能为空'
            } else if (value.trim().length > 100) {
              return '输入字数不能超过100'
            }
          } else {
            return '输入不能为空'
          }
        }
      }).then(({ value }) => {
        if (value) {
          const params = {
            id: row.id,
            checkStatus: '2',
            checkRejectReason: value.trim()
          }
          monitorCheck(params).then(response => {
            if (response.code === 200) {
              this.$message.success('监察驳回成功')
              this.fetchData()
            }
          })
        }
      }).catch(() => {
      })
    },
    // 更换页码等
    changePage(listQuery) {
      this.listQuery = listQuery
      this.fetchData()
    }
  }
}
</script>
