<template>
    <div class="default-main device-manage" :style="{ height: pageHeight.height }" v-loading="loading">
        <Terminal @node-click="nodeClick" @init="nodeClick"></Terminal>
        <div class="device-manage-right">
            <el-form :inline="true" class="demo-form-inline">
                <el-form-item>
                    <el-button size="small" icon="el-icon-Plus" type="primary" @click="add">新 增</el-button>
                </el-form-item>
                <el-form-item>
                    <el-button size="small" icon="el-icon-Edit" type="primary" @click="update">修 改</el-button>
                </el-form-item>
                <el-form-item>
                    <el-button size="small" icon="el-icon-Close" type="danger" @click="remove">删 除</el-button>
                </el-form-item>
                <el-form-item>
                    <el-button
                        size="small"
                        icon="el-icon-Right"
                        :disabled="nextfalg"
                        type="primary"
                        @click="next"
                        v-if="nodeLevel <= 700 && pageStatus == 2"
                    >
                        下一步
                    </el-button>
                </el-form-item>
                <el-form-item>
                    <el-button
                        size="small"
                        type="info"
                        @click="black"
                        icon="el-icon-Back"
                        v-if="nodeLevel <= 700 && (pageStatus == 2 || pageStatus == 3)"
                    >
                        撤 销
                    </el-button>
                </el-form-item>
                <el-form-item>
                    <el-button
                        size="small"
                        text-align="center"
                        icon="el-icon-Check"
                        type="primary"
                        v-if="pageStatus == 2"
                        @click="onsubmit"
                    >
                        确认提交
                    </el-button>
                </el-form-item>
                <el-form-item>
                    <el-button
                        size="small"
                        text-align="center"
                        icon="el-icon-check"
                        type="primary"
                        v-if="pageStatus == 3"
                        @click="onsubmit"
                    >
                        修改提交
                    </el-button>
                </el-form-item>
                <el-form-item style="right: 0; position: absolute">
                    <!-- <i style="font-size: 20px; color: #396" icon="el-icon-LocationInformation"></i> -->
                    <LocationInformation style="width: 16px; margin-right: 8px; color: #396" />
                    <span style="font-size: 16px; font-weight: bold; color: #396">当前操作节点：</span>
                    <div style="float: right">
                        <el-breadcrumb separator-icon="el-icon-ArrowRightBold" style="font-weight: bold">
                            <!-- <el-breadcrumb-item>台账管理</el-breadcrumb-item> -->
                            <el-breadcrumb-item v-for="item in titleList" :key="item">
                                {{ item }}
                            </el-breadcrumb-item>
                        </el-breadcrumb>
                    </div>
                </el-form-item>
            </el-form>
            <el-form
                class="main-form overview_scroll"
                :label-position="'right'"
                :model="AddProjectBO"
                label-width="120px"
                :inline="true"
                ref="mainForm"
            >
                <el-form-item
                    id="id100"
                    class="form-item"
                    label="项目名称:"
                    :prop="'projectParam.name'"
                    :rules="{ required: true, message: '请输入项目名称', trigger: 'blur' }"
                >
                    <el-select v-model="AddProjectBO.projectParam.name" placeholder="请选择项目类型">
                        <el-option
                            v-for="item in project"
                            :key="item.name"
                            :label="item.name"
                            :value="item.value"
                        ></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item
                    id="id100"
                    class="form-item"
                    label="项目排序:"
                    :prop="'projectParam.sort'"
                    :rules="{ required: true, message: '请输入排序', trigger: 'blur' }"
                >
                    <el-input v-model="AddProjectBO.projectParam.sort" placeholder="请输入排序"></el-input>
                </el-form-item>
                <el-form-item
                    id="id200"
                    class="form-item"
                    label="行政区域:"
                    :prop="'provinceParam.name'"
                    :rules="[{ required: true, message: '请选择行政区域', trigger: 'change' }]"
                >
                    <el-select
                        v-model="AddProjectBO.provinceParam.name"
                        placeholder="请选择行政区域"
                        style="width: 100%"
                    >
                        <el-option
                            v-for="item in treeOptions"
                            :key="item.id"
                            :label="item.name"
                            :value="item.id"
                        ></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item
                    id="id200"
                    class="form-item"
                    label="区域排序:"
                    :prop="'provinceParam.sort'"
                    :rules="[{ required: true, message: '请输入排序', trigger: 'change' }]"
                >
                    <el-input v-model="AddProjectBO.provinceParam.sort" placeholder="请输入排序"></el-input>
                </el-form-item>
                <el-form-item
                    id="id300"
                    class="form-item"
                    label="供电公司:"
                    :prop="'gdInformationParam.name'"
                    :rules="[{ required: true, message: '请输入供电公司', trigger: 'blur' }]"
                >
                    <el-input v-model="AddProjectBO.gdInformationParam.name" placeholder="请输入供电公司"></el-input>
                </el-form-item>
                <el-form-item
                    id="id300"
                    class="form-item"
                    label="公司排序:"
                    :prop="'gdInformationParam.sort'"
                    :rules="[{ required: true, message: '请输入排序', trigger: 'blur' }]"
                >
                    <el-input v-model="AddProjectBO.gdInformationParam.sort" placeholder="请输入排序"></el-input>
                </el-form-item>
                <!--变电站((pageStatus != 3 &&(nodeLevel > 300 && (nodeLevel &lt; 700 || pageStatus == 2))) || (pageStatus == 3 && nodeLevel == 400))-->

                <el-form-item
                    class="form-item"
                    label="变电站:"
                    :prop="'subStationParam.name'"
                    :rules="{ required: true, message: '请输入变电站名称', trigger: 'blur' }"
                >
                    <el-input v-model="AddProjectBO.subStationParam.name" placeholder="请输入变电站名称"></el-input>
                </el-form-item>

                <el-form-item
                    class="form-item"
                    label="经度:"
                    :prop="'subStationParam.lng'"
                    :rules="[{ required: true, validator: lngff, trigger: 'blur' }]"
                >
                    <el-input v-model="AddProjectBO.subStationParam.lng" placeholder="请输入经度"></el-input>
                </el-form-item>

                <el-form-item
                    class="form-item"
                    label="纬度:"
                    :prop="'subStationParam.lat'"
                    :rules="[{ required: true, validator: latff, trigger: 'blur' }]"
                >
                    <el-input v-model="AddProjectBO.subStationParam.lat" placeholder="请输入纬度"></el-input>
                </el-form-item>

                <el-form-item
                    class="form-item"
                    label="电压等级:"
                    :prop="'subStationParam.scale'"
                    :rules="[{ required: true, message: '选中电压等级', trigger: 'change' }]"
                >
                    <el-select v-model="AddProjectBO.subStationParam.scale" placeholder="请选择电压等级">
                        <el-option
                            v-for="item in voltageLevelArr"
                            :key="item.name"
                            :label="item.name"
                            :value="item.id"
                        ></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item
                    class="form-item"
                    label="排序:"
                    :prop="'subStationParam.sort'"
                    :rules="[{ required: true, message: '输入排序', trigger: 'change' }]"
                >
                    <el-input v-model="AddProjectBO.subStationParam.sort" placeholder="请输入排序"></el-input>
                </el-form-item>

                <!--终端设备-->
                <div
                    id="id500"
                    class="form-device"
                    v-if="
                        (pageStatus != 3 && nodeLevel > 300 && (nodeLevel <= 700 || pageStatus == 2)) ||
                        (pageStatus == 3 && 400 < nodeLevel && nodeLevel <= 700)
                    "
                >
                    <el-tabs
                        v-if="AddProjectBO.deviceParam && AddProjectBO.deviceParam.length"
                        v-model="deviceIndex"
                        type="card"
                        :editable="pageStatus != 1"
                        @edit="handleDeviceTabsEdit"
                        @tab-click="tabChange('deviceIndex')"
                    >
                        <el-tab-pane
                            v-for="(item, index) in AddProjectBO.deviceParam"
                            :key="index"
                            :label="item.name ? item.name : '新建终端' + index"
                            :name="index + ''"
                        >
                            <div class="flex">
                                <el-form-item
                                    class="form-item"
                                    label="名称:"
                                    :prop="'deviceParam.' + index + '.name'"
                                    :rules="[{ required: true, message: '请输入名称', trigger: 'blur' }]"
                                >
                                    <el-input
                                        v-model="item.name"
                                        :disabled="
                                            nodeLevel > 500 && (pageStatus == 3 || pageStatus == 2)
                                                ? pageStatus == 3 || pageStatus == 2
                                                : pageStatus == 1
                                        "
                                        placeholder="请输入名称"
                                    ></el-input>
                                </el-form-item>
                                <el-form-item
                                    class="form-item"
                                    label="通讯状态:"
                                    :prop="'deviceParam.' + index + '.comFlag'"
                                    :rules="[{ required: true, message: '请选择通讯状态', trigger: 'change' }]"
                                >
                                    <el-select v-model="item.comFlag" placeholder="请选择通讯状态" :disabled="true">
                                        <el-option
                                            v-for="option in comStatusArr"
                                            :key="option.name"
                                            :label="option.name"
                                            :value="option.value"
                                        ></el-option>
                                    </el-select>
                                </el-form-item>
                                <el-form-item
                                    class="form-item"
                                    label="通讯类型:"
                                    :prop="'deviceParam.' + index + '.frontType'"
                                    :rules="[{ required: true, message: '请选择通讯类型', trigger: 'change' }]"
                                >
                                    <el-select
                                        v-model="item.frontType"
                                        placeholder="请选择通讯类型"
                                        :popper-append-to-body="false"
                                        :disabled="
                                            nodeLevel > 500 && (pageStatus == 3 || pageStatus == 2)
                                                ? pageStatus == 3 || pageStatus == 2
                                                : pageStatus == 1
                                        "
                                    >
                                        <el-option
                                            v-for="option in comTypeStatusArr"
                                            :key="option.id"
                                            :label="option.name"
                                            :value="option.id"
                                        ></el-option>
                                    </el-select>
                                </el-form-item>
                                <el-form-item
                                    class="form-item"
                                    label="终端模型:"
                                    :prop="'deviceParam.' + index + '.devModel'"
                                    :rules="[{ required: true, message: '请选择终端模型', trigger: 'change' }]"
                                >
                                    <el-select
                                        v-model="item.devModel"
                                        placeholder="请选择终端模型"
                                        :disabled="
                                            nodeLevel > 500 && (pageStatus == 3 || pageStatus == 2)
                                                ? pageStatus == 3 || pageStatus == 2
                                                : pageStatus == 1
                                        "
                                    >
                                        <el-option
                                            v-for="option in terminalModelArr"
                                            :key="option.name"
                                            :label="option.name"
                                            :value="option.value"
                                        ></el-option>
                                    </el-select>
                                </el-form-item>
                                <el-form-item
                                    class="form-item"
                                    label="数据模型:"
                                    :prop="'deviceParam.' + index + '.devDataType'"
                                    :rules="[{ required: true, message: '请选择数据模型', trigger: 'change' }]"
                                >
                                    <el-select
                                        v-model="item.devDataType"
                                        placeholder="请选择数据模型"
                                        :disabled="
                                            nodeLevel > 500 && (pageStatus == 3 || pageStatus == 2)
                                                ? pageStatus == 3 || pageStatus == 2
                                                : pageStatus == 1
                                        "
                                    >
                                        <el-option
                                            v-for="option in dataModelArr"
                                            :key="option.name"
                                            :label="option.name"
                                            :value="option.value"
                                        ></el-option>
                                    </el-select>
                                </el-form-item>
                                <el-form-item
                                    class="form-item"
                                    label="厂家:"
                                    :prop="'deviceParam.' + index + '.manufacturer'"
                                    :rules="[{ required: true, message: '请选择厂家', trigger: 'change' }]"
                                >
                                    <el-select
                                        v-model="item.manufacturer"
                                        placeholder="请选择厂家"
                                        :popper-append-to-body="false"
                                        :disabled="
                                            nodeLevel > 500 && (pageStatus == 3 || pageStatus == 2)
                                                ? pageStatus == 3 || pageStatus == 2
                                                : pageStatus == 1
                                        "
                                    >
                                        <el-option
                                            v-for="option in factoryArr"
                                            :key="option.id"
                                            :label="option.name"
                                            :value="option.id"
                                        ></el-option>
                                    </el-select>
                                </el-form-item>
                                <el-form-item
                                    class="form-item"
                                    label="所属前置机:"
                                    :prop="'deviceParam.' + index + '.nodeId'"
                                    :rules="[{ required: true, message: '请选择所属前置机', trigger: 'change' }]"
                                >
                                    <el-select
                                        v-model="item.nodeId"
                                        placeholder="请选择所属前置机"
                                        :disabled="
                                            nodeLevel > 500 && (pageStatus == 3 || pageStatus == 2)
                                                ? pageStatus == 3 || pageStatus == 2
                                                : pageStatus == 1
                                        "
                                    >
                                        <el-option
                                            v-for="option in affiliatiedFrontArr"
                                            :key="option.id"
                                            :label="option.name"
                                            :value="option.id"
                                        ></el-option>
                                    </el-select>
                                </el-form-item>
                                <el-form-item
                                    class="form-item"
                                    label="召唤标志:"
                                    :prop="'deviceParam.' + index + '.callFlag'"
                                    :rules="[{ required: true, message: '请选择召唤标志', trigger: 'change' }]"
                                >
                                    <el-select
                                        v-model="item.callFlag"
                                        placeholder="请选择召唤标志"
                                        :disabled="
                                            nodeLevel > 500 && (pageStatus == 3 || pageStatus == 2)
                                                ? pageStatus == 3 || pageStatus == 2
                                                : pageStatus == 1
                                        "
                                    >
                                        <el-option
                                            v-for="option in summonSignArr"
                                            :key="option.name"
                                            :label="option.name"
                                            :value="option.value"
                                        ></el-option>
                                    </el-select>
                                </el-form-item>
                                <el-form-item
                                    class="form-item"
                                    label="识别码:"
                                    :prop="'deviceParam.' + index + '.series'"
                                >
                                    <el-input
                                        v-model="item.series"
                                        :disabled="
                                            nodeLevel > 500 && (pageStatus == 3 || pageStatus == 2)
                                                ? pageStatus == 3 || pageStatus == 2
                                                : pageStatus == 1
                                        "
                                        show-password
                                        placeholder="请输入识别码"
                                    ></el-input>
                                </el-form-item>
                                <el-form-item
                                    class="form-item"
                                    label="密钥:"
                                    :prop="'deviceParam.' + index + '.devKey'"
                                >
                                    <el-input
                                        v-model="item.devKey"
                                        :disabled="
                                            nodeLevel > 500 && (pageStatus == 3 || pageStatus == 2)
                                                ? pageStatus == 3 || pageStatus == 2
                                                : pageStatus == 1
                                        "
                                        show-password
                                        placeholder="请输入密钥"
                                    ></el-input>
                                </el-form-item>
                                <el-form-item
                                    class="form-item"
                                    label="电度功能"
                                    :prop="'deviceParam.' + index + '.electroplate'"
                                    :rules="[{ required: true, message: '请选择电度功能', trigger: 'change' }]"
                                >
                                    <el-select
                                        v-model="item.electroplate"
                                        placeholder="请选择电度功能"
                                        :disabled="
                                            nodeLevel > 500 && (pageStatus == 3 || pageStatus == 2)
                                                ? pageStatus == 3 || pageStatus == 2
                                                : pageStatus == 1
                                        "
                                    >
                                        <el-option
                                            v-for="option in electroplateCanArr"
                                            :key="option.name"
                                            :label="option.name"
                                            :value="option.value"
                                        ></el-option>
                                    </el-select>
                                </el-form-item>
                                <el-form-item class="form-item" label="投运时间:">
                                    <el-date-picker
                                        :popper-append-to-body="false"
                                        type="date"
                                        placeholder="选择日期"
                                        format="yyyy-MM-dd"
                                        style="width: 100%"
                                        value-format="yyyy-MM-dd"
                                        v-model="item.loginTime"
                                        :disabled="
                                            nodeLevel > 500 && (pageStatus == 3 || pageStatus == 2)
                                                ? pageStatus == 3 || pageStatus == 2
                                                : pageStatus == 1
                                        "
                                    ></el-date-picker>
                                </el-form-item>
                                <el-form-item class="form-item" label="本次定检时间:">
                                    <el-date-picker
                                        :popper-append-to-body="false"
                                        type="date"
                                        placeholder="选择日期"
                                        format="yyyy-MM-dd"
                                        style="width: 100%"
                                        value-format="yyyy-MM-dd"
                                        v-model="item.thisTimeCheck"
                                        :disabled="
                                            nodeLevel > 500 && (pageStatus == 3 || pageStatus == 2)
                                                ? pageStatus == 3 || pageStatus == 2
                                                : pageStatus == 1
                                        "
                                    ></el-date-picker>
                                </el-form-item>
                                <el-form-item class="form-item" label="下次定检时间:">
                                    <el-date-picker
                                        :popper-append-to-body="false"
                                        type="date"
                                        placeholder="选择日期"
                                        format="yyyy-MM-dd"
                                        style="width: 100%"
                                        value-format="yyyy-MM-dd"
                                        v-model="item.nextTimeCheck"
                                        :disabled="
                                            nodeLevel > 500 && (pageStatus == 3 || pageStatus == 2)
                                                ? pageStatus == 3 || pageStatus == 2
                                                : pageStatus == 1
                                        "
                                    ></el-date-picker>
                                </el-form-item>
                                <el-form-item class="form-item" label="数据更新时间:">
                                    <el-date-picker
                                        type="date"
                                        placeholder="选择日期"
                                        format="yyyy-MM-dd"
                                        value-format="yyyy-MM-dd"
                                        v-model="item.updateTime"
                                        style="width: 100%"
                                        :disabled="true"
                                    ></el-date-picker>
                                </el-form-item>
                                <el-form-item
                                    class="form-item"
                                    label="端口号:"
                                    :prop="'deviceParam.' + index + '.port'"
                                    :rules="[{ required: true, message: '请输入端口号', trigger: 'blur' }]"
                                >
                                    <el-input
                                        v-model="item.port"
                                        placeholder="请输入端口号"
                                        :disabled="
                                            nodeLevel > 500 && (pageStatus == 3 || pageStatus == 2)
                                                ? pageStatus == 3 || pageStatus == 2
                                                : pageStatus == 1
                                        "
                                    ></el-input>
                                </el-form-item>
                                <el-form-item
                                    class="form-item"
                                    label="合同号:"
                                    :prop="'deviceParam.' + index + '.contract'"
                                    :rules="[{ required: true, message: '请输入合同号', trigger: 'blur' }]"
                                >
                                    <el-input
                                        v-model="item.contract"
                                        placeholder="请输入合同号"
                                        :disabled="
                                            nodeLevel > 500 && (pageStatus == 3 || pageStatus == 2)
                                                ? pageStatus == 3 || pageStatus == 2
                                                : pageStatus == 1
                                        "
                                    ></el-input>
                                </el-form-item>
                                <el-form-item
                                    class="form-item"
                                    label="ISM卡号:"
                                    :prop="'deviceParam.' + index + '.sim'"
                                    :rules="[{ required: true, message: '请输入ISM卡号', trigger: 'blur' }]"
                                >
                                    <el-input
                                        v-model="item.sim"
                                        placeholder="请输入ISM卡号"
                                        :disabled="
                                            nodeLevel > 500 && (pageStatus == 3 || pageStatus == 2)
                                                ? pageStatus == 3 || pageStatus == 2
                                                : pageStatus == 1
                                        "
                                    ></el-input>
                                </el-form-item>
                                <el-form-item
                                    class="form-item"
                                    label="排序:"
                                    :prop="'deviceParam.' + index + '.sort'"
                                    :rules="[{ required: true, message: '请输入排序', trigger: 'blur' }]"
                                >
                                    <el-input
                                        v-model="item.sort"
                                        placeholder="请输入排序"
                                        :disabled="
                                            nodeLevel > 500 && (pageStatus == 3 || pageStatus == 2)
                                                ? pageStatus == 3 || pageStatus == 2
                                                : pageStatus == 1
                                        "
                                    ></el-input>
                                </el-form-item>
                            </div>
                        </el-tab-pane>
                    </el-tabs>
                </div>
                <!--母线-->
                <!-- <div
                    id="id600"
                    class="form-bus"
                    v-if="((pageStatus != 3 && (nodeLevel > 400 && (nodeLevel &lt;= 700 || pageStatus == 2))) ||  (pageStatus == 3 && 400 < nodeLevel && nodeLevel &lt;= 700))"
                >
     
                    <el-tabs
                        v-if="
                            AddProjectBO.deviceParam &&
                            AddProjectBO.deviceParam.length &&
                            AddProjectBO.deviceParam[deviceIndex] &&
                            AddProjectBO.deviceParam[deviceIndex].subVoltageParam &&
                            AddProjectBO.deviceParam[deviceIndex].subVoltageParam.length
                        "
                        v-model="busBarIndex"
                        type="card"
                        :editable="pageStatus != 1"
                        @edit="handleBusBarTabsEdit"
                        @tab-click="tabChange('busBarIndex')"
                    >
                        <el-tab-pane
                            v-for="(busItem, bIndex) in AddProjectBO.deviceParam[deviceIndex].subVoltageParam"
                            :key="bIndex"
                            :label="busItem.name ? busItem.name : '新建母线' + bIndex"
                            :name="bIndex + ''"
                        >
                            <div class="flex">
                                <el-form-item
                                    class="form-item"
                                    label="母线名称:"
                                    :prop="'deviceParam.' + [deviceIndex] + '.subVoltageParam.' + bIndex + '.name'"
                                    :rules="{ required: true, message: '请输入母线名称', trigger: 'blur' }"
                                >
                                    <el-input
                                        v-model="busItem.name"
                                        placeholder="请输入母线名称"
                                        :disabled="
                                            nodeLevel > 600 && (pageStatus == 3 || pageStatus == 2)
                                                ? pageStatus == 3 || pageStatus == 2
                                                : pageStatus == 1
                                        "
                                    ></el-input>
                                </el-form-item>
                                <el-form-item
                                    class="form-item"
                                    label="母线编号:"
                                    :prop="'deviceParam.' + [deviceIndex] + '.subVoltageParam.' + bIndex + '.num'"
                                    :rules="{ required: true, message: '请输入母线编号', trigger: 'blur' }"
                                >
                                    <el-select
                                        v-model="busItem.num"
                                        placeholder="请选择母线编号"
                                        :disabled="
                                            nodeLevel > 600 && (pageStatus == 3 || pageStatus == 2)
                                                ? pageStatus == 3 || pageStatus == 2
                                                : pageStatus == 1
                                        "
                                    >
                                        <el-option
                                            v-for="option in optionarr"
                                            :key="option.name"
                                            :label="option.name"
                                            :value="option.value"
                                        ></el-option>
                                    </el-select>
                                </el-form-item>
                                <el-form-item
                                    class="form-item"
                                    label="电压等级:"
                                    :prop="'deviceParam.' + [deviceIndex] + '.subVoltageParam.' + bIndex + '.scale'"
                                    :rules="{ required: true, message: '请选择电压等级', trigger: 'blur' }"
                                >
                                    <el-select
                                        v-model="busItem.scale"
                                        value-key="value"
                                        placeholder="请选择电压等级"
                                        :disabled="
                                            nodeLevel > 600 && (pageStatus == 3 || pageStatus == 2)
                                                ? pageStatus == 3 || pageStatus == 2
                                                : pageStatus == 1
                                        "
                                        @change="selectChanged"
                                    >
                                        <el-option
                                            v-for="option in voltageLevelArr"
                                            :key="option.name"
                                            :label="option.name"
                                            :value="option.value"
                                        ></el-option>
                                    </el-select>
                                </el-form-item>
                                <el-form-item
                                    class="form-item"
                                    label="母线类型:"
                                    :prop="'deviceParam.' + [deviceIndex] + '.subVoltageParam.' + bIndex + '.model'"
                                    :rules="{ required: true, message: '请选择母线类型', trigger: 'blur' }"
                                >
                                    <el-select
                                        v-model="busItem.model"
                                        placeholder="请选择母线类型"
                                        :disabled="
                                            nodeLevel > 600 && (pageStatus == 3 || pageStatus == 2)
                                                ? pageStatus == 3 || pageStatus == 2
                                                : pageStatus == 1
                                        "
                                    >
                                        <el-option
                                            v-for="option in busBarType"
                                            :key="option.name"
                                            :label="option.name"
                                            :value="option.value"
                                        ></el-option>
                                    </el-select>
                                </el-form-item>
                                <el-form-item
                                    class="form-item"
                                    label="排序:"
                                    :prop="'deviceParam.' + [deviceIndex] + '.subVoltageParam.' + bIndex + '.sort'"
                                    :rules="{ required: true, message: '请输入排序', trigger: 'blur' }"
                                >
                                    <el-input
                                        v-model="busItem.sort"
                                        placeholder="请输入排序"
                                        :disabled="
                                            nodeLevel > 600 && (pageStatus == 3 || pageStatus == 2)
                                                ? pageStatus == 3 || pageStatus == 2
                                                : pageStatus == 1
                                        "
                                    ></el-input>
                                </el-form-item>
                            </div>
                        </el-tab-pane>
                    </el-tabs>
                </div> -->
                <!--监测点-->
                <!-- <div
                    id="id700"
                    class="form-point"
                    v-if="((pageStatus != 3 && (nodeLevel > 400 && (nodeLevel &lt;= 700 || pageStatus == 2))) || (pageStatus == 3 && 400 < nodeLevel && nodeLevel &lt;= 700))"
                >
     
                    <el-tabs
                        type="card"
                        v-if="
                            AddProjectBO.deviceParam &&
                            AddProjectBO.deviceParam.length &&
                            AddProjectBO.deviceParam[deviceIndex] &&
                            AddProjectBO.deviceParam[deviceIndex].subVoltageParam &&
                            AddProjectBO.deviceParam[deviceIndex].subVoltageParam.length &&
                            AddProjectBO.deviceParam[deviceIndex].subVoltageParam[busBarIndex] &&
                            AddProjectBO.deviceParam[deviceIndex].subVoltageParam[busBarIndex].lineParam &&
                            AddProjectBO.deviceParam[deviceIndex].subVoltageParam[busBarIndex].lineParam.length
                        "
                        v-model="lineIndex"
                        :editable="pageStatus != 1"
                        @edit="handleLineTabsEdit"
                        @tab-click="tabChange('lineIndex')"
                    >
                        <el-tab-pane
                            v-for="(lineItem, lIndex) in AddProjectBO.deviceParam[deviceIndex].subVoltageParam[
                                busBarIndex
                            ].lineParam"
                            :key="lIndex"
                            :label="lineItem.name ? lineItem.name : '新建监测点' + lIndex"
                            :name="lIndex + ''"
                        >
                            <div class="flex">
                                <el-form-item
                                    class="form-item"
                                    label="监测点名称:"
                                    :prop="
                                        'deviceParam.' +
                                        [deviceIndex] +
                                        '.subVoltageParam.' +
                                        [busBarIndex] +
                                        '.lineParam.' +
                                        lIndex +
                                        '.name'
                                    "
                                    :rules="{ required: true, message: '请输入监测点名称', trigger: 'blur' }"
                                >
                                    <el-input
                                        v-model="lineItem.name"
                                        :disabled="pageStatus == 1"
                                        placeholder="请输入监测点名称"
                                    ></el-input>
                                </el-form-item>
              
                                <el-form-item
                                    class="form-item"
                                    label="监测点序号:"
                                    :prop="
                                        'deviceParam.' +
                                        [deviceIndex] +
                                        '.subVoltageParam.' +
                                        [busBarIndex] +
                                        '.lineParam.' +
                                        lIndex +
                                        '.num'
                                    "
                                    :rules="{ required: true, message: '请选择监测点序号', trigger: 'blur' }"
                                >
                                    <el-select
                                        v-model="lineItem.num"
                                        placeholder="请选择序号"
                                        :disabled="pageStatus == 1"
                                    >
                                        <el-option
                                            v-for="option in pointNumArr"
                                            :key="option.name"
                                            :label="option.name"
                                            :value="option.value"
                                        ></el-option>
                                    </el-select>
                                </el-form-item>
                            
                                <el-form-item class="form-item" label="基准容量(MVA):">
                                    <el-input
                                        v-model="lineItem.standardCapacity"
                                        :disabled="pageStatus == 1"
                                        placeholder="请输入基准容量(MVA)"
                                    ></el-input>
                                </el-form-item>
                                <el-form-item
                                    class="form-item"
                                    label="短路容量(MVA):"
                                    :prop="
                                        'deviceParam.' +
                                        [deviceIndex] +
                                        '.subVoltageParam.' +
                                        [busBarIndex] +
                                        '.lineParam.' +
                                        lIndex +
                                        '.shortCapacity'
                                    "
                                    :rules="{ required: false, message: '请输入短路容量', trigger: 'blur' }"
                                >
                                
                                    <el-input
                                        v-model="lineItem.shortCapacity"
                                        :disabled="pageStatus == 1"
                                        placeholder="请输入短路容量(MVA)"
                                    ></el-input>
                                </el-form-item>
                                <el-form-item
                                    class="form-item"
                                    label="设备容量(MVA):"
                                    :prop="
                                        'deviceParam.' +
                                        [deviceIndex] +
                                        '.subVoltageParam.' +
                                        [busBarIndex] +
                                        '.lineParam.' +
                                        lIndex +
                                        '.devCapacity'
                                    "
                                    :rules="{ required: false, message: '请输入设备容量', trigger: 'blur' }"
                                >
                                    <el-input
                                        v-model="lineItem.devCapacity"
                                        :disabled="pageStatus == 1"
                                        placeholder="请输入设备容量(MVA)"
                                    ></el-input>
                                </el-form-item>
                                <el-form-item
                                    class="form-item"
                                    label="协议容量(MVA):"
                                    :prop="
                                        'deviceParam.' +
                                        [deviceIndex] +
                                        '.subVoltageParam.' +
                                        [busBarIndex] +
                                        '.lineParam.' +
                                        lIndex +
                                        '.dealCapacity'
                                    "
                                    :rules="{ required: false, message: '请输入协议容量', trigger: 'blur' }"
                                >
                                    <el-input
                                        v-model="lineItem.dealCapacity"
                                        :disabled="pageStatus == 1"
                                        placeholder="请输入协议容量(MVA)"
                                    ></el-input>
                                </el-form-item>
                                <el-form-item
                                    class="form-item"
                                    label="测量点间隔:"
                                    :prop="
                                        'deviceParam.' +
                                        [deviceIndex] +
                                        '.subVoltageParam.' +
                                        [busBarIndex] +
                                        '.lineParam.' +
                                        lIndex +
                                        '.timeInterval'
                                    "
                                    :rules="{ required: true, message: '请选择测点间隔', trigger: 'blur' }"
                                >
                                    <el-select
                                        v-model="lineItem.timeInterval"
                                        placeholder="请选择测量点间隔"
                                        :disabled="pageStatus == 1"
                                    >
                                        <el-option
                                            v-for="option in lineSpaceArr"
                                            :key="option.name"
                                            :label="option.name"
                                            :value="option.value"
                                        ></el-option>
                                    </el-select>
                                </el-form-item>
                                <el-form-item
                                    class="form-item"
                                    label="PT变比:"
                                    :prop="
                                        'deviceParam.' +
                                        [deviceIndex] +
                                        '.subVoltageParam.' +
                                        [busBarIndex] +
                                        '.lineParam.' +
                                        lIndex +
                                        '.pt1'
                                    "
                                    :rules="{ required: true, message: '请输入pt', trigger: 'blur' }"
                                >
                                    <div class="flex" style="justify-content: space-between">
                                        <el-input
                                            style="width: 48%"
                                            v-model="lineItem.pt1"
                                            :disabled="pageStatus == 1"
                                        ></el-input>
                                        <el-input
                                            style="width: 48%"
                                            v-model="lineItem.pt2"
                                            :disabled="pageStatus == 1"
                                        ></el-input>
                                    </div>
                                </el-form-item>
                                <el-form-item
                                    class="form-item"
                                    label="CT变比:"
                                    :prop="
                                        'deviceParam.' +
                                        [deviceIndex] +
                                        '.subVoltageParam.' +
                                        [busBarIndex] +
                                        '.lineParam.' +
                                        lIndex +
                                        '.ct1'
                                    "
                                    :rules="{ required: true, message: '请输入ct', trigger: 'blur' }"
                                >
                                    <div class="flex" style="justify-content: space-between">
                                        <el-input
                                            style="width: 48%"
                                            v-model="lineItem.ct1"
                                            :disabled="pageStatus == 1"
                                        ></el-input>
                                        <el-input
                                            style="width: 48%"
                                            v-model="lineItem.ct2"
                                            :disabled="pageStatus == 1"
                                        ></el-input>
                                    </div>
                                </el-form-item>
                                <el-form-item
                                    class="form-item"
                                    label="接线类型:"
                                    :prop="
                                        'deviceParam.' +
                                        [deviceIndex] +
                                        '.subVoltageParam.' +
                                        [busBarIndex] +
                                        '.lineParam.' +
                                        lIndex +
                                        '.ptType'
                                    "
                                    :rules="{ required: true, message: '请选择接线类型', trigger: 'blur' }"
                                >
                                    <el-select
                                        v-model="lineItem.ptType"
                                        placeholder="请选择接线类型"
                                        :disabled="pageStatus == 1"
                                    >
                                        <el-option
                                            v-for="option in wiringTypeArr"
                                            :key="option.name"
                                            :label="option.name"
                                            :value="option.value"
                                        ></el-option>
                                    </el-select>
                                </el-form-item>
                                <el-form-item
                                    class="form-item"
                                    label="干扰源类型:"
                                    :prop="
                                        'deviceParam.' +
                                        [deviceIndex] +
                                        '.subVoltageParam.' +
                                        [busBarIndex] +
                                        '.lineParam.' +
                                        lIndex +
                                        '.loadType'
                                    "
                                    :rules="{ required: true, message: '请选择干扰源类型', trigger: 'blur' }"
                                >
                                    <el-select
                                        v-model="lineItem.loadType"
                                        placeholder="请选择干扰源类型"
                                        :disabled="pageStatus == 1"
                                    >
                                        <el-option
                                            v-for="option in loadTypeArr"
                                            :key="option.id"
                                            :label="option.name"
                                            :value="option.id"
                                        ></el-option>
                                    </el-select>
                                </el-form-item>
                                <el-form-item
                                    class="form-item"
                                    label="行业类型:"
                                    :prop="
                                        'deviceParam.' +
                                        [deviceIndex] +
                                        '.subVoltageParam.' +
                                        [busBarIndex] +
                                        '.lineParam.' +
                                        lIndex +
                                        '.businessType'
                                    "
                                    :rules="{ required: true, message: '请选择行业类型', trigger: 'blur' }"
                                >
                                    <el-select
                                        v-model="lineItem.businessType"
                                        placeholder="请选择行业类型"
                                        :disabled="pageStatus == 1"
                                    >
                                        <el-option
                                            v-for="option in industryTypeArr"
                                            :key="option.id"
                                            :label="option.name"
                                            :value="option.id"
                                        ></el-option>
                                    </el-select>
                                </el-form-item>
                                <el-form-item
                                    class="form-item"
                                    label="谐波监测号:"
                                    :prop="
                                        'deviceParam.' +
                                        [deviceIndex] +
                                        '.subVoltageParam.' +
                                        [busBarIndex] +
                                        '.lineParam.' +
                                        lIndex +
                                        '.monitorId'
                                    "
                                >
                                    <el-input
                                        v-model="lineItem.monitorId"
                                        :disabled="pageStatus == 1"
                                        placeholder="请输入国网谐波监测号"
                                    ></el-input>
                                </el-form-item>
                                <el-form-item
                                    class="form-item"
                                    label="电压下偏差:"
                                    :prop="
                                        'deviceParam.' +
                                        [deviceIndex] +
                                        '.subVoltageParam.' +
                                        [busBarIndex] +
                                        '.lineParam.' +
                                        lIndex +
                                        '.uvoltageDev'
                                    "
                                    :rules="{ required: true, message: '请输入电压下偏差', trigger: 'blur' }"
                                >
                                    <el-input
                                        v-model="lineItem.uvoltageDev"
                                        :disabled="pageStatus == 1"
                                        placeholder="请输入电压下偏差"
                                    ></el-input>
                                </el-form-item>
                                <el-form-item
                                    class="form-item"
                                    label="对象名称:"
                                    :prop="
                                        'deviceParam.' +
                                        [deviceIndex] +
                                        '.subVoltageParam.' +
                                        [busBarIndex] +
                                        '.lineParam.' +
                                        lIndex +
                                        '.objName'
                                    "
                                >
                                    <el-input
                                        v-model="lineItem.objName"
                                        :disabled="pageStatus == 1"
                                        placeholder="请输入对象名称"
                                    ></el-input>
                                </el-form-item>
                                <el-form-item
                                    class="form-item"
                                    label="测量点性质:"
                                    :prop="
                                        'deviceParam.' +
                                        [deviceIndex] +
                                        '.subVoltageParam.' +
                                        [busBarIndex] +
                                        '.lineParam.' +
                                        lIndex +
                                        '.powerFlag'
                                    "
                                    :rules="{ required: true, message: '请选择测量点性质', trigger: 'blur' }"
                                >
                                    <el-select
                                        v-model="lineItem.powerFlag"
                                        placeholder="请选择测量点性质"
                                        :disabled="pageStatus == 1"
                                    >
                                        <el-option
                                            v-for="option in lineNatureArr"
                                            :key="option.name"
                                            :label="option.name"
                                            :value="option.value"
                                        ></el-option>
                                    </el-select>
                                </el-form-item>
                                <el-form-item
                                    class="form-item"
                                    label="电压上偏差:"
                                    :prop="
                                        'deviceParam.' +
                                        [deviceIndex] +
                                        '.subVoltageParam.' +
                                        [busBarIndex] +
                                        '.lineParam.' +
                                        lIndex +
                                        '.voltageDev'
                                    "
                                    :rules="{ required: true, message: '请输入电压上偏差', trigger: 'blur' }"
                                >
                                    <el-input
                                        v-model="lineItem.voltageDev"
                                        :disabled="pageStatus == 1"
                                        placeholder="请输入电压上偏差"
                                    ></el-input>
                                </el-form-item>
                                <el-form-item
                                    class="form-item"
                                    label="备注:"
                                    :prop="
                                        'deviceParam.' +
                                        [deviceIndex] +
                                        '.subVoltageParam.' +
                                        [busBarIndex] +
                                        '.lineParam.' +
                                        lIndex +
                                        '.remark'
                                    "
                                >
                                    <el-input
                                        v-model="lineItem.remark"
                                        :disabled="pageStatus == 1"
                                        placeholder="请输入备注"
                                    ></el-input>
                                </el-form-item>
                                <el-form-item
                                    class="form-item"
                                    label="分类等级:"
                                    :prop="
                                        'deviceParam.' +
                                        [deviceIndex] +
                                        '.subVoltageParam.' +
                                        [busBarIndex] +
                                        '.lineParam.' +
                                        lIndex +
                                        '.calssificationGrade'
                                    "
                                    :rules="{ required: true, message: '请选择分类等级', trigger: 'blur' }"
                                >
                                    <el-select
                                        v-model="lineItem.calssificationGrade"
                                        placeholder="请选择分类等级"
                                        :disabled="pageStatus == 1"
                                    >
                                        <el-option
                                            v-for="option in pointTypeArr"
                                            :key="option.name"
                                            :label="option.name"
                                            :value="option.value"
                                        ></el-option>
                                    </el-select>
                                </el-form-item>
                                <el-form-item
                                    class="form-item"
                                    label="监测点拥有者:"
                                    :prop="
                                        'deviceParam.' +
                                        [deviceIndex] +
                                        '.subVoltageParam.' +
                                        [busBarIndex] +
                                        '.lineParam.' +
                                        lIndex +
                                        '.owner'
                                    "
                                    :rules="{ required: true, message: '请输入监测点拥有者', trigger: 'blur' }"
                                >
                                    <el-input
                                        v-model="lineItem.owner"
                                        :disabled="pageStatus == 1"
                                        placeholder="请输入监测点拥有者"
                                    ></el-input>
                                </el-form-item>
                                <el-form-item
                                    class="form-item"
                                    label="拥有者职务:"
                                    :prop="
                                        'deviceParam.' +
                                        [deviceIndex] +
                                        '.subVoltageParam.' +
                                        [busBarIndex] +
                                        '.lineParam.' +
                                        lIndex +
                                        '.ownerDuty'
                                    "
                                    :rules="{ required: true, message: '请输入拥有者职务', trigger: 'blur' }"
                                >
                                    <el-input
                                        v-model="lineItem.ownerDuty"
                                        :disabled="pageStatus == 1"
                                        placeholder="请输入拥有者职务"
                                    ></el-input>
                                </el-form-item>
                                <el-form-item
                                    class="form-item"
                                    label="电网侧变电站:"
                                    :prop="
                                        'deviceParam.' +
                                        [deviceIndex] +
                                        '.subVoltageParam.' +
                                        [busBarIndex] +
                                        '.lineParam.' +
                                        lIndex +
                                        '.powerSubstationName'
                                    "
                                    :rules="{ required: true, message: '请输入电网侧变电站', trigger: 'blur' }"
                                >
                                    <el-input
                                        v-model="lineItem.powerSubstationName"
                                        :disabled="pageStatus == 1"
                                        placeholder="请输入电网侧变电站"
                                    ></el-input>
                                </el-form-item>
                                <el-form-item
                                    class="form-item"
                                    label="上级变电站:"
                                    :prop="
                                        'deviceParam.' +
                                        [deviceIndex] +
                                        '.subVoltageParam.' +
                                        [busBarIndex] +
                                        '.lineParam.' +
                                        lIndex +
                                        '.superiorsSubstation'
                                    "
                                    :rules="{ required: true, message: '请输入上级变电站', trigger: 'blur' }"
                                >
                                    <el-input
                                        v-model="lineItem.superiorsSubstation"
                                        :disabled="pageStatus == 1"
                                        placeholder="请输入上级变电站"
                                    ></el-input>
                                </el-form-item>
                                <el-form-item
                                    class="form-item"
                                    label="排序:"
                                    :prop="
                                        'deviceParam.' +
                                        [deviceIndex] +
                                        '.subVoltageParam.' +
                                        [busBarIndex] +
                                        '.lineParam.' +
                                        lIndex +
                                        '.sort'
                                    "
                                    :rules="{ required: true, message: '请输入排序', trigger: 'blur' }"
                                >
                                    <el-input
                                        v-model="lineItem.sort"
                                        :disabled="pageStatus == 1"
                                        placeholder="请输入排序"
                                    ></el-input>
                                </el-form-item>
                            </div>
                        </el-tab-pane>
                    </el-tabs>
                </div> -->
            </el-form>
        </div>
    </div>
