 <!-- 审核督办 -->
<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-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 { superviseCheck, getCheckSuperviseList } from '@/api/caseSupervise'

export default {
  name: 'WaitCheckSupervise',
  components: { AppContainer, SearchArea, SearchItem, CaseListTable },
  data() {
    return {
      list: [],
      total: 0,
      timeRange: [], // 时间范围
      listLoading: true, // 列表加载动画
      listQuery: {
        urgeContent: '', // 事件标题
        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'
        // }
      ], // 显示列
      superviseDialogVisible: false,
      superviseForm: {
        caseId: '',
        urgeStatus: '1',
        urgeResult: ''
      },
      superviseRules: {
        urgeResult: [{ 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.startTime = this.timeRange[0]
        this.listQuery.endTime = this.timeRange[1]
      } else {
        this.listQuery.startTime = ''
        this.listQuery.endTime = ''
      }
      getCheckSuperviseList(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': '-'
          //   }
          // ]
          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'
        }
        superviseCheck(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()
          }
          superviseCheck(params).then(response => {
            if (response.code === 200) {
              this.$message.success('督办驳回成功')
              this.fetchData()
            }
          })
        }
      }).catch(() => {
      })
    },
    // 更换页码等
    changePage(listQuery) {
      this.listQuery = listQuery
      this.fetchData()
    }
  }
}
</script>
