<template>
    <div>
        <el-form :inline="true" :model="ruleForm" class="demo-form-inline">
            <el-form-item label="信息查询:">
                <el-input v-model.trim="ruleForm.searchValue" placeholder="请输入查询信息" style="width: 160px"
                    clearable></el-input>
            </el-form-item>

            <el-form-item label="对象标签:">
                <el-select v-model="ruleForm.monitorTag" placeholder="请选择装置类别" clearable style="width: 160px">
                    <el-option v-for="item in monitorTagList" :key="item.id" :label="item.name"
                        :value="item.id"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="对象类型:">
                <el-cascader filterable clearable ref="SubObjType" placeholder="请选择对象类型" v-model="objTypes"
                    :show-all-levels="false" :options="flag == 1 ? MonitoringPointTypes : MonitoringPointType" :props="{
                        checkStrictly: true,
                        expandTrigger: 'hover',
                        value: 'id',
                        label: 'name',
                        children: 'children'
                    }"></el-cascader>
            </el-form-item>
            <el-form-item>
                <!-- <el-button type="primary" icon="el-icon-download" class="pms">PMS获取数据</el-button>
                <el-button type="primary" icon="el-icon-upload2" class="ml10" @click="upload">PMS数据上传</el-button> -->
                <el-button type="primary" class="ml10" icon="el-icon-search" @click="pagMonitoring">查询</el-button>
                <!-- <el-button type="primary" icon="el-icon-refresh-right" @click="Reset"
          >重置</el-button
        > -->
                <el-button type="primary" icon="el-icon-download" @click="exportEvent">导出</el-button>

            </el-form-item>

        </el-form>

        <template>

            <vxe-table stripe :data="UserData" :height="height" border :row-config="{ isCurrent: true, isHover: true }"
                size="mini" ref="Monitoringpoint" style="width: 100%" v-loading="isLoading"
                header-cell-class-name="table_header" @checkbox-change="handleSelectionChange" class="mt10"
                :cell-style="cellStyle">
                <vxe-table-column align="center" type="checkbox" width="55"></vxe-table-column>

                <vxe-table-column v-for="(item, index) in tableHeaderMonitoring" align="center" :field="item.prop"
                    :title="item.label" :min-width="item.width" :key="index" :formatter="formFilter"
                    :show-overflow="true"></vxe-table-column>

            </vxe-table>
            <el-pagination background align="right" @size-change="handleSizeChange"
                @current-change="handleCurrentChange" :current-page="ruleForm.pageNum"
                :page-sizes="[20, 30, 40, 50, 100]" :page-size="ruleForm.pageSize"
                layout="total, sizes, prev, pager, next, jumper" :total="total" class="mt10"></el-pagination>
        </template>



        <!-- 新增/修改 -->
        <el-dialog :close-on-click-modal="false" :title="title" :visible.sync="addinformation"
            :before-close="handleClose" width="50%" height="80%">
            <el-form :inline="true" :model="form" ref="rulesform" label-width="170px" :rules="rules" class="form">
                <el-form-item label="用户编号:" class="mt10">
                    <el-input v-model="form.id" placeholder="不填写默认生成自动编号" clearable :disabled="disabled"></el-input>
                </el-form-item>
                <el-form-item label="用户名称:" prop="name" class="mt10">
                    <el-input v-model="form.name" clearable placeholder="请输入用户名称"></el-input>
                </el-form-item>
                <el-form-item prop="orgName" class="mt10" label="组织机构名称:" :rules="{
                    required: true,
                    message: '请输入组织机构名称',
                    trigger: 'change'
                }">
                    <Organization @click="handleNodeClick" ref="Organization" :valueTitle="valueTitle"
                        :editCheckCode="editCheckCode"></Organization>
                </el-form-item>
                <el-form-item prop="operationName" class="mt10" label="运维单位名称:" :rules="{
                    required: true,
                    message: '请输入运维单位名称',
                    trigger: 'change'
                }">
                    <Operation @click="handleNodeClick1" ref="Operation" :valueTitle="valueTitle1"
                        :editCheckCode="editCheckCode1"></Operation>
                </el-form-item>
                <el-form-item label="变电站名称:" prop="powerrId" class="mt10">
                    <el-select v-model="form.powerrId" clearable placeholder="请选择变电站名称" @change="changeFn1" filterable>
                        <el-option v-for="item in statationName" :key="item.powerId"
                            :label="item.orgName + '_' + item.powerName" :value="item.powerId"></el-option>
                    </el-select>
                </el-form-item>

                <el-form-item label="关联的监测终端编号:" prop="terminalId" class="mt10">
                    <el-select v-model="form.terminalId" clearable placeholder="请选择关联的监测终端编号" filterable
                        @change="changeTerminal">
                        <el-option v-for="item in TerminalNo" :key="item.id" :label="item.orgName + '_' + item.name"
                            :value="item.id"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="监测线路名称:" prop="lineId" class="mt10">
                    <el-select v-model="form.lineId" clearable placeholder="请选择监测线路名称" @change="changeFn3" filterable>
                        <el-option v-for="item in MonitoringLine" :key="item.id"
                            :label="item.stationName + '_' + item.name" :value="item.id"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="电压等级:" prop="voltageLevel" class="mt10">
                    <el-select v-model="form.voltageLevel" clearable placeholder="请选择电压等级">
                        <el-option v-for="item in voltageLevelList" :key="item.id" :label="item.name"
                            :value="item.id"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="用户状态:" prop="monitorState" class="mt10">
                    <el-select v-model="form.monitorState" clearable placeholder="请选择用户状态">
                        <el-option 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="用户类型:" prop="monitorType" class="mt10">
                    <el-select v-model="form.monitorType" clearable placeholder="请选择用户类型">
                        <el-option v-for="item in monitorTypeList" :key="item.id" :label="item.name"
                            :value="item.id"></el-option>
                    </el-select>
                </el-form-item>

                <el-form-item label="PT变比:" required class="mt10">
                    <div style="display: flex">
                        <!-- <el-form-item prop="pt1" style="flex: 1"> -->
                        <el-input v-model="form.pt1" clearable style="width: 100%" placeholder="请输入pt1"></el-input>
                        <!-- </el-form-item>
                        <el-form-item prop="pt2" style="flex: 1"> -->
                        <el-input v-model="form.pt2" clearable style="width: 100%" placeholder="请输入pt1"></el-input>
                        <!-- </el-form-item> -->
                    </div>
                </el-form-item>
                <el-form-item label="CT变比:" required class="mt10">
                    <div style="display: flex">
                        <!-- <el-form-item prop="ct1"> -->
                        <el-input v-model="form.ct1" clearable style="width: 100%" placeholder="请输入ct1"></el-input>
                        <!-- </el-form-item>
                        <el-form-item prop="ct2"> -->
                        <el-input v-model="form.ct2" clearable style="width: 100%" placeholder="请输入ct2"></el-input>
                        <!-- </el-form-item> -->
                    </div>
                </el-form-item>
                <el-form-item label="电压偏差限值（上）:" prop="voltageDeviationUpperLimit" class="mt10">
                    <el-input v-model="form.voltageDeviationUpperLimit" maxlength="10" clearable
                        placeholder="请输入电压偏差限值（上）"></el-input>
                </el-form-item>
                <el-form-item label="电压偏差限值（下）:" prop="voltageDeviationLowerLimit" class="mt10">
                    <el-input v-model="form.voltageDeviationLowerLimit" maxlength="10" clearable
                        placeholder="请输入电压偏差限值（下）"></el-input>
                </el-form-item>
                <el-form-item label="最小短路容量:" prop="minShortCircuitCapacity" class="mt10">
                    <el-input v-model="form.minShortCircuitCapacity" maxlength="10" clearable
                        placeholder="请输入最小短路容量"></el-input>
                </el-form-item>
                <el-form-item label="供电设备容量:" prop="powerSupplyEqCapacity" class="mt10">
                    <el-input v-model="form.powerSupplyEqCapacity" maxlength="10" clearable
                        placeholder="请输入供电设备容量"></el-input>
                </el-form-item>
                <el-form-item label="用户协议容量:" prop="userAgreementCapacity" class="mt10">
                    <el-input v-model="form.userAgreementCapacity" maxlength="10" clearable
                        placeholder="请输入用户协议容量"></el-input>
                </el-form-item>

                <el-form-item label="电压互感器类型:" prop="potentialTransFormerType" class="mt10">
                    <el-select v-model="form.potentialTransFormerType" clearable placeholder="请选择电压互感器类型">
                        <el-option v-for="item in potentialTransFormerTypeList" :key="item.id" :label="item.name"
                            :value="item.id"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="中性点接地方式:" prop="neutralGroundingMode" class="mt10">
                    <el-select v-model="form.neutralGroundingMode" clearable placeholder="请选择中性点接地方式">
                        <el-option v-for="item in neutralGroundingModeList" :key="item.id" :label="item.name"
                            :value="item.id"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="行业分类:" prop="MonitoringData" class="mt10">
                    <el-select v-model="form.tradeCode" clearable placeholder="请选择监测对象">
                        <el-option v-for="item in industryType" :key="item.id" :label="item.name"
                            :value="item.id"></el-option>
                    </el-select>
                </el-form-item>

                <el-form-item label="监测对象标签:" prop="monitorTag" class="mt10">
                    <el-select v-model="form.monitorTag" clearable placeholder="请选择监测对象标签">
                        <el-option v-for="item in monitorTagList" :key="item.id" :label="item.name"
                            :value="item.id"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="对象类型:" prop="objType" class="mt10">
                    <el-cascader placeholder="请选择对象类型" v-model="form.objType" filterable ref="cascader"
                        style="width: 100%" :show-all-levels="false" :options="MonitoringPointType" :props="{
                            checkStrictly: true,
                            expandTrigger: 'hover',
                            value: 'id',
                            label: 'name',
                            children: 'children'
                        }" @change="changeCascader"></el-cascader>
                </el-form-item>
                <el-form-item label="新能源场:" v-if="objTypeCode == '1402' || objTypeCode == '1401'" prop="fieldStation"
                    class="mt10">
                    <el-select v-model="form.fieldStation" placeholder="请选择新能源场">
                        <el-option label="在运站" value="01"></el-option>
                        <el-option label="新(改、扩)建站" value="02"></el-option>
                    </el-select>
                </el-form-item>

                <!-- <el-form-item label="监测对象:" prop="MonitoringData" class="mt10">
                    <el-select
                        v-model="form.MonitoringData"
                        clearable
                        placeholder="请选择监测对象"
                        @change="ToggleObjects"
                    >
                        <el-option
                            v-for="item in MonitoringObjectData"
                            :key="item.value"
                            :label="item.label"
                            :value="item.label"
                        ></el-option>
                    </el-select>
                </el-form-item> -->
                <el-form-item label="是否用户专线:" prop="isSpecialSupplyElectricity" class="mt10">
                    <el-select v-model="form.isSpecialSupplyElectricity" clearable placeholder="请选择是否用户专线">
                        <el-option v-for="item in whether1" :key="item.id" :label="item.label"
                            :value="item.id"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="监测对象名称:" prop="monitorObjectId" class="mt10">
                    <el-input v-model="form.monitorObjectName" clearable placeholder="请输入监测对象名称"></el-input>
                    <!-- <el-select
                        v-model="form.monitorObjectId"
                        clearable
                        multiple
                        collapse-tags
                        placeholder="请选择监测对象名称"
                    >
                        <el-option
                            v-for="item in MonitoringObject"
                            :key="item.id"
                            :label="item.name"
                            :value="item.id"
                        ></el-option>
                    </el-select> -->
                </el-form-item>
                <el-form-item label="统计间隔(分钟):" prop="statisticalInterval" class="mt10">
                    <el-select v-model="form.statisticalInterval" clearable placeholder="请选择统计间隔">
                        <el-option v-for="item in timeInterval" :key="item.id" :label="item.label"
                            :value="item.label"></el-option>
                    </el-select>
                </el-form-item>

                <el-form-item label="监测终端接线方式:" prop="terminalWiringMethod" class="mt10">
                    <el-select v-model="form.terminalWiringMethod" clearable placeholder="请选择监测终端接线方式">
                        <el-option v-for="item in terminalWiringMethodList" :key="item.id" :label="item.name"
                            :value="item.id"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="是否是上送网公司用户:" prop="isUpToGrid" class="mt10">
                    <el-select v-model="form.isUpToGrid" clearable placeholder="请选择是否是上送网公司用户">
                        <el-option v-for="item in whether" :key="item.id" :label="item.label"
                            :value="item.id"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="是否专项分析:" prop="isSpecialMonitor" class="mt10">
                    <el-select v-model="form.isSpecialMonitor" placeholder="请选择是否专项分析">
                        <el-option v-for="item in whether" :key="item.id" :label="item.label"
                            :value="item.id"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="关联牵引站:" v-if="objTypeCode == '1300'" class="mt10">
                    <el-select v-model="form.tractionId" filterable clearable placeholder="请选择关联牵引站">
                        <el-option v-for="item in TractionStation" :key="item.id" :label="item.name"
                            :value="item.id"></el-option>
                    </el-select>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button type="primary" @click="handleClose">取 消</el-button>
                <el-button v-if="add" type="primary" @click="addinformationFn">确 定</el-button>
                <el-button v-if="modify" type="primary" @click="modifyinformationFn">确 定</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
