<template>
  <div>
    <case-list
      v-loading="listLoading"
      :case-list="caseList"
      :total="total"
      :list-query="listQuery"
      :table-columns="tableColumns"
      @changeQuery="changeQuery"
      @addDetail="showDetail"/>
  </div>
</template>

<script>
import CaseList from '@/components/CaseCommon/caseList'
import CaseDetailRead from '@/components/CaseCommon/caseDetailRead'
import { deptAssessCaseList } from '@/api/assess/assessDept'

export default {
  name: 'AssessDeptCaseList',
  components: { CaseList, CaseDetailRead },
  data() {
    return {
      caseList: [], // 案卷列表// ，传递给子组件
      tableColumns: [
        {
          text: '案卷编号',
          value: 'caseCode'
        },
        {
          text: '案卷类别',
          value: 'caseType'
        },
        {
          text: '节点名称',
          value: 'nodeName'
        },
        {
          text: '案卷描述',
          value: 'caseDesc'
        },
        {
          text: '大类',
          value: 'caseMajorcategory'
        },
        {
          text: '小类',
          value: 'caseSubcategory'
        },
        {
          text: '发生地点',
          value: 'casePoint'
        },
        {
          text: '限制完成时间',
          value: 'nodeTime',
          width: 160
        }],
      listQuery: {
        begTime: '',
        endTime: '',
        caseType: '',
        departmentId: '',
        offset: 1,
        limit: 20,
        sort: 'caseid',
        order: 'desc'
      }, // 筛选条件
      total: 0,
      listLoading: true // 加载动画
    }
  },
  mounted() {
    this.listQuery.begTime = this.$route.query.begTime
    this.listQuery.endTime = this.$route.query.endTime
    this.listQuery.caseType = this.$route.query.caseType
    this.listQuery.depId = this.$route.query.departmentId
    this.fetchData()
  },
  activated() {
    this.listQuery.begTime = this.$route.query.begTime
    this.listQuery.endTime = this.$route.query.endTime
    this.listQuery.caseType = this.$route.query.caseType
    this.listQuery.depId = this.$route.query.departmentId
    this.fetchData()
  },
  methods: {
    // 获取数据
    fetchData() {
      this.listLoading = true
      // 根据不同类型，调用不同的接口
      deptAssessCaseList(this.listQuery).then(res => {
        this.caseList = res.data.rows
        this.total = parseInt(res.data.total)
        this.listLoading = false
      })
    },
    // 来自caselist组件的查询条件(分页)更改后的查询
    changeQuery(listQuery) {
      this.listQuery = listQuery
      this.fetchData()
    },
    // 查看详情
    showDetail(tabPane, row) {
      // this.$router.push({ path: '/caseDetailRead/' + row.id })
      this.$router.push({
        name: 'CaseDetailRead',
        params: {
          id: row.id
        }
      })
    }
  }
}
</script>
