<template>
    <div class="zhuwangjiancedianxianzhi">
        <div id="select-form">
            <el-form ref="form" inline>
                <el-form-item label="信息查询:">
                    <el-input v-model.trim="store.params.searchValue" placeholder="请输入查询信息" clearable></el-input>
                </el-form-item>
                <el-form-item label="监测点状态:">
                    <el-select v-model="store.params.monitorState" placeholder="请选择监测点状态" clearable class="select">
                        <el-option clearable v-for="item in monitorStateList" :key="item.id" :label="item.name"
                            :value="item.id"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="上送网公司监测点:">
                    <el-select v-model="store.params.isUpToGrid" placeholder="请选择上送网公司监测点" clearable class="select">
                        <el-option label="是" value="1"></el-option>
                        <el-option label="否" value="0"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item>
                    <el-button size="small" type="primary" icon="el-icon-search" @click="search">查询</el-button>
                </el-form-item>
                <el-form-item>
                    <el-button size="small" type="primary" icon="el-icon-upload2" @click="feed">上送网公司</el-button>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" icon="el-icon-download" @click="exportEvent">导出</el-button>
                </el-form-item>
            </el-form>
        </div>
        <div v-loading="store.loading">
            <vxe-table ref="table" stripe :height="tableHeight" :data="store.data" size="mini" highlight-current-row
                header-cell-class-name="table_header" style="width: 100%" border @checkbox-all="handleSelectionChange"
                @checkbox-change="handleSelectionChange">
                <vxe-table-column align="center" type="checkbox" width="55"></vxe-table-column>
                <vxe-table-column fixed="right" align="center" field="monitorUploadStatus" show-overflow-tooltip
                    title="上送状态" :min-width="130">
                    <template slot-scope="scope">
                        <el-tag type="primary" size="small" style="color: #409eff; background: #ecf5ff"
                            v-if="scope.row.monitorUploadStatus == 0">
                            未上送
                        </el-tag>
                        <el-tag type="primary" size="small" style="color: #67c23a; background: #f0f9eb"
                            v-if="scope.row.monitorUploadStatus == 1">
                            已上送
                        </el-tag>
                        <el-tag type="primary" size="small" style="color: #909399; background: #f4f4f5"
                            v-if="scope.row.monitorUploadStatus == 2">
                            取消上送
                        </el-tag>
                        <el-tag type="primary" size="small" style="color: orange; background: #f4f4f5"
                            v-if="scope.row.monitorUploadStatus == 3">
                            待重新上送
                        </el-tag>
                    </template>
                </vxe-table-column>
                <vxe-table-column align="center" v-for="(item, index) in tableColumn" :field="item.prop"
                    :title="item.label" :min-width="item.width" :show-overflow="true" :key="index"></vxe-table-column>
            </vxe-table>
            <el-pagination background align="right" @size-change="handleSizeChange"
                @current-change="handleCurrentChange" :current-page="store.params.pageNum"
                :page-sizes="[20, 30, 40, 50, 130]" :page-size="store.params.pageSize"
                layout="total, sizes, prev, pager, next, jumper" :total="store.total" class="mt10"></el-pagination>
        </div>
    </div>
</template>
<script>
import list from '@/mixins/list'
import Area from '@/views/components/Area/Area.vue'
import { dicData } from '@/assets/commjs/dictypeData'
import request from '@/utils/request'
import { getGeneratrixWirePageList } from '@/api/hbaccountoperation/RouteTable'