import PMS_Data from '@/views/components/Accountinformation/PMS_Data'
import Organization from '../Area/Organization.vue'
import Operation from '../Area/Operation.vue'
import {
    getstatationStatList,
    getGeneratrixWireList,
    getTerminalSelectList,
    getPowerClientList,
    getPowerGenerationUserList,
    getAllMainUserPageList,
    addMonitor,
    updateMonitor,
    delMonitor,
    importMonitor,
    queryTree,
    exportSend,
    sendType,
    pushMonitor,
    getTractionStationList
} from '@/api/hbaccountoperation/Monitoringpoint'
//   import {deptTree} from '@/api/admin/dept'
import { dicData } from '@/assets/commjs/dictypeData'
export default {
    props: {
        flag: {
            type: Number,
            default: 0
        }
    },
    components: { PMS_Data, Organization, Operation },
    data() {
        return {
            fileList: [],
            vh: '',
            title: '',
            add: false,
            modify: false,
            disabled: false,
            objTypes: [],
            // 查询数据
            ruleForm: {
                searchValue: '',
                monitorTag: '',
                monitorState: '',
                objType: '',
                pageNum: 1,
                pageSize: 20
            },
            objTypeCode: '',
            total: 0,
            monitorObjectName: [],
            monitorObjectId: [],
            form: {
                id: '',
                isSpecialSupplyElectricity: '',
                isUpToGrid: '',
                lineId: '',
                lineName: '',
                minShortCircuitCapacity: '',
                // monitorObjectId: [],
                MonitoringData: '',
                monitorObjectType: '',
                monitorState: '',
                objType: '',
                monitorTag: '',
                monitorType: '',
                name: '',
                neutralGroundingMode: '',
                operationId: '',
                operationName: '',
                orgId: '',
                fieldStation: '',
                orgName: '',
                potentialTransFormerType: '',
                powerSupplyEqCapacity: '',
                powerrId: '',
                powerrName: '',
                statisticalInterval: '',
                terminalId: '',
                terminalWiringMethod: '',
                userAgreementCapacity: undefined,
                voltageDeviationLowerLimit: '',
                voltageDeviationUpperLimit: '',
                voltageLevel: '',
                ct1: '',
                ct2: '',
                pt1: '',
                pt2: '',
                stationName: '',
                isSpecialMonitor: 0,
                tractionId: ''
            },
            rules: {
                voltageDeviationUpperLimit: [
                    {
                        required: true,
                        message: '请输入电压偏差限值（上）',
                        trigger: 'blur'
                    },
                    {
                        pattern: /^-?[0-9]\d*$/,
                        message: '只可以输入整数',
                        trigger: 'blur'
                    }
                ],
                voltageDeviationLowerLimit: [
                    {
                        required: true,
                        message: '请输入电压偏差限值（下）',
                        trigger: 'blur'
                    },
                    {
                        pattern: /^-?[0-9]\d*$/,
                        message: '只可以输入整数',
                        trigger: 'blur'
                    }
                ],
                name: [{ required: true, message: '请输入用户名称', trigger: 'blur' }],
                fieldStation: [{ required: true, message: '请输入新能源场', trigger: 'blur' }],
                // valueTitle: [
                //   { required: true, message: "请输入组织机构名称", trigger:["blur",'change']},
                // ],
                powerrId: [
                    {
                        required: true,
                        message: '请选择变电站名称',
                        trigger: ['blur', 'change']
                    }
                ],
                terminalId: [
                    {
                        required: true,
                        message: '请选择关联的监测终端编号',
                        trigger: ['blur', 'change']
                    }
                ],
                lineId: [
                    {
                        required: true,
                        message: '请选择监测线路名称',
                        trigger: ['blur', 'change']
                    }
                ],
                voltageLevel: [{ required: true, message: '请选择电压等级', trigger: 'change' }],
                monitorState: [{ required: true, message: '请选择用户状态', trigger: 'change' }],
                monitorType: [{ required: true, message: '请选择用户类型', trigger: 'change' }],
                pt1: [
                    { required: true, message: '请输入pt1', trigger: 'blur' },
                    { pattern: /^[0-9]*$/, message: '只可以输入数字', trigger: 'blur' }
                ],
                pt2: [
                    { required: true, message: '请输入pt2', trigger: 'blur' },
                    { pattern: /^[0-9]*$/, message: '只可以输入数字', trigger: 'blur' }
                ],
                ct1: [
                    { required: true, message: '请输入ct1', trigger: 'blur' },
                    { pattern: /^[0-9]*$/, message: '只可以输入数字', trigger: 'blur' }
                ],
                ct2: [
                    { required: true, message: '请输入ct2', trigger: 'blur' },
                    { pattern: /^[0-9]*$/, message: '只可以输入数字', trigger: 'blur' }
                ],
                minShortCircuitCapacity: [
                    { required: true, message: '请输入最小短路容量', trigger: 'blur' },
                    {
                        pattern: /^[0-9.]*$/,
                        message: '只可以输入数字和小数',
                        trigger: 'blur'
                    }
                ],
                powerSupplyEqCapacity: [
                    { required: true, message: '请输入供电设备容量', trigger: 'blur' },
                    {
                        pattern: /^[0-9.]*$/,
                        message: '只可以输入数字和小数',
                        trigger: 'blur'
                    }
                ],
                userAgreementCapacity: [
                    { required: true, message: '请输入用户协议容量', trigger: 'blur' },
                    {
                        pattern: /^[0-9.]*$/,
                        message: '只可以输入数字和小数',
                        trigger: 'blur'
                    }
                ],
                potentialTransFormerType: [
                    {
                        required: true,
                        message: '请选择电压互感器类型',
                        trigger: 'change'
                    }
                ],
                neutralGroundingMode: [
                    {
                        required: true,
                        message: '请选择中性点接地方式',
                        trigger: 'change'
                    }
                ],
                isSpecialSupplyElectricity: [{ required: true, message: '请选择是否用户专线', trigger: 'change' }],
                monitorTag: [{ required: true, message: '请选择监测对象标签', trigger: 'change' }],
                objType: [{ required: true, message: '对象类型', trigger: 'change' }],

                // MonitoringData: [
                //   { required: true, message: "请选择监测对象", trigger: "change" },
                // ],
                // monitorObjectId: [
                //   {
                //     required: true,
                //     message: "请选择监测对象名称",
                //     trigger: ["blur", "change"],
                //   },
                // ],
                statisticalInterval: [{ required: true, message: '请选择统计间隔', trigger: 'change' }],
                terminalWiringMethod: [
                    {
                        required: true,
                        message: '请选择监测终端接线方式',
                        trigger: 'change'
                    }
                ],
                isUpToGrid: [
                    {
                        required: true,
                        message: '请选择是否是上送网公司用户',
                        trigger: 'change'
                    }
                ],
                isSpecialMonitor: [{ required: true, message: '请选择是否专项分析', trigger: 'change' }]
            },
            MonitoringData: '',
            height: null,
            height1: null,
            isLoading: false,

            multipleSelection: [],
            monitorTagList: [],
            //台区台账表头
            tableHeaderMonitoring: [
                // { prop: 'id', label: '用户编号', width: 120 },
                { prop: 'monitorObjectName', label: '监测对象名称', width: 250 },

                { prop: 'orgName', label: '组织机构名称', width: 170 },
                { prop: 'operationName', label: '运维单位名称', width: 170 },
                { prop: 'powerrName', label: '变电站名称', width: 120 },
                //{ prop: "generatrixName", label: "母线名称", width: 120 },

                { prop: 'lineName', label: '母线名称', width: 180 },

                { prop: 'voltageLevel', label: '电压等级', width: 100 },

                {
                    prop: 'isSpecialSupplyElectricity',
                    label: '是否用户专线',
                    width: 130
                },
                { prop: 'monitorTag', label: '监测对象标签', width: 170 },
                { prop: 'objType', label: '对象类型', width: 170 },

                // { prop: "monitorObjectId", label: "监测对象编号", width:170 },

                { prop: 'tradeCode', label: '行业分类', width: 170 },

                { prop: 'fieldStation', label: '新能源场', width: 120 },

            ],
            whether: [
                {
                    id: 0,
                    value: '选项1',
                    label: '否'
                },
                {
                    id: 1,
                    value: '选项2',
                    label: '是'
                }
            ],
            whether1: [
                {
                    id: 0,
                    value: '选项1',
                    label: '否'
                },
                {
                    id: 1,
                    value: '选项2',
                    label: '是'
                }
            ],
            timeInterval: [
                {
                    id: 0,
                    value: '选项1',
                    label: 1
                },
                {
                    id: 1,
                    value: '选项2',
                    label: 3
                },
                {
                    id: 3,
                    value: '选项2',
                    label: 5
                },
                {
                    id: 4,
                    value: '选项2',
                    label: 10
                }
            ],

            MonitoringObjectData: [
                {
                    value: '选项1',
                    label: '用电用户信息'
                },
                {
                    value: '选项2',
                    label: '发电用户信息'
                }
            ],
            UserData: [],
            device: '',
            editCheckCode: '',
            valueTitle: '',
            editCheckCode1: '',
            valueTitle1: '',
            // organization: [],//组织机构名称
            // operation : [],//运维单位名称
            statationName: [], //变电站名称
            BusbarName: [], //母线名称
            MonitoringLine: [], //监测线路名称
            MonitoringObject: [], //监测对象名称
            TerminalNo: [], //关联的监测终端编号
            voltageLevelList: [], //电压等级
            industryType: [], //行业分类
            monitorStateList: [], //用户状态
            monitorTypeList: [], //用户标签
            MonitoringPointType: [], //用户类型
            MonitoringPointTypes: [], //用户类型
            potentialTransFormerTypeList: [], //电压互感器类型
            neutralGroundingModeList: [], //中性点接地方式

            terminalWiringMethodList: [], //监测终端接线方式
            PMSobtain: false,
            information: false, //修改台区信息
            addinformation: false, //新增台区信息
            TractionStation: [] //关联牵引站
        }
    },
    created() {
        this.getclassificationData()
    },

    mounted() {
        this.setHeight()
        window.addEventListener('resize', this.setHeight)

        this.Monitoring()
    },
    beforeDestroy() {
        window.removeEventListener('resize', this.setHeight)
    },
    computed: {},
    methods: {
        setHeight() {
            this.device = window.devicePixelRatio
            this.height = window.sessionStorage.getItem('appheight') - 208
            this.height1 = window.sessionStorage.getItem('appheight') - 285
        },
        // 切换选项
        handleNodeClick(data) {
            if (data.code != null) {
                this.form.powerrId = ''
                this.form.terminalId = ''
                this.form.lineId = ''
                let form = {
                    deptId: data.id
                }
                // 变电站名称
                getstatationStatList(form).then(res => {
                    this.statationName = res.data
                })
            }
            this.form.orgId = data.code
            this.form.orgName = data.name
            // this.rules['powerrId'] = []
        },
        handleNodeClick1(data) {
            // console.log(data);
            this.form.operationId = data.code
            this.form.operationName = data.name
        },

        //变电站change事件
        changeFn1(val) {
            this.form.terminalId = ''
            this.form.lineId = ''
            let form = {
                stationId: val
            }
            // 线路名称
            getGeneratrixWireList(form).then(res => {
                this.MonitoringLine = res.data
            })
            this.statationName.forEach(item => {
                if (item.powerId == val) {
                    this.form.powerrName = item.powerName
                }
            })

            //关联的监测终端编号

            getTerminalSelectList(form).then(res => {
                this.TerminalNo = res.data
                // console.log(this.TerminalNo);
            })
        },

        changeFn3(val) {
            this.MonitoringLine.forEach(item => {
                if (item.id == val) {
                    this.form.lineName = item.name
                }
            })
            this.$forceUpdate()
        },

        ToggleObjects(val) {
            // console.log(val, "++++++++++++");
            if (val == '用电用户信息') {
                let obj = {}
                getPowerClientList(obj).then(res => {
                    this.MonitoringObject = res.data
                })
            } else if (val == '发电用户信息') {
                let obj = {}
                getPowerGenerationUserList(obj).then(res => {
                    this.MonitoringObject = res.data
                })
            }
        },
        //获取类型
        getclassificationData() {
            //电压等级
            this.voltageLevelList = dicData('Dev_Voltage', [])
            //用户状态
            this.monitorStateList = dicData('Line_State', [])

            //用户标签
            this.monitorTypeList = dicData('Line_Type', [])
            //电压互感器类型
            this.potentialTransFormerTypeList = dicData('Voltage_Transformer', [])
            //中性点接地方式
            this.neutralGroundingModeList = dicData('Neutral_Point', [])
            //用户标签
            this.monitorTagList = dicData('Monitoring_Labels', [])
            //监测终端接线方式
            this.terminalWiringMethodList = dicData('Dev_Connect', [])
            //行业分类
            this.industryType = dicData('industry_type', [])

            // 用户类型
            queryTree({}).then(res => {
                if (res && res.code == `A0000`) {
                    this.MonitoringPointType = this.getTreeData(res.data)
                    if (this.flag == 1) {
                        this.MonitoringPointTypes = []
                        this.MonitoringPointType.forEach(item => {
                            if (
                                item.code == '1401' ||
                                item.code == '1402' ||
                                item.code == '2400' ||
                                item.code == '1300'
                            ) {
                                this.MonitoringPointTypes.push(item)
                            }
                        })
                        console.log(this.MonitoringPointTypes)

                        //特殊处理
                        this.MonitoringPointTypes.push({ name: '其他干扰用户', id: '987654321' })
                    }
                }
            })
            getTractionStationList().then(res => {
                this.TractionStation = res.data
            })
        },
        getTreeData(data) {
            for (var i = 0; i < data.length; i++) {
                if (data[i].children.length < 1) {
                    // children若为空数组，则将children设为undefined

                    data[i].children = undefined
                } else {
                    this.getTreeData(data[i].children)
                }
            }

            return data
        },

        //PMS获取数据
        // PMSobtainFn() {
        //   this.PMSobtain = true;
        //   this.title = "线路表";
        // },
        // 查询分页置1
        pagMonitoring() {
            this.ruleForm.pageSize = 20
            this.ruleForm.pageNum = 1
            this.Monitoring()
        },

        //查询用户用电信息
        Monitoring() {
            this.isLoading = true
            if (this.objTypes.length > 0) {
                this.ruleForm.objType = this.objTypes[this.objTypes.length - 1]
            } else {
                this.ruleForm.objType = ''
            }
            getAllMainUserPageList(this.ruleForm).then(res => {
                this.isLoading = false
                this.UserData = res.data.records
                this.total = res.data.total
            })
        },
        // 数据过滤
        formFilter(row, column) {
            if (row.column.property == 'voltageLevel') {
                let title = ''
                this.voltageLevelList.forEach(item => {
                    if (item.value == row.row.voltageLevel) {
                        title = item.label
                    }
                })
                return title
            } else if (row.column.property == 'monitorState') {
                let title = ''
                this.monitorStateList.forEach(item => {
                    if (item.value == row.row.monitorState) {
                        title = item.label
                    }
                })
                return title
            } else if (row.column.property == 'monitorType') {
                let title = ''
                this.monitorTypeList.forEach(item => {
                    if (item.value == row.row.monitorType) {
                        title = item.label
                    }
                })
                return title
            } else if (row.column.property == 'potentialTransFormerType') {
                let title = ''
                this.potentialTransFormerTypeList.forEach(item => {
                    if (item.value == row.row.potentialTransFormerType) {
                        title = item.label
                    }
                })
                return title
            } else if (row.column.property == 'tradeCode') {
                let title = '/'
                this.industryType.forEach(item => {
                    if (item.value == row.row.tradeCode) {
                        title = item.label
                    }
                })
                return title
            } else if (row.column.property == 'neutralGroundingMode') {
                let title = ''
                this.neutralGroundingModeList.forEach(item => {
                    if (item.value == row.row.neutralGroundingMode) {
                        title = item.label
                    }
                })
                return title
            } else if (row.column.property == 'terminalWiringMethod') {
                let title = ''
                this.terminalWiringMethodList.forEach(item => {
                    if (item.value == row.row.terminalWiringMethod) {
                        title = item.label
                    }
                })
                return title
            } else if (row.column.property == 'monitorTag') {
                let title = ''
                this.monitorTagList.forEach(item => {
                    if (item.value == row.row.monitorTag) {
                        title = item.label
                    }
                })
                return title
            } else if (row.column.property == 'objType') {
                let title = ''
                this.MonitoringPointType.forEach(item => {
                    if (item.id == row.row.objType) {
                        return (title = item.name)
                    } else {
                        if (item.children != undefined) {
                            item.children.forEach(val => {
                                if (val.id == row.row.objType) {
                                    return (title = val.name)
                                }
                            })
                        }
                    }
                })
                return title //this.getTreeName(this.MonitoringPointType, row.row.objType)
            } else if (row.column.property == 'isSpecialSupplyElectricity') {
                if (row.row.monitorTag == 1) {
                    return '是'
                } else {
                    return '否'
                }
            } else if (row.column.property == 'isUpToGrid') {
                if (row.row.isUpToGrid == 1) {
                    return '是'
                } else {
                    return '否'
                }
            } else if (row.column.property == 'isUploadHead') {
                return row.row.isUploadHead == 0
                    ? '未上送 '
                    : row.row.isUploadHead == 1
                        ? '已上送 '
                        : row.row.isUploadHead == 2
                            ? '取消上送 '
                            : row.row.isUploadHead == 3
                                ? '待重新上送 '
                                : ''
            } else if (row.column.property == 'monitorUploadStatus') {
                return row.row.monitorUploadStatus == 0
                    ? '未上送 '
                    : row.row.monitorUploadStatus == 1
                        ? '已上送 '
                        : row.row.monitorUploadStatus == 2
                            ? '取消上送 '
                            : row.row.monitorUploadStatus == 3
                                ? '待重新上送 '
                                : ''
            } else if (row.column.property == 'fieldStation') {
                return row.row.fieldStation == '01'
                    ? '在运站'
                    : row.row.fieldStation == '02'
                        ? ' 新(改、扩)建站  '
                        : '/'
            } else {
                return row.row[row.column.property]
            }
        },
        getTreeName(data, id) {
            for (var i = 0; i < data.length; i++) {
                if (data[i].id == id) {
                    // children若为空数组，则将children设为undefined

                    return data[i].name
                } else {
                    if (data[i].children != undefined) {
                        this.getTreeName(data[i].children, id)
                    }
                }
            }
        },
        changeCascader(e) {
            this.objTypeCode = this.$refs['cascader'].getCheckedNodes()[0].data.code //标签上定义的 ref值
        },
        //数据上传
        upload(params) {
            // 获取文件 通过FormData将文件转化为二进制流的形式传给后端
            let form = new FormData()
            form.append('file', params.file)
            importMonitor(form).then(res => {
                if (res.type == 'application/json') {
                    this.$message({
                        message: '上传成功,无错误数据!',
                        type: 'success'
                    })
                } else {
                    this.$message({
                        message: '上传成功,有错误数据  自动下载 请查看',
                        type: 'warning'
                    })
                    let blob = new Blob([res], {
                        type: 'application/vnd.ms-excel'
                    })
                    const url = window.URL.createObjectURL(blob)
                    const link = document.createElement('a') // 创建a标签
                    link.href = url
                    link.download = '模板错误信息' // 设置下载的文件名
                    document.body.appendChild(link)
                    link.click() //执行下载
                    document.bodyNaNpxoveChild(link)
                }

                this.fileList = []
            })
        },
        // 重置
        Reset() {
            // 查询数据
            this.ruleForm.searchValue = ''
        },

        //监测线路名称
        getGeneratrixWireList() {
            getGeneratrixWireList({}).then(res => {
                this.MonitoringLine = res.data
            })
        },

        //新增
        addFn() {
            this.form = {
                id: '',
                isSpecialSupplyElectricity: '',
                isUpToGrid: '',
                lineId: '',
                lineName: '',
                minShortCircuitCapacity: '',
                // monitorObjectId: [],
                MonitoringData: '',
                monitorObjectType: '',
                monitorState: '',
                monitorTag: '',
                monitorType: '',
                name: '',
                neutralGroundingMode: '',
                operationId: '',
                operationName: '',
                orgId: '',
                orgName: '',
                potentialTransFormerType: '',
                powerSupplyEqCapacity: '',
                powerrId: '',
                powerrName: '',
                statisticalInterval: '',
                terminalId: '',
                terminalWiringMethod: '',
                userAgreementCapacity: undefined,
                voltageDeviationLowerLimit: '',
                voltageDeviationUpperLimit: '',
                voltageLevel: '',
                ct1: '',
                ct2: '',
                pt1: '',
                pt2: '',
                stationName: '',
                isSpecialMonitor: 0,
                tractionId: ''
            }
            this.form.isSpecialMonitor = 0
            this.disabled = false
            this.modify = false
            this.add = true
            this.title = '新增主网用户台帐'
            this.addinformation = true
            // this.getData();
        },
        //新增台区确定
        addinformationFn() {
            // this.MonitoringObject.forEach(item => {
            //     this.form.monitorObjectId.forEach(i => {
            //         if (i == item.id) {
            //             this.monitorObjectName.push(item.name)
            //         }
            //     })
            // })
            // this.form.monitorObjectName = this.monitorObjectName.toString()
            // this.form.monitorObjectId = this.form.monitorObjectId.toString()
            // // console.log(
            //   this.form.monitorObjectName,
            //   this.form.monitorObjectId,
            //   "this.form"
            // );
            this.$refs.rulesform.validate(value => {
                // console.log(value);
                if (value == true) {
                    this.$confirm('是否确认新增?', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    })
                        .then(() => {
                            this.form.objType = this.$refs['cascader'].getCheckedNodes()[0].data.id //标签上定义的 ref值
                            addMonitor(this.form).then(res => {
                                if (res.code == 'A0000') {
                                    this.$message({
                                        message: res.message,
                                        type: 'success'
                                    })
                                }
                                this.addinformation = false
                                this.Monitoring()
                            })
                        })
                        .catch(() => {
                            this.$message({
                                type: 'info',
                                message: '已取消新增'
                            })
                        })
                }
            })
        },
        handleClose() {
            this.addinformation = false
            if (this.title == '新增主网用户台帐') {
                this.$refs.Operation.form.valueTitle = ''
                this.$refs.Organization.form.valueTitle = ''
            }
        },
        //修改数据
        modifyFn() {
            // this.getData();
            this.disabled = true
            this.modify = true
            this.add = false

            this.title = '修改主网用户台帐'
            if (this.$refs.Monitoringpoint.getCheckboxRecords().length != 1) {
                this.$message({
                    showClose: true,
                    message: '请选择台账!!!',
                    type: 'warning'
                })
                return
            }
            this.addinformation = true
            // console.log(this.$refs.Monitoringpoint.getCheckboxRecords()[0], "===============");
            // debugger
            this.form = this.$refs.Monitoringpoint.getCheckboxRecords()[0]
            this.valueTitle = this.$refs.Monitoringpoint.getCheckboxRecords()[0].orgName
            this.editCheckCode = this.$refs.Monitoringpoint.getCheckboxRecords()[0].orgId
            this.valueTitle1 = this.$refs.Monitoringpoint.getCheckboxRecords()[0].operationName
            this.editCheckCode1 = this.$refs.Monitoringpoint.getCheckboxRecords()[0].operationId

            // console.log(this.form);

            //处理下拉框回显数据
            let form = {
                deptCode: this.$refs.Monitoringpoint.getCheckboxRecords()[0].orgId
            }
            // 变电站名称
            getstatationStatList(form).then(res => {
                this.statationName = res.data
            })

            //关联的监测终端编号
            let formDev = {
                stationId: this.$refs.Monitoringpoint.getCheckboxRecords()[0].powerrId
            }
            getTerminalSelectList(formDev).then(res => {
                // console.log(res);
                this.TerminalNo = res.data
            })

            // 线路名称
            getGeneratrixWireList(formDev).then(res => {
                this.MonitoringLine = res.data
            })
            let list = []
            this.MonitoringPointType.forEach(item => {
                if (item.id == this.$refs.Monitoringpoint.getCheckboxRecords()[0].objType) {
                    list = [item.id]
                    this.objTypeCode = item.code
                } else {
                    if (item.children != undefined) {
                        item.children.forEach(val => {
                            if (val.id == this.$refs.Monitoringpoint.getCheckboxRecords()[0].objType) {
                                list = [item.id, val.id]
                                this.objTypeCode = val.code
                            }
                        })
                    }
                }
            })
            this.form.objType = list
        },
        //修改台区信息确定
        modifyinformationFn() {
            this.$refs.rulesform.validate(value => {
                // console.log(value);
                if (value == true) {
                    this.$confirm('是否确认修改?', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    })
                        .then(() => {
                            this.form.objType = this.$refs['cascader'].getCheckedNodes()[0].data.id //标签上定义的 ref值
                            updateMonitor(this.form).then(res => {
                                if (res.code == 'A0000') {
                                    this.$message({
                                        message: res.message,
                                        type: 'success'
                                    })
                                }
                                this.addinformation = false
                                this.Monitoring()
                            })
                        })
                        .catch(() => {
                            this.$message({
                                type: 'info',
                                message: '已取消修改'
                            })
                        })
                }
            })
        },
        // 删除
        deleteFn() {
            if (this.$refs.Monitoringpoint.getCheckboxRecords().length == 0) {
                this.$message({
                    showClose: true,
                    message: '请选择台账!!!',
                    type: 'warning'
                })
                return
            }
            this.$confirm('是否确认删除?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            })
                .then(() => {
                    let id = []
                    this.$refs.Monitoringpoint.getCheckboxRecords().forEach(item => {
                        id.push(item.id)
                    })

                    delMonitor(id).then(res => {
                        if ((res.code == 'A0000')) {
                            this.$message({
                                type: 'success',
                                message: res.message
                            })
                        }
                        this.Monitoring()
                    })
                })
                .catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    })
                })
        },

        //关闭PMS数据弹框
        // Close() {
        //   this.PMSobtain = false;
        // },

        //checkbox选择事件
        handleSelectionChange(row) {
            // this.$refs.Monitoringpoint.getCheckboxRecords() = row.records
            // console.log(this.$refs.Monitoringpoint.getCheckboxRecords());
        },

        //每页条数改变时触发 选择一页显示多少行
        handleSizeChange(val) {
            this.ruleForm.pageSize = val
            this.Monitoring()
        },
        //当前页改变时触发 跳转其他页
        handleCurrentChange(val) {
            this.ruleForm.pageNum = val
            this.Monitoring()
        },
        cellStyle(row) { },
        //导出
        exportEvent() {
            if (this.flag == 0) {
                let form = JSON.parse(JSON.stringify(this.ruleForm))
                form.pageNum = 1
                form.pageSize = this.total
                getAllMainUserPageList(form).then(res => {
                    this.$refs.Monitoringpoint.exportData({
                        filename: '用户台账', // 文件名字
                        sheetName: 'Sheet1',
                        type: 'xlsx', //导出文件类型 xlsx 和 csv
                        useStyle: true,
                        data: res.data.records, // 数据源 // 过滤那个字段导出
                        columnFilterMethod: function (column, $columnIndex) {
                            return !(column.$columnIndex === 0)
                        }
                    })
                })
            } else {
                exportSend().then(res => {
                    let blob = new Blob([res], {
                        type: 'application/vnd.ms-excel'
                    })
                    const url = window.URL.createObjectURL(blob)
                    const link = document.createElement('a') // 创建a标签
                    link.href = url // link.download = "电压暂降事件分析报告"; // 设置下载的文件名
                    link.download = '典型台账.xls' // 设置下载的文件名
                    document.body.appendChild(link)
                    link.click() //执行下载
                    document.body.removeChild(link)
                })
            }
        },
        Submission() {
            let flag = true
            let isUpToGrid = true
            let flagState = true
            if (this.$refs.Monitoringpoint.getCheckboxRecords().length == 0) {
                return this.$message({
                    message: '请选择用户!',
                    type: 'warning'
                })
            }
            if (this.objTypes.length == 0) {
                return this.$message({
                    message: '请选择监测对象,进行上送!',
                    type: 'warning'
                })
            }

            let state = this.monitorStateList.filter(item => item.code == 'Run')

            let ids = []
            this.$refs.Monitoringpoint.getCheckboxRecords().forEach(item => {
                ids.push(item.id)

                if (this.$refs['SubObjType'].getCheckedNodes()[0].children.length > 0) {
                    this.$refs['SubObjType'].getCheckedNodes()[0].children.forEach(val => {
                        if (item.objType == val.data.id) {
                            return (flag = true)
                        }
                    })
                } else if (item.objType != this.objTypes[this.objTypes.length - 1]) {
                    flag = false
                }
                if (item.isUpToGrid != 1) {
                    isUpToGrid = false
                }
                // if (item.monitorState != state[0].id) {
                //     flagState = false
                // }
            })
            if (this.$refs['SubObjType'].getCheckedNodes()[0].data.id == '987654321') {
                flag = true
            }
            if (flag && isUpToGrid && flagState) {
                this.isLoading = true
                sendType({
                    ids: ids,
                    objType: this.objTypes[0] //this.$refs['SubObjType'].getCheckedNodes()[0].value
                })
                    .then(res => {
                        if (res && res.code == 'A0000') {
                            this.$message({
                                message: '上送成功!',
                                type: 'success'
                            })

                            this.Monitoring()
                        }
                        this.isLoading = false
                    })
                    .catch(err => {
                        this.isLoading = false
                    })
            } else if (flag == false) {
                return this.$message({
                    message: '所选用户与监测对象不符合,请重新选择!',
                    type: 'warning'
                })
            } else if (isUpToGrid == false) {
                return this.$message({
                    message: '所选用户存在非上送网公司用户!',
                    type: 'warning'
                })
            } else if (flagState == false) {
                return this.$message({
                    type: 'warning',
                    message: '请选择运行状态的用户进行上送!'
                })
            }
            // this.objTypeVisible = true
        },
        // 台账上送
        LedgerSubmission() {
            let flag = true
            let isUpToGrid = true
            let flagState = true

            let ids = []
            let state = this.monitorStateList.filter(item => item.code == 'Run')

            this.$refs.Monitoringpoint.getCheckboxRecords().forEach(item => {
                ids.push(item.id)
                if (item.isUpToGrid != 1) {
                    isUpToGrid = false
                }
                // if (item.monitorState != state[0].id) {
                //     flagState = false
                // }
            })

            if (isUpToGrid && flagState) {
                if (this.$refs.Monitoringpoint.getCheckboxRecords().length == 0) {
                    this.$confirm('是否上送全部用户?', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {
                        this.isLoading = true
                        pushMonitor([])
                            .then(res => {
                                if (res && res.code == 'A0000') {
                                    this.isLoading = false
                                    this.$message({
                                        message: '上送成功!',
                                        type: 'success'
                                    })
                                    this.Monitoring()
                                }
                                this.isLoading = false
                            })
                            .catch(err => {
                                this.isLoading = false
                            })
                    })
                } else {
                    this.isLoading = true
                    pushMonitor(ids)
                        .then(res => {
                            if (res && res.code == 'A0000') {
                                this.isLoading = false
                                this.$message({
                                    message: '上送成功!',
                                    type: 'success'
                                })
                                this.Monitoring()
                            }
                            this.isLoading = false
                        })
                        .catch(err => {
                            this.isLoading = false
                        })
                }
            } else if (isUpToGrid == false) {
                return this.$message({
                    message: '所选用户存在非上送网公司用户!',
                    type: 'warning'
                })
            } else if (flagState == false) {
                return this.$message({
                    type: 'warning',
                    message: '请选择运行状态的用户进行上送!'
                })
            }
        },
        SubmitToState() {
            if (this.SubObjType.length == 0) {
                return this.$message({
                    message: '请选择监测对象!',
                    type: 'warning'
                })
            }
        },

        //导入台账
        importLedger() { },

        changeTerminal() {
            this.$forceUpdate()
        },

        handleRemove(file, fileList) {
            // console.log(file, fileList);
        },
        handlePreview(file) {
            // console.log(file);
        },
        handleExceed(files, fileList) {
            this.$message.warning(
                `当前限制选择 1 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length
                } 个文件`
            )
        },
        beforeRemove(file, fileList) {
            return this.$confirm(`确定移除 ${file.name}？`)
        }
    },
    watch: {
        objTypeCode: {
            handler(newVal, oldVal) {
                if (this.objTypeCode != '1402' || this.objTypeCode != '1401') {
                    this.form.fieldStation = ''
                }
                if (this.objTypeCode != '1300') {
                    this.form.tractionId = ''
                }
            }
        }
    }
}
</script>
<style lang="less" scoped>
@import url('../../../../styles/comStyle.less');

::v-deep .vxe-table .cell {
    text-align: center;
}

::v-deep .el-tabs--border-card>.el-tabs__content {
    padding: 0;
}

::v-deep .form {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;

    .el-form-item {
        display: flex;
        width: 48%;

        .el-form-item__content {
            width: calc(100% - 170px) !important;

            // flex: 1 !important;
            .el-select {
                width: 100%;
            }

            .el-input__inner {
                width: 100% !important;
            }

            .el-date-editor {
                width: 100%;
            }
        }
    }
}

.pms {
    margin-left: 10px;
}

.obtain {
    margin-left: 1220px;
}

::v-deep .select {
    width: 100px;
}
</style>
