<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-cascader
                clearable
                filterable
                size="mini"
                :options="basAdNames"
                v-model="queryParam.params.addvcd"
                :props="setKesLabel"
                @change="onhouChange"
              >
                <template slot-scope="{node, data}">
                  <span>{{ data.name }}</span>
                  <span v-if="!node.isLeaf">
                    ({{ data.children === [] ? '' : data.children.length }})
                  </span>
                </template>
              </el-cascader>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="水库名称">
              <el-select
                size="mini"
                filterable
                v-model="queryParam.params.rscd"
                clearable
                placeholder="请选择水库名称"
              >
                <el-option
                  v-for="item in rsnms"
                  :key="item.id"
                  :label="item.rsnm"
                  :value="item.rscd"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="测点名称">
              <el-select
                size="mini"
                filterable
                v-model="queryParam.params.stcd"
                clearable
                placeholder="请选择测点名称"
              >
                <el-option
                  v-for="item in stnms"
                  :key="item.id"
                  :label="item.mpnm"
                  :value="item.mpcd"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <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-button type="text" @click.stop="openMore"
                >更多
                <i
                  :class="showMore ? 'el-icon-arrow-up' : 'el-icon-arrow-down'"
                ></i
              ></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
                  size="mini"
                  v-model="queryParam.params.wkcn"
                  clearable
                  placeholder="请选择在线状态"
                >
                  <el-option
                    v-for="item in statuss"
                    :key="item.value"
                    :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
          :disabled="!multipleSelection.length"
          size="mini"
          icon="el-icon-delete"
          type="danger"
          @click="deleteSelect"
          >删除</el-button
        > -->
      </div>
      <!-- 
        @selection-change="handleSelectionChange" 
        :row-key="getRowKey"-->
      <el-table
        stripe
        size="mini"
        :height="tableMaxHeight"
        :style="{width: '100%'}"
        ref="multipleSelection"
        v-loading="loading"
        border
        :data="tableData"
        :header-cell-style="{'text-align': 'center'}"
        :cell-style="{'text-align': 'center'}"
      >
        <el-table-column
          fixed
          type="index"
          width="55"
          label="序号"
        ></el-table-column>
        <el-table-column
          min-width="130"
          fixed
          sortable
          prop="stnm"
          label="测站名称"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          fixed
          min-width="140"
          sortable
          prop="stcd"
          label="测站代码"
          show-overflow-tooltip
        >
        </el-table-column>
        <el-table-column
          min-width="140"
          sortable
          prop="rsnm"
          label="水库名称"
          show-overflow-tooltip
        >
        </el-table-column>
        <el-table-column
          min-width="180"
          sortable
          prop="areaName"
          label="行政区划"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          min-width="150"
          sortable
          prop="rz"
          label="X向水平位移(mm)"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          min-width="150"
          sortable
          prop="inq"
          label="Y向水平位移(mm)"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          min-width="150"
          sortable
          prop="otq"
          label="垂直位移(mm)"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          min-width="150"
          sortable
          prop="otq"
          label="最新上报时间"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          min-width="150"
          sortable
          prop="thresholdStatus"
          label="是否达到阈值"
          show-overflow-tooltip
        >
          <template slot-scope="scope">
            <span v-if="scope.row.thresholdStatus === '1' || scope.row.thresholdStatus === 1">达到</span>
            <span v-if="scope.row.thresholdStatus === '0' || scope.row.thresholdStatus === 0">未达到</span>
            <span v-else>----</span>
          </template>
        </el-table-column>
        <el-table-column
          min-width="150"
          sortable
          prop="wkcn"
          label="在线状态"
          show-overflow-tooltip
        >
          <template slot-scope="scope">
            <span v-if="scope.row.wkcn === 1 || scope.row.wkcn === '1'">在线</span>
            <span v-if="scope.row.wkcn === 0 || scope.row.wkcn === '0'">不在线</span>
          </template>
        </el-table-column>
        <el-table-column
          fixed="right"
          min-width="150"
          sortable
          label="操作"
          show-overflow-tooltip
        >
          <template slot-scope="scope">
            <el-button
              size="mini"
              plain
              @click="openDate(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="[5, 10, 20, 50]"
        :page-size="queryParam.pageBean.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      ></el-pagination>
    </div>
  </div>