</template>

<script setup lang="ts">
defineOptions({
    name: 'device-boot/deviceter'
})
import { LocationInformation } from '@element-plus/icons-vue'
import Terminal from '@/components/tree/pms/Terminal.vue'
import { mainHeight } from '@/utils/layout'
import { areaTree } from '@/api/system-boot/dicData'
import { queryTerminal, nodeAllList, delTerminal } from '@/api/Business'
import { useDictData } from '@/stores/dictData'
import { ref, reactive } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
const pageHeight = mainHeight(20)
const loading = ref(false)
const nextfalg = ref(false)
const dictData = useDictData()
const nodeLevel = ref(0)
const pageStatus = ref(1)
const titleList: any = ref([])
const nodeData: any = ref([])
const treeOptions: any = ref([])
const deviceIndex: any = ref('0')
const busBarIndex: any = ref('0')
const lineIndex: any = ref('0')

const projectId: any = ref('0')
const provinceId: any = ref('0')
const gdId: any = ref('0')
const subId: any = ref('0')
const devId: any = ref('0')
const busBarId: any = ref('0')
const lineId: any = ref('0')

const currentGdName: any = ref('')
const affiliatiedFrontArr: any = ref([])
const comTypeStatusArr = dictData.getBasicData('Front_Type')
const factoryArr = dictData.getBasicData('Dev_Manufacturers')
const voltageLevelArr = dictData.getBasicData('Dev_Voltage_Stand')
const typeArr = dictData.getBasicData('Dev_Type')
const industryTypeArr = dictData.getBasicData('Business_Type')
const loadTypeArr = dictData.getBasicData('Interference_Source')
const comStatusArr = ref([
    { name: '中断', value: 0 },
    { name: '正常', value: 1 }
])