export default {
    components: { Area },
    mixins: [list],
    data() {
        return {
            isLoading: false,
            multipleSelection: [],
            voltageLevelOptions: [],
            monitorStateList: [], //监测点状态
            tableColumn: [
                { label: '单位名称', prop: 'orgName', width: 200 },
                { label: '监测点名称', prop: 'monitorName', width: 200 },
                { label: '监测点编号', prop: 'monitorId', width: 200 },
                { label: '当前的电压的等级', prop: 'voltage', width: 200 },
                { label: 'CT变比', prop: 'ct', width: 100 },
                { label: 'PT变比', prop: 'pt', width: 100 },
                { label: '电压偏差上限', prop: 'voldelimiteUp', width: 150 },
                { label: '电压偏差下限', prop: 'voldelimiteLow', width: 150 },
                { label: '长闪变限值', prop: 'pltLimit', width: 120 },
                { label: '频率限值', prop: 'freqLimit', width: 120 },
                { label: '频率偏差上限', prop: 'ratedeLimiteUp', width: 150 },
                { label: '频率偏差下限', prop: 'ratedeLimiteDown', width: 150 },
                { label: '电压总谐波畸变率限值', prop: 'vthdLimit', width: 200 },
                { label: '电压波动限值', prop: 'flucLimit', width: 150 },
                { label: '电压偏差限值', prop: 'deltaLimit', width: 150 },
                { label: '三相电压不平衡度限值', prop: 'vunbanLimit', width: 200 },
                { label: '奇次谐波电压含有率限值', prop: 'oddHamVPerate', width: 200 },
                { label: '偶次谐波电压含有率限值', prop: 'eveHamVPerate', width: 200 },
                { label: '0.5-1.5次间谐波电压限值', prop: 'harmonicVoltageLimit2', width: 200 },
                { label: '2.5-15.5次间谐波电压限值', prop: 'harmonicVoltageLimit3to16', width: 220 },
                { label: '短时负序电压不平衡度限值', prop: 'shortNegatiVUnbalan_limit', width: 220 },
                { label: '正常负序电压不平衡度限值', prop: 'normNegatiVUnbalanLimit', width: 220 },
                { label: '负序电流不平衡度CP95限值', prop: 'negatiCUnbalanCp95', width: 200 },
                { label: '负序电流不平衡度最大值限值', prop: 'negatiCUnbalanMax', width: 220 },
                { label: '2次谐波电流限值', prop: 'i2Limit', width: 150 },
                { label: '3次谐波电流限值', prop: 'i3Limit', width: 150 },
                { label: '4次谐波电流限值', prop: 'i4Limit', width: 150 },
                { label: '5次谐波电流限值', prop: 'i5Limit', width: 150 },
                { label: '6次谐波电流限值', prop: 'i6Limit', width: 150 },
                { label: '7次谐波电流限值', prop: 'i7Limit', width: 150 },
                { label: '8次谐波电流限值', prop: 'i8Limit', width: 150 },
                { label: '9次谐波电流限值', prop: 'i9Limit', width: 150 },
                { label: '10次谐波电流限值', prop: 'i10Limit', width: 150 },
                { label: '11次谐波电流限值', prop: 'i11Limit', width: 150 },
                { label: '12次谐波电流限值', prop: 'i12Limit', width: 150 },
                { label: '13次谐波电流限值', prop: 'i13Limit', width: 150 },
                { label: '14次谐波电流限值', prop: 'i14Limit', width: 150 },
                { label: '15次谐波电流限值', prop: 'i15Limit', width: 150 },
                { label: '16次谐波电流限值', prop: 'i16Limit', width: 150 },
                { label: '17次谐波电流限值', prop: 'i17Limit', width: 150 },
                { label: '18次谐波电流限值', prop: 'i18Limit', width: 150 },
                { label: '19次谐波电流限值', prop: 'i19Limit', width: 150 },
                { label: '20次谐波电流限值', prop: 'i20Limit', width: 150 },
                { label: '21次谐波电流限值', prop: 'i21Limit', width: 150 },
                { label: '22次谐波电流限值', prop: 'i22Limit', width: 150 },
                { label: '23次谐波电流限值', prop: 'i23Limit', width: 150 },
                { label: '24次谐波电流限值', prop: 'i24Limit', width: 150 },
                { label: '25次谐波电流限值', prop: 'i25Limit', width: 150 },
                { label: '26次谐波电流限值', prop: 'i26Limit', width: 150 },
                { label: '27次谐波电流限值', prop: 'i27Limit', width: 150 },
                { label: '28次谐波电流限值', prop: 'i28Limit', width: 150 },
                { label: '29次谐波电流限值', prop: 'i29Limit', width: 150 },
                { label: '30次谐波电流限值', prop: 'i30Limit', width: 150 },
                { label: '31次谐波电流限值', prop: 'i31Limit', width: 150 },
                { label: '32次谐波电流限值', prop: 'i32Limit', width: 150 },
                { label: '33次谐波电流限值', prop: 'i33Limit', width: 150 },
                { label: '34次谐波电流限值', prop: 'i34Limit', width: 150 },
                { label: '35次谐波电流限值', prop: 'i35Limit', width: 150 },
                { label: '36次谐波电流限值', prop: 'i36Limit', width: 150 },
                { label: '37次谐波电流限值', prop: 'i37Limit', width: 150 },
                { label: '38次谐波电流限值', prop: 'i38Limit', width: 150 },
                { label: '39次谐波电流限值', prop: 'i39Limit', width: 150 },
                { label: '40次谐波电流限值', prop: 'i40Limit', width: 150 },
                { label: '41次谐波电流限值', prop: 'i41Limit', width: 150 },
                { label: '42次谐波电流限值', prop: 'i42Limit', width: 150 },
                { label: '43次谐波电流限值', prop: 'i43Limit', width: 150 },
                { label: '44次谐波电流限值', prop: 'i44Limit', width: 150 },
                { label: '45次谐波电流限值', prop: 'i45Limit', width: 150 },
                { label: '46次谐波电流限值', prop: 'i46Limit', width: 150 },
                { label: '47次谐波电流限值', prop: 'i47Limit', width: 150 },
                { label: '48次谐波电流限值', prop: 'i48Limit', width: 150 },
                { label: '49次谐波电流限值', prop: 'i49Limit', width: 150 },
                { label: '50次谐波电流限值', prop: 'i50Limit', width: 150 }
            ]
        }
    },
    created() {
        this.init()
        this.voltageLevelOptions = dicData('Dev_Voltage', [])
        this.monitorStateList = dicData('Line_State', [])
    },
    mounted() {
        this.setHeight()
        window.addEventListener('resize', this.setHeight)
    },
    beforeDestroy() {
        window.removeEventListener('resize', this.setHeight)
    },
    methods: {
        setHeight() {
            this.tableHeight = window.sessionStorage.getItem('appheight') - 170
        },
        search() {
            this.store.loading = true
            this.store.params.pageNum = 1
            this.store.params.pageSize = 20
            this.store.search()
        },
        //导出
        exportEvent() {
            this.store.export(data => {
                this.$refs.table.exportData({
                    filename: 'export', // 文件名字
                    sheetName: 'Sheet1',
                    type: 'xlsx', //导出文件类型 xlsx 和 csv
                    useStyle: true,
                    data, // 数据源
                    columnFilterMethod: function (column, $columnIndex) {
                        return !(column.$columnIndex === 0)
                    }
                })
            })
        },
        handleSelectionChange({ records }) {
            console.log(records)
            this.multipleSelection = records.map(item => item.id)
        },
        feed() {
            if (this.multipleSelection.length === 0) {
                this.$confirm('是否上送全部监测点?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    this.store.loading = true
                    request
                        .post('/device-boot/gwTerminalPush/pushMonitorOverLimit', [])
                        .then(res => {
                            if (res && res.code == 'A0000') {
                                this.$message({
                                    message: '上送成功!',
                                    type: 'success'
                                })
                                this.multipleSelection = []
                                this.store.search()
                            }

                            this.store.loading = false
                        })
                        .catch(err => {
                            this.store.loading = false
                        })
                })
            } else {
                this.store.loading = true
                request
                    .post('/device-boot/gwTerminalPush/pushMonitorOverLimit', this.multipleSelection)
                    .then(res => {
                        if (res && res.code == 'A0000') {
                            this.$message({
                                message: '上送成功!',
                                type: 'success'
                            })
                            this.multipleSelection = []
                            this.store.search()
                        }

                        this.store.loading = false
                    })
                    .catch(err => {
                        this.store.loading = false
                    })
            }
        },
        init() {
            this.store = this.dataSource('/device-boot/gwTerminalPush/queryMonitorOverLimit')
            this.store.params.searchValue = ''
            this.store.loadCallback = () => {
                this.store.data.forEach(item => {
                    for (let key in item) {
                        if (item[key] === null || item[key] === '') {
                            item[key] = '/'
                        } else if (item[key] === 3.1415926) {
                            item[key] = '暂无数据'
                        }
                        if (key === 'voltage') {
                            item[key] =
                                this.voltageLevelOptions.find(item2 => item2.value === item[key]) &&
                                this.voltageLevelOptions.find(item2 => item2.value === item[key]).label
                        }
                        //  else if (key === 'monitorUploadStatus') {
                        //     // 0.未上送 1.上送 2.取消上送 3.待重新上送（用于主网监测点）
                        //     switch (item[key]) {
                        //         case 0:
                        //             item[key] = '未上送'
                        //             break
                        //         case 1:
                        //             item[key] = '上送'
                        //             break
                        //         case 2:
                        //             item[key] = '取消上送'
                        //             break
                        //         case 3:
                        //             item[key] = '待重新上送'
                        //             break
                        //         default:
                        //             break
                        //     }
                        // }
                    }
                })
            }
            this.store.reload()
        }
    }
}
</script>