</template>
<script>
import wyQuery from '@/api/monitor/gqMonitor/wyQuery.js'
import {TableMixin} from '@/mixins/tableMixin'
import req from '@/request.js'
export default {
  name: 'displacement',
  components: {
    // FormDialog,
  },
  mixins: [TableMixin],
  data() {
    return {
      loading: false,
      basAdNames: [], //行政区
      statuss: [
        {name: '在线', value: '1'},
        {name: '不在线', value: '0'},
      ],
      multipleSelection: [], // 复选框
      rsnms: [], //水库下拉，
      stnms: [], //测站下拉
      setKesLabel: {
        value: 'code',
        label: 'name',
        children: 'children',
      },
      queryParam: {
        pageBean: {
          pageSize: 10,
          page: 1,
        },
        params: {
          rscd: null,
          stcd: null,
          addvcd: null,
          wkcn: null,
        },
      },
      rwptns:[],//水势
      showFormDia: false,
      tableData: [],
      pId: '',
      total: 0,
    }
  },
  created() {
    this.getSysDict()
  },
  methods: {
    openMore() {
      this.showMore = !this.showMore;
    },
    onhouChange(val) {
      if (val) {
        this.queryParam.params.addvcd = val[val.length - 1]
      } else {
        this.queryParam.params.addvcd = null
      }
    },
    openDate(val) {
      console.log(val)
    },
    getDateList() {
      this.loading = true
      this.tableData = []
      wyQuery.ListGet(this.queryParam, (res) => {
        this.total = res.value.total;
        this.tableData = JSON.parse(JSON.stringify(res.value.rows))
        this.$set(this.tableData)
        this.loading = false
      })
    },
    handleSizeChange(val) {
      this.queryParam.pageBean.pageSize = val
      this.getDateList()
    },
    handleCurrentChange(val) {
      this.queryParam.pageBean.page = val
      this.getDateList()
    },
    handleSelectionChange(val) {
      this.multipleSelection = val.map((item) => {
        return item.id
      })
    },
    // // 指定一个key标识这一行的数据
    // getRowKey(row) {
    //   return row.id
    // },
    //获取字典数据
    getSysDict() {
      let portal = window.context.portal
      return new Promise((resolve, reject) => {
        req.post(portal + '/sys/sysDictionary/v1/queryAllDictItems').then(
          (response) => {
            resolve(response.data)
            this.rwptns = response.data.ss;//水势
            wyQuery.getbasAdName({}, (res) => {
              this.basAdNames = res.value
            })
            wyQuery.getRsnm({}, (res) => {
              this.rsnms = res.value
            })
            wyQuery.getStnms({}, (res) => {
              this.stnms = res.value
            })
            this.getDateList()
          },
          (error) => {
            reject(error)
          }
        )
      })
    },
    // // 点击查询
    onClickSearch() {
      this.queryParam.pageBean.page = 1
      this.getDateList()
    },
    // 重置
    resetQuery() {
      this.queryParam.params = {}
      this.onClickSearch()
    },
  },
}
</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;
}
.el-switch__label--left {
  position: relative;
  left: 45px;
  color: #fff;
  z-index: -1111;
}
.el-switch__core {
  width: 50px !important;
}
.el-switch__label--right {
  position: relative;
  right: 46px;
  color: #fff;
  z-index: -1111;
}
.el-switch__label--right.is-active {
  z-index: 1111;
  color: #fff !important;
}
.el-switch__label--left.is-active {
  z-index: 1111;
  color: #9c9c9c !important;
}
.sampling {
  ::v-deep .el-dialog__body {
    padding: 30px 20px 0 20px;
  }
}
::-webkit-scrollbar {
  background: #fff !important;
}
</style>