/**终端模型选项 */
const terminalModelArr = ref([
    { name: '实际终端', value: 1 },
    { name: '虚拟终端', value: 0 },
    { name: '离线终端', value: 2 }
])
/**电镀功能选项 */
const electroplateCanArr = ref([
    { name: '开启', value: 0 },
    { name: '关闭', value: 1 }
])
/**数据模型选项 */
const dataModelArr = ref([
    { name: '双系统', value: 2 },
    { name: '暂降系统', value: 0 },
    { name: '稳态系统', value: 1 }
])
/**召唤标志选项 */
const summonSignArr = ref([
    { name: '变位触发', value: 0 },
    { name: '周期触发', value: 1 }
])
const busBarDetail = ref({
    /**母线名称 */
    name: '',
    /**母线编号 */
    num: 1,
    /**电压等级 */
    scale: '',
    /**母线类型 */
    model: 0,
    /**母线id */
    subvIndex: '',
    /**监测点 */
    lineParam: [],
    /**排序 */
    sort: 0
})
/**监测点详情 */
const monitorPointDetail:any = ref({
    /**行业类型 */
    businessType: '',
    /**CT变比 */
    ct1: '',
    /**CT变比 */
    ct2: '',
    /**所属部门 */
    deptIndex: '',
    /**设备容量 */
    devCapacity: '',
    /**短路容量 */
    shortCapacity: '',
    /**基准容量 */
    standardCapacity: '',
    /**监测点id */
    lineIndex: '',
    /**监测点序号 */
    num: 1,
    //分类等级
    calssificationGrade: 1,
    //电网测变电站
    powerSubstationName: '',
    //监测点拥有着
    owner: '',
    //拥有者职位
    ownerDuty: '',
    //上级变电站
    superiorsSubstation: '',
    /**负荷类型 */
    loadType: '',
    /**国网监测号 */
    monitorId: '',
    /**监测点名称 */
    name: '',
    /**对象名称 */
    objName: '',
    /**监测点性质 */
    powerFlag: 0,
    /**PT比 */
    pt1: 0,
    /**PT比 */
    pt2: 0,
    /**接线类型 */
    ptType: 0,
    /**测点间隔 */
    timeInterval: 1,
    /**协议容量 */
    dealCapacity: '',
    /**电压等级 */
    scale: '',
    /**备注 */
    remark: '',
    /**电压上偏差 */
    voltageDev: 10,
    /**电压下偏差 */
    uvoltageDev: 10,
    /**供电公司 */
    gdName: currentGdName.value,
    /**排序 */
    sort: 0
})
const subStationParam = ref({
    /**名称 */
    name: '',
    /**经度 */
    lng: '0',
    /**纬度 */
    lat: '0',
    /**电压等级 */
    scale: '',
    /**排序 */
    sort: 0
})
const AddProjectBO: any = ref({
    /**项目Id */
    projectIndex: 0,
    /**行政区域Id */
    provinceIndex: 0,
    /**供电公司Id*/
    gdIndex: 0,
    /**变电站Id*/
    subIndex: 0,
    /**设备Id */
    devIndex: 0,
    /**母线ID */
    subvIndex: 0,
    /**项目名称 */
    projectParam: {
        name: '',
        sort: 0
    },
    /**行政区域 */
    provinceParam: {
        name: '',
        sort: 0
    },
    /**供电公司 */
    gdInformationParam: {
        name: '',
        sort: 0
    },
    /**变电站 */
    subStationParam: {
        name: '',
        lng: '0',
        lat: '0',
        scale: '',
        sort: 0
    },
    /**终端设备   母线  母线下面subVoltage是监测点*/
    deviceParam: null
})
const deviceBODetail: any = ref({
    /**名称 */
    name: '',
    /**设备id*/
    devIndex: '',
    /**设备型号 */
    devType: '',
    /**ip */
    ip: '255.255.255.255',
    /**通讯状态 */
    comFlag: 0,
    /**通讯类型 */
    frontType: '',
    /**投运时间 */
    loginTime: '',
    /**数据更新时间 */
    updateTime: '',
    /**所属变电站 */
    zhan: '',
    /**所属前置机 */
    nodeId: '',
    /**终端模型 */
    devModel: 1,
    /**本次定检时间 */
    thisTimeCheck: '',
    /**下次定检时间 */
    nextTimeCheck: '',
    /**厂家 */
    manufacturer: '',
    /**数据模型 */
    devDataType: 2,
    /**端口号 */
    port: 102,
    /**排序 */
    sort: 0,
    //合同号
    contract: '',
    //ISM卡号
    sim: '',
    /**电镀功能 */
    electroplate: 0,
    /**识别码 */
    series: '',
    /**召唤标志 */
    callFlag: 0,
    /**密钥 */
    devKey: '',
    /**母线*/
    subVoltageParam: [],
    /**供电公司 */
    gdName: currentGdName.value
})
const project = ref([
    { name: '在线项目', value: '在线项目' },
    { name: '普测项目', value: '普测项目' }
])
const arrdess: any = ref((rule: any, value: any, callback: any) => {
    let reg1 =
        /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/
    let reg2 =
        /^[A-Fa-f0-9]{1,2}\-[A-Fa-f0-9]{1,2}\-[A-Fa-f0-9]{1,2}\-[A-Fa-f0-9]{1,2}\-[A-Fa-f0-9]{1,2}\-[A-Fa-f0-9]{1,2}$/
    let reg3 =
        /^[A-Fa-f0-9]{1,2}\:[A-Fa-f0-9]{1,2}\:[A-Fa-f0-9]{1,2}\:[A-Fa-f0-9]{1,2}\:[A-Fa-f0-9]{1,2}\:[A-Fa-f0-9]{1,2}$/
    if (reg1.test(value)) {
        return true
    } else if (reg2.test(value)) {
        return true
    } else if (reg3.test(value)) {
        return true
    } else if (value == '') {
        return callback(new Error('请输入IP/MAC地址'))
    } else {
        callback(new Error('请输入正确IP/MAC地址'))
    }
})
/**经度 */
const lngff: any = ref((rule: any, value: any, callback: any) => {
    let reg1 = /^(([1-9]\d?)|(1[0-7]\d))(\.\d{1,6})|180|0(\.\d{1,6})?/
    if (reg1.test(value)) {
        return true
    } else if (value == '') {
        return callback(new Error('请输入经度'))
    } else {
        callback(new Error('请输入正确经度'))
    }
})
/**纬度 */
const latff: any = ref((rule: any, value: any, callback: any) => {
    let reg2 = /^(\-|\+)?([0-8]?\d{1}\.\d{0,6}|90\.0{0,6}|[0-8]?\d{1}|90)$/
    if (reg2.test(value)) {
        return true
    } else if (value == '') {
        return callback(new Error('请输入纬度'))
    } else {
        callback(new Error('请输入正确纬度'))
    }
})
const nodeClick = (e: anyObj, data: any) => {
    titleList.value = []
    getparentsNode(data)
    pageStatus.value = 1
    nodeLevel.value = data.data.level
    nodeData.value = e
    if (data.level > 400) {
        getNodeIndex()
    }
    /**不是根节点请求数据 */
    if (nodeLevel.value) {
        queryNodeContent()
    } else {
        /**清空数据 */
        initAddProjectBo()
        initAddProjectBoId()
    }
}
const getparentsNode = (node: any) => {
    if (!node.parent) {
        return
    }
    titleList.value.unshift(node.label)
    getparentsNode(node.parent) //调用递归
}

