 <!-- 待办监察 -->
<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.title" :size="size" placeholder="事件标题" clearable/>
      </search-item>
    </search-area>
    <case-list-table :list-query="listQuery" :list="list" :total="total" :columns="columns" :list-loading="listLoading" @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="monitor(scope.row)">监察</el-button>
          </template>
        </el-table-column>
      </template>
    </case-list-table>
    <el-dialog :visible.sync="monitorDialogVisible" :close-on-click-modal="false" title="监察" append-to-body>
      <el-form ref="monitorForm" :model="monitorForm" :rules="monitorRules" label-width="auto">
        <el-form-item label="监察结果" prop="superviseResult">
          <el-input v-model="monitorForm.superviseResult" type="textarea"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancelDialog">取消</el-button>
        <el-button type="primary" @click="submitSupervise">确定</el-button>
      </div>
    </el-dialog>
  </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 { doMonitor, getMonitorList } from '@/api/caseMonitor'

export default {
  name: 'WaitForMonitor',
  components: { AppContainer, SearchArea, SearchItem, CaseListTable },
  data() {
    return {
      list: [],
      total: 0,
      listLoading: true, // 列表加载动画
      listQuery: {
        title: '', // 事件标题
        offset: 1,
        limit: 20,
        sort: '',
        order: ''
      }, // 筛选条件
      columns: [
        {
          text: '事件标题',
          value: 'title',
          align: 'center'
        },
        {
          text: '联系人',
          value: 'reporterName',
          align: 'center'
        },
        {
          text: '联系方式',
          value: 'reporterPhone',
          align: 'center'
        },
        {
          text: '处理状态',
          value: 'caseStatus',
          align: 'center'
        },
        {
          text: '创建时间',
          value: 'createTime',
          width: 90,
          align: 'center'
        },
        {
          text: '监察内容',
          value: 'superviseContent',
          align: 'center'
        },
        {
          text: '监察状态',
          value: 'superviseStatus',
          align: 'center'
        },
        {
          text: '监察结果',
          value: 'superviseResult',
          align: 'center'
        }
      ], // 显示列
      monitorDialogVisible: false,
      monitorForm: {
        id: '',
        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
      }
      getMonitorList(this.listQuery).then(response => {
        if (response.code === 200) {
          // response.data.rows = [
          //   {
          //     'title': '事件1',
          //     'reporterName': '张三',
          //     'reporterPhone': '15652360420',
          //     'caseStatus': '处理中',
          //     'superviseContent': '监察内容',
          //     'superviseType': '申请监察',
          //     'eorcName': '咨询',
          //     'caseTypeName': '咨询',
          //     'caseDetailTypeName': '垃圾处理',
          //     'createUserName': '王',
          //     'limitedTime': '2020-04-12 00:00:00',
          //     'createTime': '2020-03-12 00:00:00',
          //     'superviseStatus': '未监察',
          //     'superviseTime': '-',
          //     '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
        }
      })
    },
    // 监察
    monitor(row) {
      this.monitorForm.id = row.id
      this.monitorDialogVisible = true
    },
    // 更换页码等
    changePage(listQuery) {
      this.listQuery = listQuery
      this.fetchData()
    },
    // 监察
    submitSupervise() {
      this.$refs['monitorForm'].validate((valid) => {
        if (valid) {
          doMonitor(this.monitorForm).then(res => {
            this.$message.success('监察成功')
            this.fetchData()
            this.cancelDialog()
          }).catch((res) => {
            this.cancelDialog()
          })
        }
      })
    },
    // 取消弹窗
    cancelDialog() {
      this.monitorDialogVisible = false
      this.resetSuperviseForm()
    },
    // 重置
    resetSuperviseForm() {
      this.$refs['monitorForm'].resetFields()
      this.monitorForm = {
        id: '',
        superviseStatus: '1',
        superviseResult: ''
      }
    }
  }
}
</script>
