<template>
    <el-form :inline="true" class="demo-form-inline form">
        <el-form-item>
            <Area @click="handleNodeClick" ref="orgId"></Area>
        </el-form-item>
        <el-form-item label="日期:">
            <el-radio-group v-model="dateType" @change="dateTypeChange">
                <el-radio :label="1">年</el-radio>
                <el-radio :label="3">月</el-radio>
                <el-radio :label="5">日</el-radio>
            </el-radio-group>
        </el-form-item>
        <el-form-item>
            <el-date-picker v-model="dateValue" :type="pickerType" value-format="yyyy-MM-dd"
                :placeholder="leable"></el-date-picker>
        </el-form-item>
        <el-form-item v-if="displayOptions.wentaizhibiao" label="稳态指标:">
            <el-select v-model="wentaizhibiao" placeholder="请选择">
                <el-option v-for="item in wentaizhibiaoList" :key="item.id" :label="item.name"
                    :value="item.id"></el-option>
            </el-select>
        </el-form-item>
        <el-form-item v-if="displayOptions.zantaizhibiao" label="暂态事件:">
            <el-select v-model="zantaizhibiao" placeholder="请选择">
                <el-option v-for="item in zantaizhibiaoList" :key="item.id" :label="item.name"
                    :value="item.id"></el-option>
            </el-select>
        </el-form-item>
        <el-form-item v-if="displayOptions.dianyadengji" label="电压等级:">
            <el-select v-model="dianyadengji" placeholder="请选择">
                <el-option v-for="item in dianyadengjiList" :key="item.id" :label="item.name"
                    :value="item.id"></el-option>
            </el-select>
        </el-form-item>

        <el-form-item v-if="displayOptions.jianceduixiang" label="监测对象:">
            <el-select v-model="jianceduixiang" placeholder="请选择">
                <el-option v-for="item in jianceduixiangList" :key="item.id" :label="item.name"
                    :value="item.id"></el-option>
            </el-select>
        </el-form-item>
        <el-form-item v-if="displayOptions.tongjileixing" label="统计类型:">
            <el-select v-model="tongjileixing" placeholder="请选择">
                <el-option v-for="item in tongjileixingList" :key="item.id" :label="item.name"
                    :value="item.id"></el-option>
            </el-select>
        </el-form-item>
        <el-form-item class="box1">
            <el-button type="primary" icon="el-icon-search" @click="queryData">查询</el-button>
        </el-form-item>
        <el-form-item class="box1">
            <el-button type="primary" icon="el-icon-share" @click="shangbao">网公司上报</el-button>
        </el-form-item>
    </el-form>
</template>

<script>
/**
 * 算法筛选框
 * @description 算法筛选框，根据父组件穿参数渲染需要展示的筛选框
 * @property {Object} displayOptions 显示配置项
 */
import Area from '@/views/components/Area/Area.vue'
import { dicData } from '@/assets/commjs/dictypeData'

export default {
    components: { Area },
    data() {
        return {
            dateValue: new Date().toLocaleDateString().replaceAll('/', '-'),
            pickerType: 'date',
            leable: '请选择日期',
            dateType: 5,
            //稳态
            wentaizhibiao: '',
            wentaizhibiaoList: [],
            //暂态
            zantaizhibiao: '',
            zantaizhibiaoList: [],
            //电压等级
            dianyadengji: '',
            dianyadengjiList: [],
            //监测对象
            jianceduixiang: '',
            jianceduixiangList: [],
            // 统计类型
            tongjileixingList: [
                {
                    id: '',
                    name: '全部'
                },
                {
                    id: 'sd',
                    name: '标准差'
                },
                {
                    id: 'avg',
                    name: '平均值'
                }
            ],
            tongjileixing: 'sd',
            // 单位code
            orgId: ''
        }
    },
    props: {
        type: {
            type: String,
            default: ''
        },
        displayOptions: {
            type: Object,
            default: {
                wentaizhibiao: false,
                zantaizhibiao: false,
                dianyadengji: false,
                jianceduixiang: false,
                tongjileixing: false
            }
        }
    },
    created() {
        //稳态指标
        this.wentaizhibiaoList = dicData('Steady_Statis', [])
        this.wentaizhibiaoList.splice(0, 0, { id: '', name: '全部' })
        this.wentaizhibiao = this.wentaizhibiaoList[0].id
        // 暂态指标
        this.zantaizhibiaoList = dicData('Transient_Indicators', [])
        this.zantaizhibiaoList.splice(0, 0, { id: '', name: '全部' })
        this.zantaizhibiao = this.zantaizhibiaoList[0].id
        // 电压等级
        this.dianyadengjiList = dicData('Dev_Voltage', [])
        this.dianyadengjiList.splice(0, 0, { id: '', name: '全部' })
        this.dianyadengji = this.dianyadengjiList[0].id
        // 监测对象
        this.jianceduixiangList = dicData('Monitoring_Labels', [])
        this.jianceduixiangList.splice(0, 0, { id: '', name: '全部' })
        this.jianceduixiang = this.jianceduixiangList[0].id
        let wentaizhibiaoListArr = []
        let dianyadengjiListArr = []
        let jianceduixiangListArr = []

        if (this.type === 'substation') {
            wentaizhibiaoListArr = ['电压偏差', '电压总谐波畸变率', '三相电压不平衡度', '长时闪变']
        } else if (this.type === 'source-load') {
            wentaizhibiaoListArr = ['电压总谐波畸变率', '谐波电压', '三相电压不平衡度', '负序电流', '长时闪变']
            jianceduixiangListArr = ['牵引站', '风电场', '光伏电站', '重要敏感用户']
        } else if (this.type === 'bus-bar') {
            wentaizhibiaoListArr = ['电压偏差', '电压总谐波畸变率', '三相电压不平衡度', '长时闪变']
        }
        if (wentaizhibiaoListArr.length > 0) {
            this.wentaizhibiaoList = this.wentaizhibiaoList.filter(item => {
                if (!item.id) return true
                return wentaizhibiaoListArr.includes(item.name)
            })
        }
        if (dianyadengjiListArr.length > 0) {
            this.jianceduixiangList = this.jianceduixiangList.filter(item => {
                if (!item.id) return true
                return dianyadengjiListArr.includes(item.name)
            })
        }
        if (jianceduixiangListArr.length > 0) {
            this.dianyadengjiList = this.dianyadengjiList.filter(item => {
                if (!item.id) return true
                return jianceduixiangListArr.includes(item.name)
            })
        }
    },
    mounted() { },
    methods: {
        init() {
            this.wentaizhibiao = this.wentaizhibiaoList[0].id
            this.zantaizhibiao = this.zantaizhibiaoList[0].id
            this.dianyadengji = this.dianyadengjiList[0].id
            this.jianceduixiang = this.jianceduixiangList[0].id
        },
        dateTypeChange() {
            switch (this.dateType) {
                case 1:
                    this.pickerType = 'year'
                    this.leable = '请选择年'
                    break
                case 3:
                    this.pickerType = 'month'
                    this.leable = '请选择月'
                    break
                case 5:
                    this.pickerType = 'date'
                    this.leable = '请选择日'
                    break
                default:
                    break
            }
        },
        // 切换选项
        handleNodeClick(data) {
            console.log(data)
            if (!this.orgId) {
                this.orgId = data.code
                this.$emit('search')
            } else {
                this.orgId = data.code
            }
        },
        queryData() {
            this.$emit('search')
        },
        shangbao() {
            this.$emit('shangbao')
        }
    }
}
</script>

<style></style>