// 新增
const add = () => {
    if (pageStatus.value == 2 || pageStatus.value == 3) {
        if (pageStatus.value == 3) {
            ElMessage({
                type: 'warning',
                message: '请先提交修改,再新增'
            })
        }
        return
    }
    pageStatus.value = 2
    /**删除Id属性 */
    delete AddProjectBO.value.projectIndex
    delete AddProjectBO.value.provinceIndex
    delete AddProjectBO.value.gdIndex
    delete AddProjectBO.value.subIndex
    delete AddProjectBO.value.devIndex
    delete AddProjectBO.value.subvIndex
    // switch (this.nodeData.data.level) {
    switch (nodeLevel.value) {
        case 0:
            addProject()
            break
        case 100:
            initAddProjectBo()
            AddProjectBO.value.projectIndex = projectId.value
            addProvince()
            break
        case 200:
            initAddProjectBo()
            AddProjectBO.value.projectIndex = projectId.value
            AddProjectBO.value.provinceIndex = provinceId.value
            addGdInformation()
            break
        case 300:
            initAddProjectBo()
            AddProjectBO.value.projectIndex = projectId.value
            AddProjectBO.value.provinceIndex = provinceId.value
            AddProjectBO.value.gdIndex = gdId.value
            addSubStation()
            break
        case 400:
            initAddProjectBo()
            AddProjectBO.value.projectIndex = projectId.value
            AddProjectBO.value.provinceIndex = provinceId.value
            AddProjectBO.value.gdIndex = gdId.value
            AddProjectBO.value.subIndex = subId.value
            addDevice()
            break
        case 500:
            AddProjectBO.value.projectIndex = projectId.value
            AddProjectBO.value.provinceIndex = provinceId.value
            AddProjectBO.value.gdIndex = gdId.value
            AddProjectBO.value.subIndex = subId.value
            AddProjectBO.value.devIndex = devId.value

            addSubVoltage()
            break
        case 600:
            AddProjectBO.value.projectIndex = projectId.value
            AddProjectBO.value.provinceIndex = provinceId.value
            AddProjectBO.value.gdIndex = gdId.value
            AddProjectBO.value.subIndex = subId.value
            AddProjectBO.value.devIndex = devId.value
            AddProjectBO.value.subvIndex = busBarId.value

            addLine()
            break
        case 700:
            AddProjectBO.value.projectIndex = projectId.value
            AddProjectBO.value.provinceIndex = provinceId.value
            AddProjectBO.value.gdIndex = gdId.value
            AddProjectBO.value.subIndex = subId.value
            AddProjectBO.value.devIndex = devId.value
            AddProjectBO.value.subvIndex = busBarId.value

            addLine()
            break
    }

    deviceBODetail.value.manufacturer = factoryArr[0].id
    deviceBODetail.value.devType = typeArr[0].value
    deviceBODetail.value.frontType = comTypeStatusArr[0].value
    deviceBODetail.value.nodeId = affiliatiedFrontArr[0].id
    busBarDetail.value.scale = voltageLevelArr[0].id
    subStationParam.value.scale = voltageLevelArr[0].id
    monitorPointDetail.value.businessType = industryTypeArr[0].value
    monitorPointDetail.value.loadType = loadTypeArr[0].id
}
  /**新增项目 */
  const  addProject=()=> {
            nodeLevel.value = 100
            AddProjectBO.value.projectParam = { name: '', sort: 0 }
        }
