<template>
  <div class="bbsl-common-page"
       @click="commonPageClick">
    <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-input clearable
                        size="mini"
                        placeholder="请输入取水户名称"
                        v-model="queryParam.params.waterName"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="取水类型：">
              <el-select style="width: 100%"
                         size="mini"
                         v-model="queryParam.params.waterType"
                         clearable
                         placeholder="请选择取水类型">
                <el-option v-for="item in waterTypes"
                           :key="item.id"
                           :label="item.name"
                           :value="item.value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="7">
            <el-form-item label="上报时间">
              <el-date-picker @change="changeDate"
                              v-model="scopeTime"
                              style="width:230px"
                              size="mini"
                              value-format="yyyy-MM-dd"
                              type="daterange"
                              clearable
                              range-separator="至"
                              start-placeholder="开始日期"
                              end-placeholder="结束日期"></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <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>
        <div class="bbsl-search-more"
             style="width:250px"
             v-if="showMore">
          <el-row>
            <el-col :span="24">
              <el-form-item label="跨界类型">
                <el-select @change="changecrOverType"
                           size="medium"
                           v-model="queryParam.params.crOverType"
                           clearable
                           placeholder="请选择跨界类型">
                  <el-option v-for="item in crOverTypes"
                             :key="item.id"
                             :label="item.name"
                             :value="item.value"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
        </div>
      </el-form>
    </div>
    <div class="bbsl-table-content"
         ref="contentPanel">
      <div class="bbsl-btn-content"
           ref="btnPanel">
        <el-button size="mini"
                   icon="el-icon-plus"
                   type="primary"
                   @click="openFormDiao">新增</el-button>
        <el-button :disabled="!multipleSelection.length"
                   size="mini"
                   icon="el-icon-delete"
                   type="danger"
                   @click="deleteSelect">删除</el-button>
      </div>
      <el-table stripe
                size="mini"
                :height="tableMaxHeight"
                @row-dblclick="handleDbClick"
                ref="multipleSelection"
                v-loading="loading"
                border
                :data="tableData"
                style="width:100%"
                :row-key="getRowKey"
                @selection-change="handleSelectionChange"
                :header-cell-style="{'text-align': 'center'}"
                :cell-style="{'text-align': 'center'}">
        <el-table-column type="selection"
                         width="55"
                         :reserve-selection="true"></el-table-column>
        <el-table-column type="index"
                         width="55"
                         label="序号"></el-table-column>
        <el-table-column min-width="130"
                         sortable
                         prop="createTime"
                         label="上报时间"
                         show-overflow-tooltip></el-table-column>
        <el-table-column min-width="110"
                         sortable
                         prop="waterCode"
                         label="取水户编码"
                         show-overflow-tooltip></el-table-column>
        <el-table-column min-width="200"
                         sortable
                         prop="waterName"
                         label="取水户"
                         show-overflow-tooltip></el-table-column>

        <el-table-column min-width="120"
                         sortable
                         prop="waterTypeName"
                         label="取水类型"
                         show-overflow-tooltip></el-table-column>
        <el-table-column min-width="120"
                         sortable
                         prop="industryType"
                         label="行业类别"
                         show-overflow-tooltip></el-table-column>
        <el-table-column min-width="120"
                         sortable
                         prop="monitorLevelName"
                         label="监控级别"
                         show-overflow-tooltip></el-table-column>
        <!-- <el-table-column
		  min-width="180"
		  sortable
		  prop="addvcd"
		  label="行政区划"
		  show-overflow-tooltip
        ></el-table-column>-->
        <el-table-column min-width="120"
                         sortable
                         prop="waterLeader"
                         label="法人代表"
                         show-overflow-tooltip></el-table-column>
        <el-table-column min-width="120"
                         sortable
                         prop="officeTel"
                         label="电话"
                         show-overflow-tooltip></el-table-column>
        <el-table-column min-width="120"
                         fixed="right"
                         label="操作">
          <template #default="scope">
            <el-button @click="toWaterPapers(scope.row)">查看取水证</el-button>
          </template>
        </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>
    <form-dialog v-if="showFormDia"
                 @closeFormDiao="closeFormDiao"
                 @refList="getDateList"
                 :showFormDia="showFormDia"
                 :title="title"
                 :pId="pId"></form-dialog>
  </div>
