<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-input
                                size="mini"
                                clearable
                                placeholder="请输入测点名称"
                                v-model="queryParam.params.stnm"
                            ></el-input>
                        </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.stnm"
                                    :value="item.stcd"
                                ></el-option>
                            </el-select>
                        </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-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: 900px"
                    v-if="showMore"
                >
                    <el-row :gutter="10">
                        <el-col :span="8">
                            <el-form-item label="在线状态">
                                <el-select
                                    size="mini"
                                    v-model="queryParam.params.usfl"
                                    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-col :span="8">
                            <el-form-item label="应用分类">
                                <el-select
                                    size="mini"
                                    v-model="queryParam.params.appType"
                                    clearable
                                    placeholder="请选择应用分类"
                                >
                                    <el-option
                                        v-for="item in czyyfl"
                                        :key="item.value"
                                        :label="item.name"
                                        :value="item.value"
                                    ></el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="报警等级">
                                <el-select
                                    style="width: 100%"
                                    size="mini"
                                    v-model="queryParam.params.warnGrade"
                                    clearable
                                    placeholder="请选择报警等级"
                                >
                                    <el-option
                                        v-for="item in yjdjs"
                                        :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
          :disabled="!multipleSelection.length"
          size="mini"
          icon="el-icon-delete"
          type="danger"
          @click="deleteSelect"
          >删除</el-button
        >-->
            </div>
            <!-- 
        @selection-change="handleSelectionChange" 
      :row-key="getRowKey"-->
            <el-table
                :row-class-name="rowStyle"
                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
                    fixed
                    min-width="110"
                    sortable
                    prop="stcd"
                    label="测站代码"
                    show-overflow-tooltip
                ></el-table-column>
                <el-table-column
                    min-width="130"
                    fixed
                    sortable
                    prop="stnm"
                    label="测站名称"
                    show-overflow-tooltip
                ></el-table-column>
                <el-table-column
                    min-width="150"
                    fixed
                    sortable
                    prop="tm"
                    label="上报时间"
                    show-overflow-tooltip
                ></el-table-column>
                <!-- <el-table-column
          min-width="140"
          sortable
          prop="stlc"
          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="160"
                    sortable
                    prop="p1"
                    label="1小时降雨量(mm)"
                    show-overflow-tooltip
                ></el-table-column>
                <el-table-column
                    min-width="160"
                    sortable
                    prop="p3"
                    label="3小时降雨量(mm)"
                    show-overflow-tooltip
                ></el-table-column>
                <el-table-column
                    min-width="160"
                    sortable
                    prop="p6"
                    label="6小时降雨量(mm)"
                    show-overflow-tooltip
                ></el-table-column>
                <el-table-column
                    min-width="165"
                    sortable
                    prop="p12"
                    label="12小时降雨量(mm)"
                    show-overflow-tooltip
                ></el-table-column>
                <el-table-column
                    min-width="165"
                    sortable
                    prop="pd"
                    label="24小时降雨量(mm)"
                    show-overflow-tooltip
                ></el-table-column>

                <el-table-column
                    min-width="110"
                    sortable
                    prop="appTypeName"
                    label="应用分类"
                    show-overflow-tooltip
                ></el-table-column>
                <el-table-column
                    min-width="150"
                    sortable
                    prop="warnSd"
                    label="报警时段"
                    show-overflow-tooltip
                ></el-table-column>
                <el-table-column
                    min-width="150"
                    sortable
                    prop="warnVal"
                    label="报警时段阈值"
                    show-overflow-tooltip
                ></el-table-column>
                <el-table-column
                    min-width="110"
                    sortable
                    prop="level"
                    label="报警等级"
                    show-overflow-tooltip
                ></el-table-column>
                <!-- <el-table-column
          min-width="150"
          sortable
          prop="usfl"
          label="在线状态"
          show-overflow-tooltip
        >
          <template slot-scope="scope">
            <span v-if="scope.row.usfl === 1 || scope.row.usfl === '1'"
              >在线</span
            >
            <span v-if="scope.row.usfl === 0 || scope.row.usfl === '0'"
              >不在线</span
            >
            <span v-else>----</span>
          </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>
    </div>
