<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
                                size="mini"
                                filterable
                                :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="5">
                        <el-form-item label="测点名称">
                            <el-select
                                style="width: 180px"
                                size="mini"
                                v-model="queryParam.params.stcd"
                                clearable
                                filterable
                                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="8">
                        <el-form-item label="降雨日期">
                            <el-date-picker
                                size="mini"
                                @change="changeDate"
                                value-format="yyyy-MM-dd HH:mm:ss"
                                style="width: 300px"
                                v-model="dates"
                                type="datetimerange"
                                start-placeholder="开始日期"
                                end-placeholder="结束日期"
                                :default-time="['12:00:00', '12:00:00']"
                            >
                            </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>
            </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
                :data="tableData"
                :header-cell-style="{'text-align': 'center'}"
                :cell-style="{'text-align': 'center'}"
                :default-sort="{prop: 'drp', order: 'descending'}"
            >
                <el-table-column
                    fixed
                    type="index"
                    width="55"
                    label="序号"
                ></el-table-column>
                <el-table-column
                    fixed
                    min-width="80"
                    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="140"
          sortable
          prop="stlc"
          label="测站地址"
          show-overflow-tooltip
        >
        </el-table-column> -->
                <el-table-column
                    min-width="220"
                    sortable
                    prop="areaName"
                    label="行政区划"
                    show-overflow-tooltip
                ></el-table-column>
                <el-table-column
                    min-width="120"
                    sortable
                    prop="drp"
                    label="累计降雨量(mm)"
                    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, 100, 200]"
                :page-size="queryParam.pageBean.pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total"
            ></el-pagination>
        </div>
    </div>
</template>
<script>
import sdYlQuery from '@/api/monitor/resMonitor/sdYlQuery.js'
import {TableMixin} from '@/mixins/tableMixin'
import req from '@/request.js'
export default {
    name: 'displacement',
    components: {},
    mixins: [TableMixin],
    data() {
        return {
            dates: null,
            total: 0,
            tableData: [],
            loading: false,
            basAdNames: [], //行政区
            yjdjs: [],
            statuss: [
                {name: '在线', value: '1'},
                {name: '不在线', value: '0'},
            ],
            multipleSelection: [], // 复选框
            stnms: [], //测站下拉
            setKesLabel: {
                value: 'code',
                label: 'name',
                children: 'children',
            },
            queryParam: {
                pageBean: {
                    pageSize: 200,
                    page: 1,
                },
                params: {
                    startTime: null,
                    endTime: null,
                    stcd: null,
                    addvcd: null,
                },
            },
        }
    },
    created() {
        this.getTimes()
        this.getSysDict()
    },
    methods: {
        getTimes() {
            let date = new Date() //1. js获取当前时间
            let min = date.getMinutes() //2. 获取当前分钟
            date.setMinutes(min - 5) //3. 设置当前时间-5分钟：把当前分钟数+5后的值重新设置为date对象的分钟数
            let y = date.getFullYear()
            let m =
                date.getMonth() + 1 < 10
                    ? '0' + (date.getMonth() + 1)
                    : date.getMonth() + 1
            let d = date.getDate() < 10 ? '0' + date.getDate() : date.getDate()
            let h =
                date.getHours() < 10 ? '0' + date.getHours() : date.getHours()
            let f =
                date.getMinutes() < 10
                    ? '0' + date.getMinutes()
                    : date.getMinutes()
            let s =
                date.getSeconds() < 10
                    ? '0' + date.getSeconds()
                    : date.getSeconds()
            this.queryParam.params.startTime =
                y + '-' + m + '-' + (d - 1) + ' ' + h + ':' + f + ':' + s
            var moment = require('moment') //打开时默认时间为一天前至获取当前年月日时分秒
            var _today = moment()
            let endTime = moment().format('L') //当前年月日
            let time = moment().format('LTS') //当前时分秒
            endTime = endTime.replace(/\//g, '-')
            this.queryParam.params.endTime = endTime + ' ' + time
        },
        changeDate(val) {
            console.log(val, 999)
            if (val) {
                this.queryParam.params.startTime = val[0]
                this.queryParam.params.endTime = val[1]
            } else {
                this.queryParam.params.startTime = ''
                this.queryParam.params.startTime = ''
            }
        },
        onhouChange(val) {
            if (val) {
                this.queryParam.params.addvcd = val[val.length - 1]
            } else {
                this.queryParam.params.addvcd = null
            }
        },
        getDateList() {
            this.loading = true
            this.tableData = []
            sdYlQuery.ListGet(this.queryParam, (res) => {
                this.total = res.value.total
                let data = JSON.parse(JSON.stringify(res.value.rows))
                data.forEach((item) => {
                    if (item.drp == undefined) item.drp = null
                })
                this.tableData = data
                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
            })
        },
        //获取字典数据
        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)
                        })
                        sdYlQuery.getbasAdName({}, (res) => {
                            this.basAdNames = res.value
                        })
                        sdYlQuery.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;
}
.bbsl-pagination {
  bottom: 10px !important;
}
</style>