// 修改
const update = () => {
    console.log('修改')
}
// 删除
const remove = () => {
    console.log('删除')
}
// 下一步
const next = () => {
    switch (nodeLevel.value) {
        case 100:
            addProvince()
            nextfalg.value = false

            break
        case 200:
            addGdInformation()
            nextfalg.value = false
            break
        case 300:
            addSubStation()
            nextfalg.value = false
            break
        case 400:
            addDevice()
            nextfalg.value = false

            break
        case 500:
            addSubVoltage()
            nextfalg.value = false

            break
        case 600:
            addLine()
            nextfalg.value = false
            break
        case 700:
            addLine()
            nextfalg.value = true
            break
    }
}
// 撤销
const black = () => {
    console.log('撤销')
}
// 确认提交
const onsubmit = () => {
    console.log('撤销')
}

const addProvince = () => {
    nodeLevel.value = 200
    AddProjectBO.value.provinceParam = { name: '', sort: 0 }
}
const addGdInformation = () => {
    nodeLevel.value = 300
    AddProjectBO.value.gdInformationParam = { name: '', sort: 0 }
}
const addSubStation = () => {
    nodeLevel.value = 400
    AddProjectBO.value.subStationParam = {
        name: '',
        lng: '0',
        lat: '0',
        scale: '',
        sort: 0
    }
}
const addDevice = () => {
    nodeLevel.value = 500
    // 不存在，赋值
    if (!AddProjectBO.value.deviceParam) {
        AddProjectBO.value.deviceParam = []
    }

    const device = JSON.parse(JSON.stringify(deviceBODetail.value))
    device.gdName = currentGdName.value

    AddProjectBO.value.deviceParam.push(JSON.parse(JSON.stringify(device)))
    deviceIndex.value = AddProjectBO.value.deviceParam.length - 1 + ''
}
const addSubVoltage = () => {}
const addLine = () => {}
const getNodeIndex = () => {
    deviceIndex.value = '0'
    busBarIndex.value = '0'
    lineIndex.value = '0'
}
/**查询节点内容 */
const queryNodeContent = () => {
    let data = {
        id: nodeData.value.id,
        level: nodeLevel.value
    }
    queryTerminal(data).then(res => {
        // console.log("内容详情", res);
        if (nodeLevel.value === 500) {
            var data = res.data
            /**假数据 */
            var arr = []
            var arr1 = []
            //取设备
            for (var i = 0; i < data.deviceVO.length; i++) {}
        }
        /**对接口再放开 */
        AddProjectBO.value.projectIndex =
            res.data.projectVO && res.data.projectVO.projectIndex ? res.data.projectVO.projectIndex : 0
        AddProjectBO.value.provinceIndex =
            res.data.provinceVO && res.data.provinceVO.provinceIndex ? res.data.provinceVO.provinceIndex : 0
        AddProjectBO.value.gdIndex =
            res.data.gdInformationVO && res.data.gdInformationVO.gdIndex ? res.data.gdInformationVO.gdIndex : 0
        AddProjectBO.value.subIndex =
            res.data.subStationVO && res.data.subStationVO.subIndex ? res.data.subStationVO.subIndex : 0

        AddProjectBO.value.projectParam = {
            name: res.data.projectVO.name,
            sort: res.data.projectVO.sort
        }

        if (nodeLevel.value > 100) {
            // AddProjectBO.value.provinceIndex = res.data.provinceVO.name
            AddProjectBO.value.provinceParam = {
                name: res.data.provinceVO.name,
                sort: res.data.provinceVO.sort
            }
            AddProjectBO.value.provinceParam.name = res.data.provinceVO.name
        }

        if (nodeLevel.value > 200) {
            AddProjectBO.value.gdInformationParam = {
                name: res.data.gdInformationVO.name,
                sort: res.data.gdInformationVO.sort
            }
            currentGdName.value = res.data.gdInformationVO.name
        }

        if (nodeLevel.value > 300) {
            AddProjectBO.value.subStationParam = JSON.parse(JSON.stringify(res.data.subStationVO))
            let deviceBO = JSON.parse(JSON.stringify(res.data.deviceVO))
            deviceBO.forEach((item: any) => {
                item.subVoltageParam = item.subVoltageVOList ? item.subVoltageVOList : []
                delete item.subVoltageVOList
                item.subVoltageParam.forEach((litem: any) => {
                    litem.lineParam = litem.lineVO ? litem.lineVO : []
                    delete litem.lineVO
                })
            })
            AddProjectBO.value.deviceParam = JSON.parse(JSON.stringify(deviceBO))
            deviceBO = null
        }
    })
}
const initAddProjectBo = () => {
    AddProjectBO.value.deviceParam = null
}
/**AddProjectBo的Id恢复初始状态 */
const initAddProjectBoId = () => {
    /**项目Id */
    AddProjectBO.value.projectIndex = 0
    AddProjectBO.value.provinceIndex = 0
    AddProjectBO.value.gdIndex = 0
    AddProjectBO.value.subIndex = 0
}
const tabChange = (type: string) => {
    if (type == 'deviceIndex') {
        busBarIndex.value = '0'
        lineIndex.value = '0'
    } else if (type == 'busBarIndex') {
        lineIndex.value = '0'
    }
}
/**
 * 新增/删除设备
 */
