<template>
  <app-container>
    <search-area :need-clear="true" :need-search-more="false" type="seperate" search-more-type="default" @search="search" @clear="clearInput">
      <!--一般查询条件-->
      <search-item>
        <el-input v-model.trim="listQuery.caseId" size="small" placeholder="事件编号" clearable/>
      </search-item>
      <search-item/>
      <search-item>
        <el-input v-model.trim="listQuery.title" size="small" placeholder="事件标题" clearable/>
      </search-item>
      <search-item>
        <el-input v-model.trim="listQuery.description" size="small" placeholder="事件内容" clearable/>
      </search-item>
      <search-item>
        <el-input v-model.trim="listQuery.reporterPhone" size="small" placeholder="联系方式" clearable/>
      </search-item>
      <search-item>
        <el-input v-model.trim="listQuery.reporterPhone" size="small" placeholder="催办内容" clearable/>
      </search-item>
      <search-item>
        <el-date-picker
          v-model="timeRange"
          type="datetimerange"
          size="small"
          range-separator="至"
          value-format="yyyy-MM-dd HH:mm:ss"
          start-placeholder="催办开始时间"
          end-placeholder="催办结束时间"/>
      </search-item>
    </search-area>
    <normal-table :data="list" :head="tableOption.head" :query="listQuery" :total="total" :columns="columns" :list-loading="listLoading" :options="tableOption.options" :tools-option="tableOption.toolsOption" @change="changePage">
      <template slot="columns">
        <el-table-column label="操作" align="center" width="100">
          <template slot-scope="scope">
            <el-button type="text" size="small" @click.stop="goDetail(scope.row)">详情</el-button>
          </template>
        </el-table-column>
      </template>
    </normal-table>
  </app-container>
</template>

<script>
import NormalTable from '@/components/NomalTable'
import AppContainer from '@/components/layout/AppContainer'
import SearchArea from '@/components/SearchArea/SearchArea'
import SearchItem from '@/components/SearchArea/SearchItem'
import { getUrgeList } from '@/api/caseUrge'
export default {
  name: 'UrgeList',
  components: { SearchItem, SearchArea, AppContainer, NormalTable },
  data() {
    return {
      listQuery: {
        caseId: '', // 事件编号
        title: '', // 事件标题
        description: '', // 事件内容
        reporterPhone: '', // 联系方式
        urgeContent: '', // 申请状态
        startTime: '', // 催办开始时间
        endTime: '', // 催办结束时间
        offset: 1,
        limit: 20,
        sort: 'urgeTime',
        order: 'desc'
      }, // 筛选条件
      timeRange: [],
      columns: [
        {
          text: '事件标题',
          value: 'title',
          align: 'center',
          showOverflow: true
        },
        {
          text: '催办内容',
          value: 'urgeContent',
          align: 'center',
          width: 160
        },
        {
          text: '催办人',
          value: 'urgeUserName',
          align: 'center'
        },
        {
          text: '催办时间',
          value: 'urgeTime',
          align: 'center',
          width: 160
        },
        {
          text: '当前处理状态',
          value: 'nowStateName',
          align: 'center'
        }
      ], // 显示列
      list: [], // 列表数据
      total: 0, // 数据总数
      listLoading: true, // 列表加载动画
      tableOption: {
        head: {
          show: false, // 是否需要标题栏，
          text: '数据列表' // 标题名称
        },
        options: {
          needIndex: false // 是否需要序号列
        },
        toolsOption: {
          selectColumns: false, // 是否需要筛选列
          refresh: false // 是否需要刷新按钮
        }
      } // 表格属性
    }
  },
  watch: {
    timeRange(val) {
      if (val && val.length > 0) {
        this.listQuery.startTime = val[0]
        this.listQuery.endTime = val[1]
      } else {
        this.listQuery.startTime = ''
        this.listQuery.endTime = ''
      }
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    search() {
      this.listQuery.offset = 1
      this.fetchData()
    },
    fetchData() {
      this.listLoading = true
      getUrgeList(this.listQuery).then(res => {
        this.list = res.data.rows
        this.total = res.data.total
        this.listLoading = false
      })
    },
    // 页数发生变化后的操作，可能是页码变化，可能是每页容量变化，此函数必写
    changePage(val) {
      if (val && val.size) {
        this.listQuery.limit = val.size
      }
      if (val && val.page) {
        this.listQuery.offset = val.page
      }
      this.fetchData()
    },
    // 重置后的操作， 若不需要显示重置按钮则不需要写
    clearInput() {
      this.listQuery.caseId = ''
      this.listQuery.title = ''
      this.listQuery.description = ''
      this.listQuery.reporterPhone = ''
      this.listQuery.applyState = ''
      // this.listQuery = {
      //   caseId: '', // 事件编号
      //   title: '', // 事件标题
      //   description: '', // 事件内容
      //   reporterPhone: '', // 联系方式
      //   applyState: '',
      //   offset: 1,
      //   limit: 20,
      //   sort: 'applyTime',
      //   order: 'desc'
      // }
    },
    // 查看详情
    goDetail(row) {
      this.$router.push({
        path: '/caseDetail/' + row.caseId,
        query: {
          showProcess: false
        }
      })
    }
  }
}
</script>

<style scoped>

</style>
