<template>
  <div>
    <el-form :inline="true" class="demo-form-inline form">
      <el-form-item>
        <Area @click="handleNodeClick" ref="area"></Area>
      </el-form-item>

      <el-form-item label="干扰源类型:" class="box1">
        <el-select v-model="formData.loadType" clearable collapse-tags placeholder="请选择">
          <el-option
              v-for="item in interferenceType"
              :key="item.id"
              :label="item.name"
              :value="item.id"
          ></el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="干扰源用户名称:">
        <el-input v-model="formData.userName" clearable placeholder="请输入关键字"></el-input>
      </el-form-item>

      <el-form-item label="是否上传报告:" class="box">
        <el-select v-model="upload" clearable placeholder="请选择">
          <el-option
              v-for="item in uploadData"
              :key="item.id"
              :label="item.label"
              :value="item.id"
          ></el-option>
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" class="ml10" icon="el-icon-search" @click="initQuery">查询</el-button>
        <el-button type="primary" icon="el-icon-refresh" @click="Reset">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row>
      <el-col :span="24">
        <div class="mb10 fl">
          <el-button type="primary" icon="el-icon-folder-add" @click="add">新增</el-button>
          <el-button type="primary" icon="el-icon-upload" @click="sc">填报评估信息</el-button>
          <el-button type="primary" icon="el-icon-folder-add" @click="submitAuditUser">提交审核</el-button>
        </div>
        <div class="mb10 fr">


          <el-button type="primary" icon="el-icon-attract" @click="relationFn">关联</el-button>
          <el-button type="primary" icon="el-icon-share" @click="dc">导出</el-button>
        </div>
        <el-table
            stripe
            :data="undocumentednonlinearData"
            :height="height"
            border
            style="width: 100%"
            v-loading="isLoading"
            header-cell-class-name="table_header"
            @selection-change="handleSelectionChange"
            :cell-style="cellStyle"
            ref="multipleTable"
        >
          <el-table-column type="selection" width="65"></el-table-column>
          <el-table-column prop="orgName" label="所属单位" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column prop="loadType" label="干扰源类型" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column
              prop="userName"
              label="干扰源用户名称"
              :show-overflow-tooltip="true"
          ></el-table-column>
          <el-table-column prop="recordTime" label="建档时间" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column prop="iisFileUpload" label="是否上传报告" :show-overflow-tooltip="true">
            <template slot-scope="scope">
              <span v-if="scope.row.iisFileUpload == 0" type="primary" size="small">否</span>
              <span v-if="scope.row.iisFileUpload == 1" type="primary" size="small">是</span>
            </template>
          </el-table-column>


          <el-table-column prop="createByName" label="创建人" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column prop="icheckPersonName" label="审核人" :show-overflow-tooltip="true"></el-table-column>


          <el-table-column prop="istatus" label="状态" :show-overflow-tooltip="true">
            <template slot-scope="scope">
                            <span
                                v-if="scope.row.istatus == 0"
                                type="primary"
                                size="small"
                                style="color: #da70d6"
                            >
                                新建
                            </span>
              <span
                  v-else-if="scope.row.istatus == 1"
                  type="primary"
                  size="small"
                  style="color: #48d1cc"
              >
                                待审核
                            </span>
              <span
                  v-else-if="scope.row.istatus == 3"
                  type="primary"
                  size="small"
                  style="color: #dc143c; text-decoration: underline"
                  @click="failed = true"
              >
                                未通过
                            </span>
              <span
                  v-else-if="scope.row.istatus == 2"
                  type="primary"
                  size="small"
                  style="color: #9acd32"
              >
                                通过
                            </span>
              <span v-else type="primary" size="small">{{ scope.row.istatus }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="plandetails" label="详情">
            <template slot-scope="scope">
              <!-- <span  type="primary" size="small" style="color:blue;text-decoration:underline" @click="userDetails=true">查看</span> -->
              <el-button
                  v-if="scope.row.istatus != null"
                  @click="ck(scope.row)"
                  size="mini"
                  type="primary"
              >
                查看
              </el-button>

              <!--                          <el-button
                                            v-if="scope.row.istatus != null"
                                            @click="ck(scope.row)"
                                            size="mini"
                                            type="primary"
                                        >
                                          编辑
                                        </el-button>-->

              <el-button
                  v-if="scope.row.istatus != null"
                  @click="deleteData(scope.row)"
                  size="mini"
                  type="primary"
              >
                删除
              </el-button>
            </template>
          </el-table-column>
        </el-table>
        <el-pagination
            align="right"
            class="mt10"
            background
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="pageNum"
            :page-sizes="[20, 30, 40, 50, 100]"
            :page-size="pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total"
        ></el-pagination>
      </el-col>
    </el-row>

    <!-- 选择审核人 -->
    <el-dialog :close-on-click-modal="false" title="选择审核人" :visible.sync="chooseAudit" width="25%">
      <el-form label-width="80px">
        <el-row :gutter="20">
          <el-form-item label="审核人">
            <el-select v-model="auditUser" placeholder="请选择" style="width: 90%;" clearable>
              <el-option
                  v-for="item in auditUserList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-row>

        <el-row :gutter="20">
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" @click="auditSubmit">确认</el-button>
          </el-form-item>
        </el-row>
      </el-form>

    </el-dialog>

    <!-- 未通过弹窗 -->
    <el-dialog :close-on-click-modal="false" title="未通过审批意见查看" :visible.sync="failed" width="50%">
      <el-divider content-position="left" style="font-weight: bolder; font-size: 18px">审核意见</el-divider>
      <el-input type="textarea" :rows="7" placeholder="请输入内容" v-model="textarea"></el-input>
    </el-dialog>

    <!-- 新增 -->
    <el-dialog :close-on-click-modal="false" title="未建档干扰用户新增" :visible.sync="userAdd" width="1400px">
      <el-divider content-position="left" style="font-weight: bolder; font-size: 18px">基本信息</el-divider>
      <el-form :inline="true" label-width="120px">
        <el-form-item>
          <Area @click="handleNodeClick" ref="area"></Area>
        </el-form-item>
        <el-form-item label="干扰源类型:">
          <el-select v-model="addData.loadType" clearable collapse-tags placeholder="请选择">
            <el-option
                v-for="item in interferenceType"
                :key="item.id"
                :label="item.name"
                :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="干扰源用户名称:">
          <el-input v-model="addData.userName" clearable placeholder="请输入关键字"></el-input>
        </el-form-item>

        <el-form-item label="建档时间:">
          <!-- <el-date-picker
              v-model.trim="addData.recordTime"
              value-format="yyyy-MM-dd"
              type="date"
              placeholder="选择日期"
          >
          </el-date-picker> -->
          <el-date-picker
              value-format="yyyy-MM-dd HH:mm:ss"
              v-model="addData.recordTime"
              type="datetime"
              placeholder="选择日期时间"
          ></el-date-picker>
        </el-form-item>
      </el-form>
      <div style="display: flex; justify-content: center; margin-top: 30px">
        <el-button type="primary" class="ml20" @click="config">确定</el-button>
        <el-button type="primary" class="ml20" @click="userAdd = false">取消</el-button>
      </div>
    </el-dialog>

    <!-- 上传 -->
    <el-dialog
        :close-on-click-modal="false"
        title="未建档干扰源用户入网报告结论填报"
        :visible.sync="uploadConclusions"
        width="1400px"
    >
      <el-divider content-position="left" style="font-weight: bolder; font-size: 18px">基本信息</el-divider>
      <el-form :inline="true">
        <el-form-item label="所属单位:">
          <el-input v-model="addData.orgNo" clearable placeholder="请输入" disabled></el-input>
        </el-form-item>
        <el-form-item label="干扰源类型:">
          <el-select v-model="addData.loadType" clearable collapse-tags placeholder="请选择" disabled>
            <el-option
                v-for="item in interferenceType"
                :key="item.id"
                :label="item.name"
                :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="干扰源用户名称:">
          <el-input v-model="addData.userName" clearable placeholder="请输入关键字" disabled></el-input>
        </el-form-item>
        <el-form-item label="建档时间:">
          <!-- <el-date-picker
              v-model.trim="addData.recordTime"
              value-format="yyyy-MM-dd"
              type="date"
              placeholder="选择日期"
          >
          </el-date-picker> -->
          <el-date-picker
              value-format="yyyy-MM-dd HH:mm:ss"
              v-model="addData.recordTime"
              disabled
              type="datetime"
              placeholder="选择日期时间"
          ></el-date-picker>
        </el-form-item>

        <el-divider content-position="left" style="font-weight: bolder; font-size: 18px">
          入网评估报告上传
        </el-divider>
        <el-form-item class="item" label="文件名称:">
          <el-input v-model="documentName" clearable placeholder="请输入填报名称" disabled></el-input>
        </el-form-item>
        <el-form-item>
          <!-- <upload/> -->
          <el-upload
              ref="upload"
              class="upload-files"
              action=""
              :headers="headers"
              name="file"
              accept=".doc,.docx,.xls,.xlsx,.pdf,.txt"
              multiple
              :auto-upload="false"
              :file-list="fileList"
              :on-change="handleChange"
              :limit="1"
              :on-exceed="handleExceed"
          >
            <el-button slot="trigger" size="mini" icon="el-icon-upload" type="primary">上传本地评估报告</el-button>
          </el-upload>
        </el-form-item>
        <el-divider content-position="left" style="font-weight: bolder; font-size: 18px">
          入网评估结论填报
        </el-divider>

        <el-row>


          <el-form-item label="是否超标:" style="margin-top: 20px">
            <el-radio v-model="radio" label="0">是</el-radio>
            <el-radio v-model="radio" label="1">否</el-radio>
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="超标指标:" style="margin-top: 20px">
            <el-checkbox-group v-model="checkedCities" @change="handleCheckedCitiesChange" :disabled="eventDis">
              <el-checkbox v-for="(city, ind) in cities" :label="city.id" :key="ind">
                {{ city.name }}
              </el-checkbox>
            </el-checkbox-group>
          </el-form-item>
        </el-row>
        <el-form-item label="计划采取措施:" style="margin-top: 20px">
          <el-select v-model="measures" placeholder="请选择" :disabled="eventDis">
            <el-option
                v-for="item in takeMeasures"
                :key="item.value"
                :label="item.label"
                :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <br/>
        <el-form-item label="入网详情:" style="margin-top: 20px">
          <el-input
              v-model="rwxq"
              placeholder="请输入入网详情"
              type="textarea"
              style="width: 500px"
          ></el-input>
        </el-form-item>
      </el-form>
      <div style="display: flex; justify-content: center; margin-top: 30px">
<!--        <el-button type="primary" class="ml20" @click="tj">提交</el-button>-->
        <el-button type="primary" class="ml20" @click="bc">保存</el-button>
<!--        <el-button type="primary" class="ml20" @click="uploadConclusions = false">取消</el-button>-->
      </div>
    </el-dialog>

    <!-- 查看详情 -->
    <el-dialog
        :close-on-click-modal="false"
        title="未建档干扰源用户详情"
        :visible.sync="userDetails"
        width="1500px"
    >
      <el-form :inline="true" style="padding: 10px">
        <el-divider content-position="left" style="font-weight: bolder; font-size: 18px">基本信息</el-divider>
        <el-form-item label="所属单位:">
          <el-input v-model="addData.orgNo" clearable placeholder="请输入" disabled></el-input>
        </el-form-item>
        <el-form-item label="干扰源类型:">
          <el-select v-model="addData.loadType" clearable collapse-tags placeholder="请选择" disabled>
            <el-option
                v-for="item in interferenceType"
                :key="item.id"
                :label="item.name"
                :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="干扰源用户名称:">
          <el-input v-model="addData.userName" clearable placeholder="请输入关键字" disabled></el-input>
        </el-form-item>

        <el-form-item label="建档时间">
          <!-- <el-date-picker
              v-model.trim="addData.recordTime"
              value-format="yyyy-MM-dd"
              type="date"
              placeholder="选择日期"
          >
          </el-date-picker> -->
          <el-date-picker
              value-format="yyyy-MM-dd HH:mm:ss"
              v-model="addData.recordTime"
              disabled
              type="datetime"
              placeholder="选择日期时间"
          ></el-date-picker>
        </el-form-item>

        <el-divider content-position="left" style="font-weight: bolder; font-size: 18px">
          入网评估报告上传
        </el-divider>
        <el-form-item class="item" label="文件名称:">
          <el-input v-model="documentName1" clearable placeholder="请输入填报名称" disabled></el-input>
        </el-form-item>

        <el-form-item>
          <el-button size="small" type="primary" icon="el-icon-download" @click="xz">下载</el-button>
        </el-form-item>
        <el-divider content-position="left" style="font-weight: bolder; font-size: 18px">
          入网评估结论填报
        </el-divider>

        <el-row>
          <el-form-item label="是否超标:" style="margin-top: 20px">
            <el-radio v-model="radio" label="0" disabled>是</el-radio>
            <el-radio v-model="radio" label="1" disabled>否</el-radio>
          </el-form-item>
        </el-row>

        <el-row>
          <el-form-item label="超标指标:" style="margin-top: 20px">
            <el-checkbox-group v-model="checkedCities" @change="handleCheckedCitiesChange" disabled>
              <el-checkbox :disabled="eventDis" v-for="(city, ind) in cities" :label="city.id" :key="ind">
                {{ city.name }}
              </el-checkbox>
            </el-checkbox-group>
          </el-form-item>
        </el-row>

        <el-form-item label="计划采取措施:" style="margin-top: 20px">
          <el-select v-model="measures" placeholder="请选择" disabled>
            <el-option
                v-for="item in takeMeasures"
                :key="item.id"
                :label="item.name"
                :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <br/>
        <el-form-item label="入网详情:" style="margin-top: 20px">
          <el-input
              v-model="rwxq"
              placeholder="请输入入网详情"
              type="textarea"
              style="width: 500px"
              disabled
          ></el-input>
        </el-form-item>
      </el-form>
<!--      <div style="display: flex; justify-content: center; margin-top: 30px">
        <el-button type="primary" class="ml20" @click="userDetails = false">关闭</el-button>
      </div>-->
    </el-dialog>

    <!-- 关联 -->
    <el-dialog :close-on-click-modal="false" title="关联营销用户" :visible.sync="marketingUsers" width="70%">
      <el-form :inline="true">
        <el-form-item label="用户编号:">
          <el-input v-model="userNumber" clearable placeholder="请输入关键字"></el-input>
        </el-form-item>
        <el-form-item label="用户类型:">
          <el-select v-model="op" placeholder="请选择">
            <el-option
                v-for="item in op1"
                :key="item.value"
                :label="item.value"
                :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" class="ml10" icon="el-icon-search" @click="opselect">查询</el-button>
          <el-button type="primary" icon="el-icon-refresh" @click="ResetFn">重置</el-button>
        </el-form-item>
      </el-form>

      <el-table
          stripe
          :data="undocumentednonlinearData1"
          :height="height - 250"
          border
          class="mt10"
          style="width: 100%"
          v-loading="isLoading"
          header-cell-class-name="table_header"
          @selection-change="handleSelectionChange1"
          ref="multipleTable1"
      >
        <el-table-column type="selection" width="55"></el-table-column>
        <el-table-column prop="id" label="用户编号" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="name" label="用户名称" :show-overflow-tooltip="true"></el-table-column>
      </el-table>

      <div style="display: flex; justify-content: center; margin-top: 30px">
        <el-button type="primary" class="ml20" @click="gl">关联</el-button>
        <el-button type="primary" class="ml20" @click="marketingUsers = false">取消</el-button>
      </div>
    </el-dialog>

    <!-- 关联用户确认弹窗 -->
    <!-- <el-dialog :close-on-click-modal="false"
  title="关联确认"
  :visible.sync="confirm"
  width="30%"

>
  <span :style="`color:${WordColor}`"
    >关联营销用户后,该干扰源用户户将纳入常态化管理列表,是否确认关联</span
  >
  <div style="display: flex; justify-content: center; margin-top: 30px">
    <el-button type="primary" class="ml20" @click="gl">关联</el-button>
    <el-button type="primary" class="ml20" @click="confirm = false"
      >取消</el-button
    >
  </div>
</el-dialog> -->
  </div>
</template>

<script>
import Area from '@/views/components/Area/Area.vue'
import {dicData} from '@/assets/commjs/dictypeData'
import {
  addLoadTypeUser,
  getLoadTypeUserList,
  getPowerClientList,
  getPowerGenerationUserList,
  linkUser,
  uploadLoadTypeUserI,
  getLoadTypeUserById,
  exportLoadTypeUserList,
  delLoadTypeUserPlan,
  submitAuditUser
} from '@/api/Process-supervision/interferencemanagement/interferencemanagement'
import {getAuditUser} from '@/api/Process-supervision/tiaoHarmonicmanagement/harmonicmanagement'


export default {
  components: {Area},
  watch: {
    // 此处监听variable变量，当期有变化时执行
    radio(item1, item2) {
      // item1为新值，item2为旧值
      if (item1 === '1') {
        console.log("未超标")
        //未超标
        this.checkedCities = []
        this.measures = ''
        this.eventDis = true

      } else if (item1 === '0') {
        console.log("超标")
        this.eventDis = false
      }
    },
  },
  data() {
    return {
      checkedCities: [],
      cities: [],
      rwxq: '',
      headers: {
        Authorization: window.sessionStorage.getItem('cntoken')
      },
      undocumentednonlinearData1: [],
      op: '发电用户',
      op1: [
        {
          value: '发电用户'
        },
        {
          value: '用电用户'
        }
      ],
      WordColor: JSON.parse(window.localStorage.echartsColor).WordColor,
      url: '',
      total: 0,
      pageSize: 20,
      pageNum: 1,
      vh: '',
      height: null,
      isLoading: false,
      failed: false,
      chooseAudit:false,
      auditUser:'',
      userAdd: false,
      uploadConclusions: false,
      userDetails: false,
      marketingUsers: false,
      confirm: false,
      checkList: ['0'],
      radio: '0',
      textarea: '评估入网报告缺少XX指标,请整改后提交。',
      upload: '',
      formData: {
        loadType: '',
        userName: ''
      },
      orgNo: JSON.parse(window.sessionStorage.getItem('Info')).deptId,

      addData: {
        orgNo: JSON.parse(window.sessionStorage.getItem('Info')).deptId,
        loadType: '',
        userName: '',
        recordTime: ''
      },
      measures: '',
      documentName: '',
      documentName1: '',
      userNumber: '',
      //是否上传
      uploadData: [
        {
          id: 1,

          label: '是'
        },
        {
          id: 0,

          label: '否'
        }
      ],
      //干扰源类型
      interferenceType: [],
      //计划采取措施
      takeMeasures: [],
      undocumentednonlinearData: [],
      multipleSelection: [],
      loadTypeId:[],
      multipleSelection1: [],
      fileList: [],
      fileList1: [],
      device: '',
      rwzt: [],
      auditUserList:[],//审核人下拉
      eventDis: false
    }
  },
  created() {
    this.rwzt = dicData('On-network_Status', [], 1)
    this.cities = dicData('Steady_Statis', [])

    this.takeMeasures = dicData('Plan_Take', [], 1)
    this.takeMeasures.shift()
    // console.log(
    //   this.rwzt,
    //   "   console.log(this.rwzt)   console.log(this.rwzt)"
    // );
    this.cities.shift()
    this.interferenceType = dicData('Interference_Source', [], 0)
  },
  mounted() {
    this.initQuery()
    this.device = window.devicePixelRatio
    this.setHeight()
    window.addEventListener('resize', this.setHeight)

    //获取审核人列表
    this.getAuditUser()
  },
  beforeDestroy() {
    window.removeEventListener('resize', this.setHeight)
  },
  methods: {
    setHeight() {
      this.height = window.sessionStorage.getItem('appheight') - 215
    },
    dc() {
      if (this.multipleSelection.length == 0) {
        this.$message({
          message: '请选择一条数据',
          type: 'warning'
        })
      } else {
        let a = []
        this.multipleSelection.forEach(res => {
          a.push(res.id)
        })
        exportLoadTypeUserList(a).then(res => {
          let blob = new Blob([res], {
            type: 'application/vnd.ms-excel'
          })
          const url = window.URL.createObjectURL(blob)
          const link = document.createElement('a') // 创建a标签
          link.href = url // link.download = "电压暂降事件分析报告"; // 设置下载的文件名
          link.download = '未建档干扰源用户管理信息.xls' // 设置下载的文件名
          document.body.appendChild(link)
          link.click() //执行下载
          document.body.removeChild(link)
        })
      }
    },
    bc() {
      //先校验
      if(this.fileList.length == 0){
        this.$message.warning(`请上传预测评估报告`);
        return false;
      }

      if(this.radio == ''){
        this.$message.warning(`请选择是否超标`);
        return false;
      }

      if(this.radio == '0'){
        if(this.checkedCities.length < 1){
          this.$message.warning(`请选择超标指标`);
          return false;
        }

        if(this.measures == '' || this.measures == null){
          this.$message.warning(`计划采取措施不可为空`);
          return false;
        }

      }

      const formData = new FormData()
      this.fileList.forEach(item => {
        if (item.raw == '') {
        } else {
          formData.append('file', item.raw)
        }
      })
      formData.append('status', '2')
      formData.append('id', this.multipleSelection[0].id)
      formData.append('IDescription', this.rwxq)
      formData.append('iIsOverLimit', this.radio)
      formData.append('IPlanStep', this.measures)
      formData.append('IOverLimitTarget', this.checkedCities.toString())
      uploadLoadTypeUserI(formData) //后端上传接口
          .then(res => {
            if (res.code == 'A0000') {
              this.$message({
                message: '保存成功!',
                type: 'success'
              })
              this.uploadConclusions = false
              this.initQuery()
            }
          })
          .catch(err => {
            // console.log(err);
          })
    },
    xz() {
      window.open(this.url)
    },

    handleExceed(files, fileList) {
      this.$message.warning(
          `当前限制选择 1个文件，本次选择了 ${files.length} 个文件，共选择了 ${
              files.length + fileList.length
          } 个文件`
      )
    },
    ck(val) {
      getLoadTypeUserById({
        id: val.id
      }).then(res => {
        this.url = res.data.ifile == null ? '' : res.data.ifile
        this.addData.orgNo = val.orgName == null ? '' : val.orgName
        this.addData.loadType = res.data.loadType == null ? '' : res.data.loadType
        this.addData.userName = res.data.userName == null ? '' : res.data.userName
        this.addData.recordTime = res.data.recordTime == null ? '' : res.data.recordTime
        this.documentName1 = res.data.ifilePath == null ? '' : res.data.ifilePath
        this.radio = res.data.iisOverLimit == null ? '' : res.data.iisOverLimit.toString()
        this.checkedCities = res.data.ioverLimitTarget == null ? '' : res.data.ioverLimitTarget.split(',')
        this.measures = res.data.iplanStep == null ? '' : res.data.iplanStep
        this.rwxq = res.data.idescription == null ? '' : res.data.idescription
        this.userDetails = true
      })
    },

    //删除
    deleteData(row) {
      let data = [row.id]
      this.$confirm("是否确认删除?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        delLoadTypeUserPlan(data).then(res => {
          if (res.code == 'A0000') {
            this.$message.success("删除成功");
            this.initQuery()
          }

        })
      });

    },
    tj() {
      const formData = new FormData()
      this.fileList.forEach(item => {
        if (item.raw == '') {
        } else {
          formData.append('file', item.raw)
        }
      })
      formData.append('status', '1')
      formData.append('id', this.multipleSelection[0].id)
      formData.append('IDescription', this.rwxq)
      formData.append('iIsOverLimit', this.radio)
      formData.append('IPlanStep', this.measures)
      formData.append('IOverLimitTarget', this.checkedCities.toString())
      uploadLoadTypeUserI(formData) //后端上传接口
          .then(res => {
            if (res.code == 'A0000') {
              this.$message({
                message: '提交成功!',
                type: 'success'
              })
              this.uploadConclusions = false
              this.initQuery()
            }
          })
          .catch(err => {
            // console.log(err);
          })
    },
    sc() {
      if (this.multipleSelection.length == 0) {
        this.$message({
          message: '请选择一条数据',
          type: 'warning'
        })
      }

      if (this.multipleSelection.length > 1) {
        this.$message({
          message: '只能选择一条数据',
          type: 'warning'
        })
      } else {
        this.fileList = []
        getLoadTypeUserById({
          id: this.multipleSelection[0].id
        }).then(res => {
          this.documentName = res.data.ifilePath == null ? '' : res.data.ifilePath
          res.data.ifilePath == null
              ? ''
              : this.fileList.push({
                name: res.data.ifilePath,
                url: res.data.ifile,
                raw: ''
              })
          this.radio = res.data.iisOverLimit == null ? '' : res.data.iisOverLimit.toString()
          this.checkedCities = res.data.ioverLimitTarget == null ? [] : res.data.ioverLimitTarget.split(',')
          this.measures = res.data.iplanStep == null ? '' : res.data.iplanStep
          this.rwxq = res.data.idescription == null ? '' : res.data.idescription
          this.uploadConclusions = true
        })
        this.addData.orgNo = this.multipleSelection[0].orgName == null ? '' : this.multipleSelection[0].orgName
        this.addData.loadType =
            this.multipleSelection[0].loadType == null ? '' : this.multipleSelection[0].loadType
        this.addData.userName =
            this.multipleSelection[0].userName == null ? '' : this.multipleSelection[0].userName
        this.addData.recordTime =
            this.multipleSelection[0].recordTime == null ? '' : this.multipleSelection[0].recordTime
      }
    },
    gl() {
      if (this.multipleSelection1.length == 0) {
        this.$message({
          message: '请选择1条数据进行关联!',
          type: 'warning'
        })
      } else {
        this.$confirm('关联营销用户后,该干扰源用户户将纳入常态化管理列表,是否确认关联?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          linkUser({
            relationUserName: this.multipleSelection1[0].name,
            id: this.multipleSelection[0].id,
            relationUserId: this.multipleSelection1[0].id,
            userLoadType: this.op == '发电用户' ? '0' : '1'
          }).then(res => {
            if (res.code == 'A0000') {
              this.$message({
                message: '关联成功',
                type: 'success'
              })
              this.initQuery()
            }
          })
          this.marketingUsers = false
          this.confirm = false
        })
      }
    },
    opselect(val) {
      if (this.op == '发电用户') {
        getPowerGenerationUserList({
          orgId: this.multipleSelection[0].orgNo,
          id: this.userNumber
        }).then(res => {
          this.undocumentednonlinearData1 = res.data
          this.marketingUsers = true
        })
      } else {
        getPowerClientList({
          orgId: this.multipleSelection[0].orgNo,
          id: this.userNumber
        }).then(res => {
          this.undocumentednonlinearData1 = res.data
          this.marketingUsers = true
        })
      }
    },
    handleSizeChange(val) {
      this.pageSize = val
      this.initQuery()
    },
    handleCurrentChange(val) {
      this.pageNum = val
      this.initQuery()
    },
    config() {
      this.userAdd = false
      addLoadTypeUser({
        ...this.addData
      }).then(res => {
        if (res.code == 'A0000') {
          this.$message({
            message: '新增成功',
            type: 'success'
          })
          this.initQuery()
        }
      })
    },
    add() {
      this.userAdd = true
      this.addData = {
        orgNo: JSON.parse(window.sessionStorage.getItem('Info')).deptId,
        loadType: this.interferenceType[0].id,
        userName: '',
        recordTime: ''
      }
    },
    //上传本地评估报告
    handleRemove(file, fileList) {
      // console.log(file, fileList,'111111');
    },
    handleChange(file, fileList) {
      // console.log(file, fileList);
      this.fileList = fileList
    },

    beforeRemove(file, fileList) {
      return this.$confirm(`确定移除 ${file.name}?`)
    },
    //上传
    handleRemove1(file, fileList1) {
      // console.log(file, fileList,'111111');
    },
    handleChange1(file, fileList) {
      // console.log(file, fileList);
      this.fileList = fileList
    },
    handleExceed1(files, fileList1) {
      this.$message.warning(
          `当前限制选择 3 个文件，本次选择了 ${files.length} 个文件，共选择了 ${
              files.length + fileList1.length
          } 个文件`
      )
    },
    beforeRemove1(file, fileList1) {
      return this.$confirm(`确定移除 ${file.name}?`)
    },
    //查询
    initQuery() {
      this.isLoading = true
      getLoadTypeUserList({
        loadType: this.formData.loadType,
        orgNo: this.orgNo,
        pageNum: this.pageNum,
        pageSize: this.pageSize,
        relationUserName: this.formData.userName,
        userName: this.formData.userName,
        fileUploadflag: this.upload
      }).then(res => {
        this.isLoading = false
        res.data.records.forEach(i => {
          this.interferenceType.forEach(o => {
            if (i.loadType == o.id) {
              i.loadType = o.name
            }
          })
        })
        this.undocumentednonlinearData = res.data.records
        this.total = res.data.total
      })
    },
    //   新增确定
    // determineFn(){
    //     this.userAdd=false;
    // },
    //   新增取消
    // cancelFn(){
    //     this.userAdd=false;
    // },

    //上传
    //   uploadFn(){
    //     this.uploadConclusions=true
    //   },

    //关联
    relationFn() {
      if (this.multipleSelection.length == 0) {
        this.$message({
          message: '请选择一条数据',
          type: 'warning'
        })
      } else if (this.multipleSelection.length > 1) {
        this.$message({
          message: '只能选择一条数据',
          type: 'warning'
        })
      } else {
        if (this.op == '发电用户') {
          getPowerGenerationUserList({
            orgId: this.multipleSelection[0].orgNo
          }).then(res => {
            this.marketingUsers = true
            this.undocumentednonlinearData1 = res.data
          })
        }
      }
    },
    // 切换选项
    handleNodeClick(data) {
      this.orgNo = data.id
    },
    toggleSelection(rows) {
      if (rows) {
        rows.forEach(row => {
          this.$refs.multipleTable.toggleRowSelection(row)
        })
      } else {
        this.$refs.multipleTable.clearSelection()
      }
    },
    toggleSelection1(rows) {
      if (rows) {
        rows.forEach(row => {
          this.$refs.multipleTable1.toggleRowSelection(row)
        })
      } else {
        this.$refs.multipleTable1.clearSelection()
      }
    },
    //勾选
    handleSelectionChange(val) {
      this.multipleSelection = val
      // console.log(
      //   this.multipleSelection,
      //   "this.multipleSelectionthis.multipleSelection"
      // );
    },
    selectAll() {
      this.$refs.multipleTable.clearSelection()
    },

    handleSelectionChange1(val) {
      // console.log(val, "valll");
      if (val.length > 1) {
        this.toggleSelection1([val[0]])
        this.multipleSelection1 = val
      } else {
        this.multipleSelection1 = val
      }
    },
    //重置
    Reset() {
      this.$refs.area.form.valueTitle = JSON.parse(window.sessionStorage.getItem('Info')).deptName
      this.orgNo = JSON.parse(window.sessionStorage.getItem('Info')).deptId
      this.upload = ''
      this.formData.loadType = this.interferenceType[0].id
      this.formData.userName = ''
      this.pageSize = 20
      this.pageNum = 1
    },
    ResetFn() {
      this.userNumber = ''
    },
    //判断颜色
    cellStyle(row) {
      // if(row.row.upload==1){
      //     // if(row.columnIndex==6 ){
      //         row.row.status='--'
      //     // }else if(row.columnIndex==7){
      //         row.row.plandetails='--'
      //     // }
      // }
      if (row.columnIndex == 6) {
        if (row.row.upload == 1) {
          row.row.status = '--'
        }
      }
      if (row.columnIndex == 7) {
        if (row.row.upload == 1) {
          row.row.plandetails = '--'
        }
      }
    },

    handleCheckedCitiesChange(value) {
      // console.log(value, "value");
      // console.log(this.checkedCities, "this.checkedCities");
    },

    // 提交审核
    submitAuditUser() {

      if (this.multipleSelection.length === 0) {
        this.$message({
          message: '请选择至少一条提交审核',
          type: 'warning'
        })
        return false;
      }

      //需要保证当前用户只能操作自己建的计划

      this.loadTypeId = []
      let flag = true
      let flagFile = true
      this.multipleSelection.forEach(item => {
        if (item.istatus == 0 || item.istatus == 2) {
          this.loadTypeId.push(item.id)
        } else {
          flag = false
        }

        if (item.iisFileUpload !== 1) {
          flagFile = false
        }
      })

      if (!flagFile) {
        this.$message({
          message: '请选择已经上传评估报告的条目进行提交审核',
          type: 'warning'
        })
        return false;
      }

      if (flag && flagFile) {
        this.chooseAudit = true;

      } else {
        this.$message({
          message: '请选择新建、未通过的计划进行审核！',
          type: 'warning'
        })
      }
    },

    //确认发起审核
    auditSubmit() {
      if (!this.auditUser || this.auditUser === '') {
        this.$message({
          message: '请选择审核人!',
          type: 'warning'
        })
        return false;
      }

      let data = {ids: this.loadTypeId, checkPerson: this.auditUser}
      submitAuditUser(data).then(res => {
        if (res && res.code == 'A0000') {
          this.$message({
            message: '提交成功!',
            type: 'success'
          })
          this.chooseAudit = false
          this.initQuery()
        }
      })
    },

    //获取审核人列表
    getAuditUser() {
      let param = {roleType: 1}
      getAuditUser(param).then(res => {
        if (res && res.code === 'A0000') {
          this.auditUserList = res.data
        }
      })
    },
  }
}
</script>
<style lang="less" scoped>
@import url('../../../../styles/comStyle.less');

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

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

::v-deep .form {
  .el-form-item {
    margin-bottom: 5px;
  }
}

::v-deep .el-form-item {
  margin-bottom: 15px;
}

.button {
  float: right;
  margin-right: 5px;
}

::v-deep .el-dialog {
  display: flex;
  flex-direction: column;
  margin: 0 !important;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  /*height:600px;*/
  max-height: calc(100% - 200px);
  max-width: calc(100% - 30px);
}

::v-deep .el-dialog .el-dialog__body {
  flex: 1;
  overflow: auto;
}
</style>