const handleDeviceTabsEdit = (targetName: any, action: any) => {
    // console.log(targetName);
    /**新增 */
    if (action === 'add') {
        addDevice()
    }
    /**删除 */
    if (action === 'remove') {
        ElMessageBox.confirm('此操作将永久删除, 是否继续?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
        })
            .then(() => {
                if (AddProjectBO.value.deviceParam[deviceIndex.value].devIndex) {
                    let data = {
                        id: AddProjectBO.value.deviceParam[deviceIndex.value].devIndex,
                        level: 500
                    }
                    delTerminal(data).then((res: any) => {
                        ElMessage({
                            type: 'success',
                            message: res.message
                        })
                        reaseStatus()
                        initAddProjectBo()
                        initAddProjectBoId()
                    })
                } else {
                    AddProjectBO.value.deviceParam.splice(deviceIndex.value, 1)
                    deviceIndex.value = AddProjectBO.value.deviceParam.length
                        ? AddProjectBO.value.deviceParam.length - 1 + ''
                        : '0'
                    busBarIndex.value = '0'
                    lineIndex.value = '0'
                    ElMessage({
                        type: 'success',
                        message: '删除成功'
                    })
                }
            })
            .catch(() => {
                ElMessage({
                    type: 'info',
                    message: '已取消删除'
                })
            })
    }
}
/**
 * 重置初始状态
 */