</template>
<script>
import FormDialog from './components/wtForm-dialog.vue'
import waterCompany from '@/api/waterCompany.js'
import req from '@/request.js'
import { TableMixin } from '@/mixins/tableMixin'
export default {
  name: 'rvManager',
  components: {
    FormDialog
  },
  mixins: [TableMixin],
  data () {
    return {
      scopeTime: '',
      loading: false,
      multipleSelection: [], // 复选框
      queryParam: {
        pageBean: {
          pageSize: 20,
          page: 1
        },
        params: {
          basAdCode: null,
          waterName: null,
          waterType: null,
          startTime: null,
          endTime: null,
        }
      },
      total: 0,
      title: '',
      showFormDia: false,
      tableData: [],
      pId: '',
      errMessage: '',
      errorFileUrl: '',
      rvGrads: [], //河流级别数组
      rvTypes: [], //河流类型数组
      monitorLevels: [], //监控级别
      basAdNames: [], //行政区
      waterTypes: [], //取水类型
      lookDetailDia: false, // 详情弹层
      codes: { codes: 'gkglbm' },
      crOverTypes: [], //跨界类型
      basGrads: [], //流域级别
      banks: [],
      setKesLabel: {
        value: 'code',
        label: 'name',
        children: 'children'
      }
    }
  },
  computed: {},
  created () {
    this.getSysDict()
    this.getDateList()
    // 行政区查询
    waterCompany.getbasAdName({}, res => {
      this.basAdNames = res.value
    })
  },

  methods: {
    changeDate (val) {
      if (val) {
        this.queryParam.params.startTime = val[0]
        this.queryParam.params.endTime = val[1]
      } else {
        this.queryParam.params.startTime = ''
        this.queryParam.params.endTime = ''
      }
    },
    openMore () {
      this.showMore = !this.showMore
    },
    changecrOverType (val) {
      if (val) {
        this.queryParam.params.crOverType = val
      } else {
        this.queryParam.params.crOverType = null
      }
    },
    changervGrad (val) {
      if (val) {
        this.queryParam.params.rvGrad = val
      } else {
        this.queryParam.params.rvGrad = null
      }
    },
    changervType (val) {
      if (val) {
        this.queryParam.params.rvType = val
      } else {
        this.queryParam.params.rvType = null
      }
    },
    onhouChange (val) {
      if (val.length > 0) {
        this.queryParam.params.basAdCode = val.pop().toString()
      } else {
        this.queryParam.params.basAdCode = null
      }
    },
    //获取字典数据
    getSysDict () {
      let portal = window.context.portal
      return new Promise((resolve, reject) => {
        req.post(portal + '/sys/sysDictionary/v1/queryAllDictItems').then(
          response => {
            resolve(response.data)
            this.crOverTypes = response.data.kjlx
            this.rvGrads = response.data.hljb
            this.rvTypes = response.data.hllx
            this.banks = response.data.hlab
            this.waterTypes = response.data.qslx
            this.monitorLevels = response.data.jkjb
            this.getDateList()
          },
          error => {
            reject(error)
          }
        )
      })
    },
    getDateList () {
      // this.loading = true
      this.tableData = []
      waterCompany.ListGet(this.queryParam, res => {
        if (res.state) {
          this.total = res.value.total
          res.value.rows.forEach(ii => {
            this.monitorLevels.forEach(ee => {
              if (ee.value == ii.monitorLevel) {
                ii['monitorLevelName'] = ee.name
              }
            })
            this.waterTypes.forEach(ee => {
              if (ee.value == ii.waterType) {
                ii['waterTypeName'] = ee.name
              }
            })
          })
          this.tableData = res.value.rows
          this.loading = false
        }
      })
    },
    openFormDiao () {
      this.title = '新增'
      this.showFormDia = true
    },
    closeFormDiao () {
      this.showFormDia = false
      this.getDateList()
    },
    handleSizeChange (val) {
      this.queryParam.pageBean.pageSize = val
      this.getDateList()
    },
    handleCurrentChange (val) {
      this.queryParam.pageBean.page = val
      this.getDateList()
    },
    // // 修改
    handleUpdate (row) {
      this.title = '修改'
      this.pId = row.id
      this.showFormDia = true
    },
    handleSelectionChange (val) {
      this.multipleSelection = val.map(item => {
        return item.id
      })
    },
    // // 指定一个key标识这一行的数据
    getRowKey (row) {
      return row.id
    },
    // // 批量删除
    deleteSelect () {
      this.$confirm('确定删除选中数据？', '提示', {
        confirmButtonText: '确 定',
        cancelButtonText: '取 消',
        type: 'warning'
      })
        .then(() => {
          waterCompany
            .remove(this.multipleSelection, res => {
              if (res.state) {
                this.$notify({
                  type: 'success',
                  message: '删除成功',
                  duration: 2000
                  // offset: 80
                })
                // this.multipleSelection = [];
                this.$refs.multipleSelection.clearSelection()
                this.queryParam.pageBean.page = 1
                this.getDateList()
              }
            })
            .catch(res => {
              this.$notify({
                type: 'error',
                message: res.message,
                duration: 2000,
                offset: 80
              })
              this.getDateList()
            })
        })
        .catch(() => { })
    },
    /** 删除按钮操作 */
    handleDelete (row) {
      this.$confirm('确定删除选中数据？', '提示', {
        confirmButtonText: '确 定',
        cancelButtonText: '取 消',
        type: 'warning'
      })
        .then(() => {
          waterCompany
            .remove(row.id, res => {
              if (res.state) {
                this.$notify({
                  type: 'success',
                  message: '删除成功',
                  duration: 2000
                  // offset: 80
                })
                this.queryParam.pageBean.page = 1
                this.getDateList()
              }
            })
            .catch(res => {
              this.$notify({
                type: 'error',
                message: res.message,
                duration: 2000,
                offset: 80
              })
              this.getDateList()
            })
        })
        .catch(() => { })
    },
    // // 点击查询
    onClickSearch () {
      this.queryParam.pageBean.page = 1
      this.getDateList()
    },
    // 重置
    resetQuery () {
      this.queryParam.params = {}
      this.scopeTime = ''
      this.onClickSearch()
    },
    toWaterPapers (row) {
      console.log(row)
      this.$router.push({
        path: 'waterPaper',
        query: { id: row.id, waterName: row.waterName }
      })
    }
  }
}
</script>
<style lang="scss" scoped>
.btn-content {
  display: flex;
}
.el-select-dropdown__item span {
  color: rgb(51, 51, 51) !important;
}
.el-select-dropdown__item {
  color: #9a9a9a !important;
}
.el-select-dropdown__item.hover,
.el-select-dropdown__item:hover {
  background: #f5f7fa;
}
.btn-content :first-child {
  margin: 0 0 0 0 !important;
}
// ::v-deep .el-table__body-wrapper::-webkit-scrollbar {
//   width: 6px;
//   height: 15px;
// }
.sampling {
  ::v-deep .el-dialog__body {
    padding: 30px 20px 0 20px;
  }
}
::-webkit-scrollbar {
  background: #fff !important;
}

//滚动条的宽度
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
  background-color: #e4e4e4;
  border-radius: 6px;
}
//滚动条的滑块
::-webkit-scrollbar-thumb {
  background-color: #a1a3a9;
  border-radius: 6px;
}
.bbsl-pagination {
  bottom: 10px !important;
}
</style>
