<!--用电用户-->
<template>
  <div>
    <el-form :inline="true" :model="ruleForm" class="demo-form-inline">
      <el-form-item label="信息查询:">
        <el-input v-model.trim="ruleForm.searchValue" placeholder="请输入查询信息" clearable>
        </el-input>
      </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="pagUser">查询</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>
      <span>
        <el-button type="primary" size="mini" class="ml10" icon="el-icon-plus" @click="addFn">新增</el-button>
        <el-button type="primary" size="mini" class="ml10" icon="el-icon-edit" @click="modifyFn">修改</el-button>
        <el-button type="primary" size="mini" class="ml10" icon="el-icon-delete" @click="deleteFn">删除</el-button>
      </span>
      <vxe-table :data="UserData" :height="height" border :row-config="{ isCurrent: true, isHover: true }" size="mini"
        ref="UseRadioAccount" style="width: 100%" v-loading="isLoading" header-cell-class-name="table_header"
        @checkbox-all="handleSelectionChange" @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 tableHeaderUser" 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>

    <!-- <PMS_Data
      :PMSobtain="PMSobtain"
      :title="title"
      @Close="Close"
      :Data="UserData"
      :Name="tableHeaderUser"
    ></PMS_Data> -->

    <!-- 新增/修改 -->
    <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" label-width="170px" class="form" :rules="rules" ref="rulesform">
        <el-form-item label="用户编号:" prop="id" 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="powerStationId" class="mt10">
          <el-select v-model="form.powerStationId" 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="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="platformId" class="mt10">
          <el-select v-model="form.platformId" clearable @change="powerChange" placeholder="请选择供电台区">
            <el-option v-for="item in Routetable" :key="item.id" :label="item.orgName + '_' + item.name"
              :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="用户分类:" prop="userType" class="mt10">
          <el-select v-model="form.userType" clearable placeholder="请选择用户分类">
            <el-option v-for="item in userList" :key="item.id" :label="item.name" :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="行业分类:" prop="industryType" class="mt10">
          <el-select v-model="form.industryType" clearable placeholder="请选择行业分类">
            <el-option v-for="item in industryList" :key="item.id" :label="item.name" :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="用电类别:" prop="electricityType" class="mt10">
          <el-select v-model="form.electricityType" clearable placeholder="请选择用电类别">
            <el-option v-for="item in electricityList" :key="item.id" :label="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="contractCapacity" class="mt10">
          <el-input maxlength="10" v-model="form.contractCapacity" clearable placeholder="请输入合同容量"></el-input>
        </el-form-item>
        <el-form-item label="运行容量:" prop="operatingCapacity" class="mt10">
          <el-input maxlength="10" v-model="form.operatingCapacity" clearable placeholder="请输入运行容量"></el-input>
        </el-form-item>
        <el-form-item label="生产班次:" prop="productionShift" class="mt10">
          <el-select v-model="form.productionShift" clearable placeholder="请选择生产班次">
            <el-option v-for="item in productionList" :key="item.id" :label="item.name" :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="负荷性质:" prop="loadNature" class="mt10">
          <el-select v-model="form.loadNature" clearable placeholder="请选择负荷性质">
            <el-option v-for="item in loadNatureList" :key="item.id" :label="item.name" :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="高耗能行业类别:" prop="highIndustryType" class="mt10">
          <el-select v-model="form.highIndustryType" clearable placeholder="请选择高耗能行业类别">
            <el-option v-for="item in highIndustryList" :key="item.id" :label="item.name" :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="送电日期:" prop="powerTransmissionDate" class="mt10">
          <el-date-picker v-model="form.powerTransmissionDate" value-format="yyyy-MM-dd" type="date" placeholder="选择日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="重要性等级:" prop="importanceLevel" class="mt10">
          <el-select v-model="form.importanceLevel" clearable placeholder="请选择重要性等级">
            <el-option v-for="item in importanceList" :key="item.id" :label="item.name" :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="用电客户状态:" prop="eccStat" class="mt10">
          <el-select v-model="form.eccStat" clearable placeholder="请选择用电客户状态">
            <el-option v-for="item in eccStatList" :key="item.id" :label="item.name" :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="是否敏感用户:" prop="ifSensitiveUser" class="mt10">
          <el-select v-model="form.ifSensitiveUser" 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="ifPowerQuality" class="mt10">
          <el-select v-model="form.ifPowerQuality" clearable placeholder="请选择是否影响电能质量">
            <el-option v-for="item in whether2" :key="item.id" :label="item.label" :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="是否重要客户:" prop="ifKeyCustomers" class="mt10">
          <el-select v-model="form.ifKeyCustomers" clearable placeholder="请选择是否重要客户">
            <el-option v-for="item in whether3" :key="item.id" :label="item.label" :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="敏感用户类别:" prop="sensitiveType" class="mt10">
          <el-select v-model="form.sensitiveType" clearable placeholder="请选择敏感用户类别">
            <el-option v-for="item in sensitiveList" :key="item.id" :label="item.name" :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="用户标签:" prop="userTag" class="mt10">
          <el-input v-model="form.userTag" clearable placeholder="请输入用户标签"></el-input>
        </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 whether3" :key="item.id" :label="item.label" :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 {
  getPowerClientPageList,
  getstatationStatList,
  addPowerClient,
  updatePowerClient,
  getGeneratrixWireList,
  getPowerDistributionAreaList,
  delPowerClient,
} from "@/api/hbaccountoperation/UseRadioAccount";
import { deptTree } from "@/api/admin/dept";
import { dicData } from "@/assets/commjs/dictypeData";
export default {
  components: { PMS_Data, Organization, Operation },
  data() {
    return {
      vh: "",
      title: "",
      add: false,
      modify: false,

      // 查询数据
      ruleForm: {
        searchValue: "",
        pageNum: 1,
        pageSize: 20,
        // orderBy: "",
        // searchBeginTime: "",
        // searchEndTime: "",
        // searchState: 0,
        // sortBy: "",
        // status: 0
      },

      total: 0,
      form: {
        contractCapacity: null,
        eccStat: "",
        electricityType: "",
        highIndustryType: "",
        id: "",
        ifKeyCustomers: null,
        ifPowerQuality: null,
        ifSensitiveUser: null,
        importanceLevel: "",
        industryType: "",
        isUpToGrid: 0,
        lineId: "",
        loadNature: "",
        name: "",
        operatingCapacity: null,
        operationId: "",
        orgId: "",
        powerStationId: "",
        powerTransmissionDate: "",
        productionShift: "",
        sensitiveType: "",
        userTag: "",
        userType: "",
        voltageLevel: "",
        orgName: "",
        operationName: "",
        powerrName: "",
        lineName: "",
        platformName: "",
        platformId: "",
      },
      rules: {
        id: [{ required: true, message: "请输入用户编号", trigger: "blur" }],
        name: [{ required: true, message: "请输入用户名称", trigger: "blur" }],
        powerStationId: [
          { required: true, message: "请选择供电变电站", trigger: "change" },
        ],
        lineId: [
          { required: true, message: "请选择供电线路", trigger: "change" },
        ],
        platformId: [
          { required: true, message: "请选择供电台区", trigger: "change" },
        ],
        userType: [
          { required: true, message: "请选择用户分类", trigger: "change" },
        ],
        industryType: [
          { required: true, message: "请选择行业分类", trigger: "change" },
        ],
        electricityType: [
          { required: true, message: "请选择用电类别", trigger: "change" },
        ],
        voltageLevel: [
          { required: true, message: "请选择供电电压", trigger: "change" },
        ],
        /*contractCapacity: [
          { required: true, message: "请输入合同容量", trigger: "blur" },
          { pattern: /^[0-9]*$/, message: "只可以输入数字", trigger: "blur" },
        ],
        operatingCapacity: [
          { required: true, message: "请输入运行容量", trigger: "blur" },
          { pattern: /^[0-9]*$/, message: "只可以输入数字", trigger: "blur" },
        ],
        productionShift: [
          { required: true, message: "请选择生产班次", trigger: "change" },
        ],
        loadNature: [
          { required: true, message: "请选择负荷性质", trigger: "change" },
        ],

        highIndustryType: [
          {
            required: true,
            message: "请选择高耗能行业类别",
            trigger: "change",
          },
        ],
        powerTransmissionDate: [
          { required: true, message: "请选择日期", trigger: "change" },
        ],
        importanceLevel: [
          { required: true, message: "请选择重要性等级", trigger: "change" },
        ],
        eccStat: [
          { required: true, message: "请选择用电客户状态", trigger: "change" },
        ],
        ifSensitiveUser: [
          { required: true, message: "请选择是否敏感用户", trigger: "change" },
        ],
        ifPowerQuality: [
          {
            required: true,
            message: "请选择是否影响电能质量",
            trigger: "change",
          },
        ],
        ifKeyCustomers: [
          { required: true, message: "请选择是否重要客户", trigger: "change" },
        ],
      sensitiveType: [
          { required: true, message: "请选择敏感用户类别", trigger: "change" },
        ],*/

        isUpToGrid: [
          {
            required: true,
            message: "请选择是否是上送网公司监测点",
            trigger: "change",
          },
        ],
      },
      height: null,
      height1: null,
      isLoading: false,
      disabled: true,
      disabled1: true,
      multipleSelection: [],
      //台区台账表头
      tableHeaderUser: [
        { prop: "id", label: "用户编号", width: 180 },
        { prop: "name", label: "用户名称", width: 260 },
        { prop: "orgName", label: "组织机构名称", width: 150 },
        { prop: "operationName", label: "运维单位名称", width: 150 },
        { prop: "userType", label: "用户分类", width: 120 },
        { prop: "industryType", label: "行业分类", width: 180 },
        { prop: "electricityType", label: "用电类别", width: 100 },
        { prop: "contractCapacity", label: "合同容量", width: 120 },
        { prop: "operatingCapacity", label: "运行容量", width: 100 },
        { prop: "productionShift", label: "生产班次", width: 100 },
        { prop: "loadNature", label: "负荷性质", width: 100 },
        { prop: "voltageLevel", label: "供电电压", width: 120 },
        { prop: "highIndustryType", label: "高耗能行业类别", width: 150 },
        { prop: "powerTransmissionDate", label: "送电日期", width: 150 },
        { prop: "importanceLevel", label: "重要性等级", width: 170 },
        { prop: "eccStat", label: "用电客户状态", width: 150 },
        { prop: "ifSensitiveUser", label: "是否敏感用户", width: 150 },
        { prop: "ifPowerQuality", label: "是否影响电能质量", width: 170 },
        { prop: "ifKeyCustomers", label: "是否重要客户", width: 170 },
        { prop: "sensitiveType", label: "敏感用户类别", width: 170 },
        { prop: "userTag", label: "用户标签", width: 170 },
        { prop: "isUpToGrid", label: "是否是上送网公司", width: 190 },
        // { prop: "status", label: "数据状态", width:100 },
      ],
      whether1: [
        {
          id: 0,
          value: "选项1",
          label: "否",
        },
        {
          id: 1,
          value: "选项2",
          label: "是",
        },
      ],
      whether2: [
        {
          id: 0,
          value: "选项1",
          label: "否",
        },
        {
          id: 1,
          value: "选项2",
          label: "是",
        },
      ],
      whether3: [
        {
          id: 0,
          value: "选项1",
          label: "否",
        },
        {
          id: 1,
          value: "选项2",
          label: "是",
        },
      ],
      whether4: [
        {
          id: 0,
          value: "选项1",
          label: "否",
        },
        {
          id: 1,
          value: "选项2",
          label: "是",
        },
      ],
      editCheckCode: "",
      valueTitle: "",
      editCheckCode1: "",
      valueTitle1: "",
      UserData: [],
      device: "",
      organization: [], //组织机构名称
      operation: [], //运维单位名称
      userList: [], //用户分类
      industryList: [], //行业分类
      electricityList: [], //用电类别
      productionList: [], //生产班次
      loadNatureList: [], //负荷性质
      voltageLevelList: [], //供电电压
      highIndustryList: [], //高耗能行业类别
      importanceList: [], //重要性等级
      eccStatList: [], //用电客户状态
      sensitiveList: [], //敏感用户类别
      statationName: [], //供电变电站
      MonitoringLine: [], //供电线路
      Routetable: [], //供电台区
      PMSobtain: false,
      information: false, //修改台区信息
      addinformation: false, //新增台区信息
    };
  },
  created() {
    this.getclassificationData();
  },

  mounted() {
    this.device = window.devicePixelRatio;
    this.setHeight()
    window.addEventListener('resize', this.setHeight)

    this.User();
  },
  beforeDestroy() {
    window.removeEventListener('resize', this.setHeight)
  },
  methods: {
    setHeight() {
      this.height = window.sessionStorage.getItem("appheight") - 205;
      this.height1 = window.sessionStorage.getItem("appheight") - 285;

    },
    // 切换选项
    handleNodeClick(data) {
      this.form.powerStationId = "";
      this.form.lineId = "";
      this.form.platformId = "";
      this.MonitoringLine = [];
      this.Routetable = [];
      this.statationName = [];
      if (data.code != null) {
        let form = {
          deptId: data.id,
        };
        // 变电站名称
        getstatationStatList(form).then((res) => {
          this.statationName = res.data;
        });
      }
      this.form.orgId = data.code;
      this.form.orgName = data.name;
    },
    handleNodeClick1(data) {
      // console.log(data);
      this.form.operationId = data.code;
      this.form.operationName = data.name;
    },
    changeFn1(val) {
      this.form.lineId = "";
      this.form.platformId = "";
      this.MonitoringLine = [];
      this.Routetable = [];

      let form = {
        stationId: val,
      };
      // 线路名称
      getGeneratrixWireList(form).then((res) => {
        this.MonitoringLine = res.data;
      });
      this.statationName.forEach((item) => {
        // console.log(item);
        if (item.powerId == val) {
          this.form.powerrName = item.powerName;

          // this.form.powerrName= item.orgName+'_'+item.powerName
        }
      });
    },
    changeFn3(val) {
      this.form.platformId = "";
      this.Routetable = [];

      let form = {
        lineId: val,
      };
      //台区
      getPowerDistributionAreaList(form).then((res) => {
        this.Routetable = res.data;
      });
      this.MonitoringLine.forEach((item) => {
        if (item.id == val) {
          this.form.lineName = item.name;
        }
      });
      this.$forceUpdate();
    },

    powerChange() {
      this.$forceUpdate();
    },
    //获取类型
    getclassificationData() {
      //用户分类
      var code = "User_Class";
      this.userList = dicData(code, []);
      //行业分类
      var code1 = "Business_Type";
      this.industryList = dicData(code1, []);
      //用电类别
      var code2 = "Ele_Class";
      this.electricityList = dicData(code2, []);
      //生产班次
      var code3 = "Production_Shifts";
      this.productionList = dicData(code3, []);
      //负荷性质
      var code4 = "Load_Type";
      this.loadNatureList = dicData(code4, []);
      //供电电压
      var code5 = "Dev_Voltage";
      this.voltageLevelList = dicData(code5, []);
      //高耗能行业类别
      var code6 = "High_Cate";
      this.highIndustryList = dicData(code6, []);
      //重要性等级
      var code7 = "Importance_Level";
      this.importanceList = dicData(code7, []);
      //用电客户状态
      var code8 = "Ecc_Stat";
      this.eccStatList = dicData(code8, []);
      //敏感用户类别
      var code9 = "Sensitive_User_Type";
      this.sensitiveList = dicData(code9, []);
    },

    // //PMS获取数据
    // PMSobtainFn() {
    //   this.PMSobtain = true;
    //   this.title = "线路表";
    // },
    pagUser() {
      this.ruleForm.pageNum = 1;
      this.ruleForm.pageSize = 20;
      this.User()
    },
    //查询用户用电信息
    User() {
      this.isLoading = true;
      getPowerClientPageList(this.ruleForm).then((res) => {
        this.isLoading = false;
        this.UserData = res.data.records;
        this.total = res.data.total;
      });
    },
    // 数据过滤
    formFilter(row, column) {
      if (row.column.property == "userType") {
        let title = "";
        this.userList.forEach((item) => {
          if (item.value == row.row.userType) {
            title = item.label;
          }
        });
        return title;
      } else if (row.column.property == "industryType") {
        let title = "";
        this.industryList.forEach((item) => {
          if (item.value == row.row.industryType) {
            title = item.label;
          }
        });
        return title;
      } else if (row.column.property == "electricityType") {
        let title = "";
        this.electricityList.forEach((item) => {
          if (item.value == row.row.electricityType) {
            title = item.label;
          }
        });
        return title;
      } else if (row.column.property == "productionShift") {
        let title = "";
        this.productionList.forEach((item) => {
          if (item.value == row.row.productionShift) {
            title = item.label;
          }
        });
        return title;
      } else if (row.column.property == "loadNature") {
        let title = "";
        this.loadNatureList.forEach((item) => {
          if (item.value == row.row.loadNature) {
            title = item.label;
          }
        });
        return title;
      } else 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 == "highIndustryType") {
        let title = "";
        this.highIndustryList.forEach((item) => {
          if (item.value == row.row.highIndustryType) {
            title = item.label;
          }
        });
        return title;
      } else if (row.column.property == "importanceLevel") {
        let title = "";
        this.importanceList.forEach((item) => {
          if (item.value == row.row.importanceLevel) {
            title = item.label;
          }
        });
        return title;
      } else if (row.column.property == "eccStat") {
        let title = "";
        this.eccStatList.forEach((item) => {
          if (item.value == row.row.eccStat) {
            title = item.label;
          }
        });
        return title;
      } else if (row.column.property == "sensitiveType") {
        let title = "";
        this.sensitiveList.forEach((item) => {
          if (item.value == row.row.sensitiveType) {
            title = item.label;
          }
        });
        return title;
      } else {
        return row.row[row.column.property];
      }
    },

    //数据上传
    upload() {
      if (this.multipleSelection.length == 0) {
        this.$message({
          showClose: true,
          message: "请选择台账!!!",
          type: "warning",
        });
        return;
      }
      this.$message({
        showClose: true,
        message: "上传成功！！！",
        type: "success",
      });
    },
    // 重置
    Reset() {
      // 查询数据
      this.ruleForm.searchValue = "";
    },
    //新增
    addFn() {
      this.form = {
        contractCapacity: null,
        eccStat: "",
        electricityType: "",
        highIndustryType: "",
        id: "",
        ifKeyCustomers: null,
        ifPowerQuality: null,
        ifSensitiveUser: null,
        importanceLevel: "",
        industryType: "",
        isUpToGrid: 0,
        lineId: "",
        loadNature: "",
        name: "",
        operatingCapacity: null,
        operationId: "",
        orgId: "",
        powerStationId: "",
        powerTransmissionDate: "",
        productionShift: "",
        sensitiveType: "",
        userTag: "",
        userType: "",
        voltageLevel: "",
        orgName: "",
        operationName: "",
        powerrName: "",
        lineName: "",
        platformName: "",
        platformId: "",
      };
      this.disabled = false;
      this.modify = false;
      this.add = true;
      this.title = "新增用电用户信息";
      this.addinformation = true;
    },
    //新增台区确定
    addinformationFn() {
      this.$refs.rulesform.validate((value) => {
        // console.log(value);
        if (value == true) {
          this.$confirm("是否确认新增?", "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning",
          })
            .then(() => {
              addPowerClient(this.form).then((res) => {
                if (res.code == "A0000") {
                  this.$message({
                    message: res.message,
                    type: "success",
                  });
                }
                this.addinformation = false;
                this.User();
              });
            })
            .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.disabled = true;
      this.modify = true;
      this.add = false;
      this.title = "修改用电用户信息";
      if (this.multipleSelection.length != 1) {
        this.$message({
          showClose: true,
          message: "请选择台账!!!",
          type: "warning",
        });
        return;
      }
      this.addinformation = true;
      // console.log(this.multipleSelection[0],'===============');
      this.form = JSON.parse(JSON.stringify(this.multipleSelection[0]));

      console.log("====", this.form)

      // this.form.powerrId=this.form.orgName+'_'+this.form.powerrName
      this.valueTitle = this.multipleSelection[0].orgName;
      this.editCheckCode = this.multipleSelection[0].orgId;
      this.valueTitle1 = this.multipleSelection[0].operationName;
      this.editCheckCode1 = this.multipleSelection[0].operationId;
      /*    if (this.form.ifSensitiveUser == "是") {
            this.form.ifSensitiveUser = 1;
          } else if (this.form.ifSensitiveUser == "否") {
            this.form.ifSensitiveUser = 0;
          }
          if (this.form.ifPowerQuality == "是") {
            this.form.ifPowerQuality = 1;
          } else if (this.form.ifPowerQuality == "否") {
            this.form.ifPowerQuality = 0;
          }
          if (this.form.ifKeyCustomers == "是") {
            this.form.ifKeyCustomers = 1;
          } else if (this.form.ifKeyCustomers == "否") {
            this.form.ifKeyCustomers = 0;
          }
          if (this.form.isUpToGrid == "是") {
            this.form.isUpToGrid = 1;
          } else if (this.form.isUpToGrid == "否") {
            this.form.isUpToGrid = 0;
          }*/

      //变电站下拉框
      let form = {
        deptCode: this.multipleSelection[0].orgId,
      };
      getstatationStatList(form).then((res) => {
        this.statationName = res.data;
      });
      //台区
      let formP = {
        lineId: this.multipleSelection[0].lineId,
      };
      getPowerDistributionAreaList(formP).then((res) => {
        this.Routetable = res.data;
      });

      // 线路名称
      let formL = {
        stationId: this.multipleSelection[0].powerStationId,
      };
      getGeneratrixWireList(formL).then((res) => {
        this.MonitoringLine = res.data;
      });
    },
    //修改台区信息确定
    modifyinformationFn() {
      this.$refs.rulesform.validate((value) => {
        // console.log(value);
        if (value == true) {
          this.$confirm("是否确认修改?", "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning",
          })
            .then(() => {
              updatePowerClient(this.form).then((res) => {
                if (res.code == "A0000") {
                  this.$message({
                    message: res.message,
                    type: "success",
                  });
                }
                this.addinformation = false;
                this.User();
              });
            })
            .catch(() => {
              this.$message({
                type: "info",
                message: "已取消修改",
              });
            });
        }
      });
    },
    // 删除
    deleteFn() {
      if (this.multipleSelection.length == 0) {
        this.$message({
          showClose: true,
          message: "请选择台账!!!",
          type: "warning",
        });
        return;
      }
      this.$confirm("是否确认删除?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          let id = [];
          this.multipleSelection.forEach((item) => {
            id.push(item.id);
          });

          delPowerClient(id).then((res) => {
            if ((res.code == "A0000")) {
              this.$message({
                type: "success",
                message: res.message,
              });
            }
            this.User();
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },

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

    // 表格多选
    handleSelectionChange(row) {
      this.multipleSelection = row.records;
      // console.log(this.multipleSelection);
    },

    //每页条数改变时触发 选择一页显示多少行
    handleSizeChange(val) {
      this.ruleForm.pageSize = val;
      this.User();
    },
    //当前页改变时触发 跳转其他页
    handleCurrentChange(val) {
      this.ruleForm.pageNum = val;
      this.User();
    },
    cellStyle(row) {
      /*  if (
          row.row.ifSensitiveUser == 0 ||
          row.row.ifPowerQuality == 0 ||
          row.row.ifKeyCustomers == 0 ||
          row.row.isUpToGrid == 0
        ) {
          row.row.ifSensitiveUser = "否";
          row.row.ifPowerQuality = "否";
          row.row.ifKeyCustomers = "否";
          row.row.isUpToGrid = "否";
        } else if (
          row.row.ifSensitiveUser == 1 ||
          row.row.ifPowerQuality == 1 ||
          row.row.ifKeyCustomers == 1 ||
          row.row.isUpToGrid == 0
        ) {
          row.row.ifSensitiveUser = "是";
          row.row.ifPowerQuality = "是";
          row.row.ifKeyCustomers = "是";
          row.row.isUpToGrid = "是";
        }*/
    },
    //导出
    exportEvent() {
      getPowerClientPageList({
        searchValue: this.ruleForm.searchValue,
        pageNum: 1,
        pageSize: this.total,
      }).then((res) => {
        this.$refs.UseRadioAccount.exportData({
          filename: "用电用户台帐", // 文件名字
          sheetName: "Sheet1",
          type: "xlsx", //导出文件类型 xlsx 和 csv
          useStyle: true,
          data: res.data.records, // 数据源 // 过滤那个字段导出
          columnFilterMethod: function (column, $columnIndex) {
            return !(column.$columnIndex === 0);
          },
        });
      });
    },
  },
};
</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: 10px;
}

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

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

    .el-form-item__content {
      flex: 1 !important;

      .el-select {
        width: 100%;
      }

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

::v-deep .el-dialog__body::-webkit-scrollbar-thumb {
  background-color: #006565;
  border: 2px solid #006565;
  border-radius: 10%;
}

.pms {
  margin-left: 10px;
}

.obtain {
  margin-left: 1220px;
}
</style>