const reaseStatus = () => {
    nodeData.value = {}
    nodeLevel.value = 0
    pageStatus.value = 1
    projectId.value = 0
    provinceId.value = 0
    gdId.value = 0
    subId.value = 0
    devId.value = 0
    busBarId.value = 0
    lineId.value = 0
    deviceIndex.value = '0'
    busBarIndex.value = '0'
    lineIndex.value = '0'
    currentGdName.value = ''
}
const area = () => {
    areaTree({ id: '', type: 0 }).then((res: any) => {
        treeOptions.value = res.data
    })
    nodeAllList().then(res => {
        // console.log("前置机", res);
        affiliatiedFrontArr.value = res.data
        deviceBODetail.value.nodeId = res.data[0].id
    })
}
area()
</script>

<style lang="scss">
.device-manage {
    display: flex;
    padding: 15px;
    &-right {
        overflow: hidden;
        flex: 1;
        padding: 10px 10px 10px 0;
        .el-descriptions__header {
            height: 36px;
            margin-bottom: 7px;
            display: flex;
            align-items: center;
        }
    }
}
.main-form {
    display: flex;
    flex-wrap: wrap;
    .form-top {
        width: 100%;
    }

    .el-form-item {
        width: 30%;
        margin-bottom: 15px;
        .el-select {
            width: 100%;
            min-width: 0px;
        }
    }
}
</style>