</template>
<script>
import latestYqQuery from '@/api/monitor/resMonitor/latestYqQuery.js'
import dictUtils from '@/components/dict/DictSelectUtils.js'
import {TableMixin} from '@/mixins/tableMixin'
import req from '@/request.js'
export default {
    name: 'displacement',
    components: {},
    mixins: [TableMixin],
    data() {
        return {
            warnSds: [
                {
                    value: 'pn10',
                    warnSdMsg: '10分钟时段降水量',
                },
                {
                    value: 'pn30',
                    warnSdMsg: '30分钟时段降水量',
                },
                {
                    value: 'p1',
                    warnSdMsg: '1小时时段降水量',
                },
                {
                    value: 'p3',
                    warnSdMsg: '3小时时段降水量',
                },
                {
                    value: 'p6',
                    warnSdMsg: '6小时时段降水量',
                },
                {
                    value: 'p12',
                    warnSdMsg: '12小时时段降水量',
                },
                {
                    value: 'pd',
                    warnSdMsg: '24小时时段降水量',
                },
            ],
            total: 0,
            tableData: [],
            loading: false,
            basAdNames: [], //行政区
            yjdjs: [],
            statuss: [
                {name: '在线', value: '1'},
                {name: '不在线', value: '0'},
            ],
            multipleSelection: [], // 复选框
            stnms: [], //测站下拉
            setKesLabel: {
                value: 'code',
                label: 'name',
                children: 'children',
            },
            czyyfl: [],
            queryParam: {
                pageBean: {
                    pageSize: 20,
                    page: 1,
                },
                params: {
                    warnGrade: null,
                    stcd: null,
                    addvcd: null,
                    usfl: null,
                },
            },
        }
    },
    created() {
        this.czyyfl = dictUtils.getDictItemsFromCache('czyyfl')
        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
            }
        },
        getDateList() {
            this.loading = true
            this.tableData = []
            latestYqQuery.ListGet(this.queryParam, (res) => {
                this.total = res.value.total
                this.tableData = JSON.parse(JSON.stringify(res.value.rows))
                this.tableData.forEach((e) => {
                    this.warnSds.forEach((w) => {
                        if (e.warnSd == w.value) {
                            e.warnSd = w.warnSdMsg
                        }
                    })
                    this.yjdjs.forEach((c) => {
                        if (e.warnGrade == c.value) {
                            e.level = c.name
                        }
                    })
                    this.czyyfl.forEach((c) => {
                        if (e.appType == c.value) {
                            e.appTypeName = c.name
                        }
                    })
                })
                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()
        },
        rowStyle({row, rowIndex}) {
            if (row.warnGrade == '2') {
                return 'orange_class'
            } else if (row.warnGrade == '1') {
                return 'error_class'
            } else if (row.warnGrade == 3) {
                return 'success_class'
            }
            return ''
        },
        handleSelectionChange(val) {
            this.multipleSelection = val.map((item) => {
                return item.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.yjdjs = response.data.yjdj
                        response.data.yjdj.forEach((e) => {
                            this.yjdjs.value = Number(e.value)
                        })
                        latestYqQuery.getbasAdName({}, (res) => {
                            this.basAdNames = res.value
                        })
                        latestYqQuery.getStnms({}, (res) => {
                            console.log(res.value, 4545)
                            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">
.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;
}
.bbsl-pagination {
  bottom: 10px !important;
}
.success_class {
  td {
    div {
      color: red !important;
    }
  }
}
.orange_class {
  td {
    div {
      color: #FFAE00 !important;
    }
  }
}
.error_class{
  td {
    div {
      color: rgb(185, 185, 0) !important;
    }
  }
}
</style>
