<template>
  <div class="bbsl-common-page">
    <!--查询-->
    <div class="bbsl-table-search">
      <el-form v-model="queryParam" :inline="true">
        <el-row :gutter="10">
          <el-col :span="6">
            <el-form-item label="水库名称">
              <el-select
                style="width: 100%"
                size="mini"
                v-model="queryParam.params.rscd"
                clearable
                placeholder="请选择水库名称"
              >
                <el-option
                  v-for="item in rscds"
                  :key="item.id"
                  :label="item.rsnm"
                  :value="item.rscd"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="巡检日期">
              <el-date-picker
                v-model="scopeTime"
                style="width:250px"
                size="mini"
                type="daterange"
                clearable
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item>
              <el-button
                type="primary"
                icon="el-icon-search"
                size="mini"
                @click="onClickSearch"
                >搜索</el-button
              >
              <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
                >重置</el-button
              >
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <!--表单-->
    <div class="bbsl-table-content" ref="contentPanel">
      <div class="bbsl-btn-content" ref="btnPanel"></div>
      <el-table
        stripe
        size="mini"
        :height="tableMaxHeight"
        :style="{width: '100%'}"
        ref="multipleSelection"
        v-loading="loading"
        border
        :row-key="getRowKey"
        :data="tableData"
        :header-cell-style="{'text-align': 'center'}"
        :cell-style="{'text-align': 'center'}"
      >
        <el-table-column fixed label="序号" type="index" width="50">
        </el-table-column>
        <el-table-column
          fixed
          sortable
          prop="rsnm"
          label="水库名称"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          fixed
          sortable
          prop="count"
          label="巡检总次数"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          fixed
          sortable
          prop="abnormalCount"
          label="异常次数"
          show-overflow-tooltip
        ></el-table-column>
      </el-table>
      <el-pagination
        ref="paginationPanel"
        align="right"
        class="bbsl-pagination"
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryParam.pageBean.page"
        :page-sizes="[20, 30, 40, 50]"
        :page-size="queryParam.pageBean.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      ></el-pagination>
    </div>
  </div>
</template>

<script>
import dsmInsInin from '@/api/resIns/dsmInsInin.js'
import {TableMixin} from '@/mixins/tableMixin'
export default {
  mixins: [TableMixin],
  data() {
    return {
      //数据
      queryParam: {
        params: {
          rscd: '' //水库编码
          // count: 0, //巡检总次数
          // abnormalCount: null, //异常次数
        },
        pageBean: {
          pageSize: 20,
          page: 1
        }
      },
      intps: [
        {name: '日常巡视检查', value: 1},
        {name: '年度巡视检查', value: 2},
        {name: '特别巡视检查', value: 3}
      ], //巡检类别数组
      isNormals: [
        {name: '正常', value: 1},
        {name: '异常', value: 2}
      ], //是否正常
      tableData: [], //数据
      rscds: [], //水库名称数组
      total: 0, //总数据
      scopeTime: '' //时间范围
    }
  },
  created() {
    this.getDateList()
    //获取水库下拉
    dsmInsInin.getResName({}, res => {
      console.log(res)
      this.rscds = res.value
    })
  },
  methods: {
    getDateList() {
      this.loading = true
      this.tableData = []
      if (this.scopeTime) {
        let starTime = new Date(this.scopeTime[0])
        this.queryParam.params.startTime =
          starTime.getFullYear() +
          '-' +
          (starTime.getMonth() + 1) +
          '-' +
          starTime.getDate()
        let endTime = new Date(this.scopeTime[1])
        this.queryParam.params.endTime =
          endTime.getFullYear() +
          '-' +
          (endTime.getMonth() + 1) +
          '-' +
          endTime.getDate()
      }

      dsmInsInin.statisticsList(this.queryParam, res => {
        if (res.state) {
          this.tableData = res.value.rows
          // console.log(res.value)
          this.tableData.forEach(item => {
            this.intps.forEach(ii => {
              if (item['intp'] == ii.value) {
                item['intp'] = ii.name
              }
            })
            this.isNormals.forEach(ss => {
              console.log()
              if (item['isNormal'] == ss.value) {
                item['isNormal'] = ss.name
              }
            })
          })
          this.$set(this.tableData, this.tableData)
          // this.total = res.value.total
          this.loading = false
        } else {
          this.$message(res.message)
        }
      })
    },
    // // 点击查询
    onClickSearch() {
      this.queryParam.pageBean.page = 1
      this.getDateList()
    },
    // 重置
    resetQuery() {
      this.queryParam.params = {}
      this.scopeTime = ''
      this.onClickSearch()
    },
    handleSizeChange(val) {
      this.queryParam.pageBean.pageSize = val
      this.getDateList()
    },
    handleCurrentChange(val) {
      this.queryParam.pageBean.page = val
      this.getDateList()
    },
    // // 指定一个key标识这一行的数据
    getRowKey(row) {
      return row.id
    }
  }
}
</script>

<style></style>
