<template>
    <div v-if="visible" class="popup-model station-model comp-container" style="z-index:999">
        <div class="station-title">
            <div :style="{'height': Alarm?'15px':'aotu'}">
                <el-button v-if="Alarm" type="danger" size="mini" @click="BatchProcess">批量处理</el-button>
            </div>{{ title }}
        </div>
        <i class="icon el-icon-close" @click="close"></i>
        <div class="station-content">

            <el-table :data="data" height="100%" stripe border size="mini" highlight-current-row
                @selection-change="handleSelectionChange">
                <el-table-column type="selection" width="40">
                </el-table-column>
                <el-table-column label="测站名称" align="center" prop="stnm" min-width='150' show-overflow-tooltip>
                </el-table-column>
                <el-table-column label="预警时间" align="center" prop="sendDate" min-width='120' show-overflow-tooltip>
                </el-table-column>
                <el-table-column label="实时数据" align="center" prop="currentValue" min-width='70' show-overflow-tooltip>
                </el-table-column>
                <el-table-column label="预警阈值" align="center" prop="warnVal" min-width='70' show-overflow-tooltip>
                </el-table-column>
                <el-table-column label="预警类型" align="center" prop="warnType" min-width='70' show-overflow-tooltip>
                </el-table-column>
                <el-table-column label="预警等级" align="center" prop="warnGrade" min-width='60' show-overflow-tooltip>
                    <template slot-scope="scope">
                        <span
                            :style="{color:scope.row.warnGrade=='危险'?'#ff9900':scope.row.warnGrade=='警戒'?'yellow':scope.row.warnGrade=='非常危险'?'red':''}">{{scope.row.warnGrade}}</span>
                    </template>
                </el-table-column>
            </el-table>
        </div>
    </div>
</template>

<script>
import dictUtils from '@/components/dict/DictSelectUtils.js'
import digitalReservoir from '@/api/frontScreen/digitalReservoir.js'
export default {
    name: 'stationsModel',
    data() {
        return {
            visible: false,
            title: '',
            data: [],
            column: [],
            Alarm: false,
            multipleSelection: [],
            params: {
                appTypeList: [],
                endTime: "",
                id: "",
                mpcd: "",
                periodTime: "",
                rscd: "",
                startTime: "",
                stcd: "",
                stlc: "",
                stnm: "",
                sttp: "ZZ",
                sttpList: [],
                usfl: ""
            },
            warningLevels: [], //预警等级
            warningTypes: []//预警类型
        }
    },
    created() {
        this.warningLevels = dictUtils.getDictItemsFromCache('yjdj') //预警等级
        this.warningTypes = dictUtils.getDictItemsFromCache('yjlx') //预警类型
    },
    watch: {
        Alarm(val) {
            console.log(val)
        },
    },

    methods: {
        open(WarningData) {
            console.log(WarningData);
            if (!!WarningData) {
                this.Alarm = true
            }
            this.data = WarningData
            this.data.forEach(ee => {
                this.warningLevels.forEach(el => {
                    if (ee.warnGrade == el.sequence) {
                        ee.warnGrade = el.name
                    }
                })
                this.warningTypes.forEach(el => {
                    if (ee.warnType == el.sequence) {
                        ee.warnType = el.name
                    }
                })

            })
            this.title = `所有报警信息详情`
            this.visible = true

        },
        handleSelectionChange(val) {
            this.multipleSelection = this.multipleSelection = val.map(item => {
                return item.id
            })
        },
        BatchProcess() {
            this.$confirm('此操作将关闭所选测站预警状态, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                digitalReservoir.updateStatus(this.multipleSelection, res => {
                    if (res.state) {
                        this.$message.success('处理成功')
                        this.$emit("getAllWarning")
                        this.close()
                    } else {
                        this.$message.error(res.$message)
                    }
                })
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消删除'
                });
            });
        },
        close() {
            this.visible = false
            this.$emit('close')
            if (this.Alarm) {
                this.$emit('Warning');
            }
        },
    },
}
</script>

<style lang="scss" scoped>
@import '../../../views/frontScreens/css/gisComp.scss';

.popup-model {
    width: 800PX;
    height: 350PX;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: rgba(0, 0, 0, 0.7);
    z-index: 99;
    border: 1px solid #d2d6dc;
    border-radius: 6px;
    color: #d3d4d7;
    padding: 20px;
    box-sizing: border-box;

    .el-icon-close {
        position: absolute;
        right: 6px;
        top: 6px;
        font-size: 20px;
        color: #f56c6c;
        cursor: pointer;
    }

    .station-title {
        display: flex;
        // text-align: center;
        font-size: 16px;
        height: 20px;
        line-height: 20px;
        font-weight: 700;
        margin-bottom: 16px;

        div {
            width: 43%;
        }
    }

    .station-content {
        height: calc(100% - 36px);
        width: 100%;
    }
}
</style>
