<template>
  <div class="pd10">
    <el-tabs v-model="activeName" type="border-card" @tab-click="handleClick">
      <el-tab-pane :label="item.label" :name="index + ''" v-for="(item, index) in storeList" :key="index"></el-tab-pane>
      <div id="select-form" v-if="activeName != '4'">
        <el-form ref="form" inline>
          <el-row>
            <el-col :span="4">
              <el-form-item class="box">
                <Area @click="handleNodeClick" ref="area"></Area>
              </el-form-item>
            </el-col>

            <el-col :span="5">
              <el-form-item label="日期">
                <div style="display: flex">
                  <el-select v-model="store.params.dataType" style="width: 80px; margin-right: 5px"
                    @change="timeChange">
                    <el-option label="年" value="01"></el-option>
                    <el-option label="月" value="02"></el-option>
                    <el-option label="日" value="03" v-if="activeName !== '2'"></el-option>
                  </el-select>
                  <el-date-picker style="width: 180px" v-model="store.params.searchBeginTime"
                    v-if="store.params.dataType == '01'" type="year" value-format="yyyy-MM-dd" @change="yearChange"
                    placeholder="选择年"></el-date-picker>
                  <el-date-picker style="width:180px" v-if="store.params.dataType == '02'" value-format="yyyy-MM-dd"
                    v-model="store.params.searchBeginTime" @change="monthChange" type="month"
                    placeholder="选择日期"></el-date-picker>
                  <el-date-picker style="width:180px" v-if="store.params.dataType == '03'" value-format="yyyy-MM-dd"
                    v-model="store.params.searchBeginTime" @change="dateChange" type="date"
                    placeholder="选择日期"></el-date-picker>
                </div>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item label="状态">
                <el-select v-model="store.params.searchState" placeholder="请选择">
                  <el-option label="全部" value=""></el-option>
                  <el-option label="已上送" value="1"></el-option>
                  <el-option label="未上送" value="0"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="11">
              <el-form-item>
                <el-button size="small" type="primary" icon="el-icon-search" @click="
                  store.params.pageNum = 1
                store.loading = true
                store.search()
                  ">
                  查询
                </el-button>
              </el-form-item>

              <el-form-item>
                <el-button type="primary" icon="el-icon-download" @click="exportEvent">导出</el-button>
              </el-form-item>
              <el-form-item v-if="storeList[activeName].canDataFeed">
                <el-button size="small" type="primary" icon="el-icon-upload2" :disabled="uploadButton" @click="feed">
                  PMS数据上送
                </el-button>
              </el-form-item>


              <el-form-item style="float: right">
                <el-button :disabled="store.params.dataType !== '03'" type="primary" @click="reCalUpload('')">
                  重新计算四个算法
                </el-button>
              </el-form-item>

              <el-form-item style="float: right;margin-right: 50px">
                <el-button :disabled="store.params.dataType === '01'" type="primary" @click="reCalUpload('1')">
                  {{ storeList[activeName].label + '重新计算' }}
                </el-button>
              </el-form-item>
            </el-col>


          </el-row>
          <el-row>
            <el-col :span="4">
              <el-form-item label="电压等级" v-if="activeName == '0'">
                <el-select clearable v-model="store.params.voltageLevel" 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-col>
            <el-col :span="5">
              <el-form-item label="指标类型" v-if="activeName == '0'">
                <el-select clearable v-model="store.params.targetType" placeholder="请选择" @change="targetChange">
                  <el-option v-for="item in targetList" :key="item.id" :label="item.name" :value="item.id"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item label="谐波次数" v-if="activeName == '0' && harmShowFlag">
                <el-select clearable v-model="store.params.harmCount" placeholder="请选择">
                  <el-option v-for="item in harmNum" :key="item" :label="item + '次'" :value="item"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12"></el-col>


          </el-row>


          <!-- <el-form-item style="float: right">
              <i class="el-icon-warning" style="color: rgb(241, 158, 60)"></i>
              未选中数据则上送列表所有数据
          </el-form-item> -->
        </el-form>
      </div>
      <div id="select-form" v-if="activeName == '4'">
        <el-form ref="aform" inline>
          <el-form-item label="日期">

            <el-date-picker style="width:180px" value-format="yyyy-MM-dd" v-model="store.params.searchBeginTime"
              @change="monthChange" type="month" placeholder="选择日期"></el-date-picker>




          </el-form-item>

          <el-form-item label="功能类型">
            <el-select clearable v-model="store.params.searchValue" style="width: 180px; margin-right: 5px">
              <el-option label="母线基准水平评估" value="0"></el-option>
              <el-option label="主网监测点统计" value="1"></el-option>
              <el-option label="变电站监测统计" value="2"></el-option>
              <el-option label="典型源荷指标统计" value="3"></el-option>
            </el-select>
          </el-form-item>

          <el-form-item label="执行结果">
            <el-select clearable v-model="store.params.sortBy" style="width: 180px; margin-right: 5px">
              <el-option label="成功" value="1"></el-option>
              <el-option label="失败" value="0"></el-option>

            </el-select>
          </el-form-item>

          <el-button size="small" type="primary" icon="el-icon-search" @click="
            store.params.pageNum = 1
          store.loading = true
          store.search()
            ">
            查询
          </el-button>

        </el-form>

      </div>
      <div v-loading="store.loading">
     
        <vxe-table ref="table" stripe :height="tableHeight" :data="store.data" size="mini" highlight-current-row
          header-cell-class-name="table_header" style="width: 100%" border @checkbox-all="handleSelectionChange"
          @checkbox-change="handleSelectionChange" :checkbox-config="{ checkMethod: checCheckboxkMethod }">

          <vxe-table-column key="uploadStatus" v-if="activeName != '4'" fixed="right" align="center" field="uploadStatus"
            show-overflow-tooltip title="上送状态" :min-width="130">
            <template slot-scope="scope">
              <el-tag type="primary" size="small" style="color: #409eff; background: #ecf5ff"
                v-if="scope.row.uploadStatus == 0 || scope.row.isUploadHead == 0">
                未上送
              </el-tag>
              <el-tag type="primary" size="small" style="color: #67c23a; background: #f0f9eb"
                v-if="scope.row.uploadStatus == 1 || scope.row.isUploadHead == 1">
                已上送
              </el-tag>
            </template>
          </vxe-table-column>

          <vxe-table-column v-if="activeName == '4'" key="result" fixed="right" align="center" field="result"
            show-overflow-tooltip title="运行结果 " :min-width="130">
            <template slot-scope="scope">
              <el-tag type="primary" size="small" style="color: #fc0303; background: #ecf5ff"
                v-if="scope.row.result == 0">
                失败
              </el-tag>
              <el-tag type="primary" size="small" style="color: #67c23a; background: #f0f9eb"
                v-if="scope.row.result == 1">
                成功
              </el-tag>
            </template>
          </vxe-table-column>




          <vxe-table-column :sortable="item.sortable" align="center" v-for="(item, index) in store.tableColumn"
            :field="item.prop" :title="item.label" :min-width="item.width" :show-overflow="true" :key="index"
            :formatter="formFilter"></vxe-table-column>
        </vxe-table>
        <el-pagination background align="right" @size-change="handleSizeChange" @current-change="handleCurrentChange"
          :current-page="store.params.pageNum" :page-sizes="[20, 30, 40, 50, 130]" :page-size="store.params.pageSize"
          layout="total, sizes, prev, pager, next, jumper" :total="store.total" class="mt10"></el-pagination>
      </div>

    </el-tabs>
  </div>
</template>
<script>
// import Timeinterval from '@/views/components/TimePicker/index6.vue'
import Timeinterval from '@/views/components/Timeinterval.vue'
import Area from '@/views/components/Area/Area.vue'
import list from '@/mixins/list'
import request from '@/utils/request'
import { dicData } from '@/assets/commjs/dictypeData'
import Monitoringpoint from '@/views/Account-management/components/Monitoringpoint.vue'
import { listRoleMenu } from '@/api/admin/role'

export default {
  mixins: [list],
  name: 'AlgorithmTemplate',
  components: { Area, Timeinterval, Monitoringpoint },
  data() {
    return {
      activeName: '0',
      canDataFeed: false,
      time: '02',
      voltageLevelList: [],
      targetList: [],
      harmNum: [],
      harmShowFlag: false,
      storeList: [
        // {
        //     label: '换流站指标汇总统计',
        //     url: '/harmonic-boot/ConverterIndex/queryPage',
        //     feedUrl: '/harmonic-boot/ConverterIndex/send',
        //     tableColumn: [
        //         { label: '发生超标或暂态母线日均占比（%）', prop: 'abnormalBusAvgRate', width: 130 },
        //         { label: '发生超标或暂态母线数量（条）', prop: 'abnormalBusNum', width: 130 },
        //         { label: '发生超标或暂态母线占比（%）', prop: 'abnormalBusRate', width: 130 },
        //         { label: '发生超标或暂态换流站日均占比（%）', prop: 'abnormalConverterAvgRate', width: 130 },
        //         { label: '发生超标或暂态换流站数量（条）', prop: 'abnormalConverterNum', width: 130 },
        //         { label: '发生超标或暂态换流站占比（%）', prop: 'abnormalConverterRate', width: 130 },
        //         { label: '市级单位id', prop: 'cityId', width: 200 },
        //         { label: '市级单位名称', prop: 'cityName', width: 200 },
        //         { label: '监测交流母线数量（条）', prop: 'monitorAlternatingBusNum', width: 130 },
        //         { label: '交流母线监测率（%）', prop: 'monitorAlternatingBusRate', width: 130 },
        //         { label: '监测换流站数量（座）', prop: 'monitorConverterNum', width: 130 },
        //         { label: '换流站监测率（%）', prop: 'monitorConverterRate', width: 130 },
        //         { label: '在运交流母线数量（条）', prop: 'onlineAlternatingBusNum', width: 130 },
        //         { label: '在运换流站数量（座）', prop: 'onlineConverterNum', width: 130 },
        //         { label: '省级单位名称', prop: 'provinceName', width: 200 },
        //         { label: '省级单位id', prop: 'provinceId', width: 200 },
        //         { label: '统计日期', prop: 'statisticalDate', width: 130 },
        //         { label: '统计类型', prop: 'statisticalType', width: 130 },
        //         { label: '统计层级', prop: 'statisticalLevel', width: 130 },
        //         { label: '累计发生超标或暂态换流站数量（座）', prop: 'abnormalConverterCount', width: 130 },
        //         { label: '累计监测换流站数量（座）', prop: 'monitorConverterCount', width: 130 },
        //         { label: '累计发生超标或暂态母线数量（座）', prop: 'abnormalBusCount', width: 130 },
        //         { label: '累计监测交流母线数量（座）', prop: 'monitorAlternatingBusCount', width: 130 }
        //     ]
        // },
        // {
        //     label: '换流站指标统计明细',
        //     url: '/harmonic-boot/ConverterDetail/queryPage',
        //     feedUrl: '/harmonic-boot/ConverterDetail/send',
        //     tableColumn: [
        //         { label: '市级单位id', prop: 'cityId', width: 130 },
        //         { label: '市级单位名称', prop: 'cityName', width: 130 },
        //         { label: '换流站id', prop: 'converterId', width: 130 },
        //         { label: '县级单位id', prop: 'countyId', width: 130 },
        //         { label: '县级单位名称', prop: 'countyName', width: 130 },
        //         { label: '站内有效监测点数量（个）', prop: 'effectiveMonitorNum', width: 130 },
        //         { label: '月均超标天数', prop: 'monthOvDays', width: 130 },
        //         { label: '奇次谐波电压限值（%）', prop: 'oddVoltLimit', width: 130 },
        //         { label: '省级单位id', prop: 'provinceId', width: 130 },
        //         { label: '省级单位名称', prop: 'provinceName', width: 130 },
        //         { label: '统计日期', prop: 'statisticalDate', width: 130 },
        //         { label: '统计类型', prop: 'statisticalType', width: 130 },
        //         { label: '累计超标天数', prop: 'totalOvDays', width: 130 },
        //         { label: '11次谐波电压95%概率值（%）', prop: 'v11', width: 130 },
        //         { label: '13次谐波电压95%概率值（%）', prop: 'v13', width: 130 },
        //         { label: '23次谐波电压95%概率值（%）', prop: 'v23', width: 130 },
        //         { label: '25次谐波电压95%概率值（%）', prop: 'v25', width: 130 },
        //         { label: '3次谐波电压95%概率值（%）', prop: 'v3', width: 130 },
        //         { label: '5次谐波电压95%概率值（%）', prop: 'v5', width: 130 },
        //         { label: '7次谐波电压95%概率值（%）', prop: 'v7', width: 130 },
        //         { label: '电压等级', prop: 'voltageLevel', width: 130 },
        //         { label: '电压总谐波畸变率95%概率值统计值（%）', prop: 'vthd', width: 130 },
        //         { label: '电压总谐波畸变率95%概率值限值（%）', prop: 'vthdLimit', width: 130 },
        //         { label: '换流站名称', prop: 'converterName', width: 130 },
        //         { label: '谐波电压超标天数', prop: 'harmvOvDay', width: 130 },
        //         { label: '母线id', prop: 'busId', width: 130 },
        //         { label: '母线名称', prop: 'busName', width: 130 },
        //         { label: '母线电压等级', prop: 'busVoltageLevel', width: 130 },
        //         { label: '当年累计月数', prop: 'monthsCount', width: 130 },
        //         { label: '监测点id', prop: 'monitorId', width: 130 }
        //     ]
        // },
        {
          label: '主网监测点统计',
          url: '/harmonic-boot/upload/getPointStatisticalData',
          feedUrl: '/harmonic-boot/upload/uploadPointStatisticalData',
          canDataFeed: false,
          tableColumn: [
            { label: '省级单位名称', prop: 'provinceName', width: 200 },
            { label: '市级单位名称', prop: 'cityName', width: 200 },
            { label: '县级单位名称', prop: 'countyName', width: 200 },
            { label: '统计日期', prop: 'statisticalDate', width: 130 },
            { label: '所属站别', prop: 'stationType', width: 130 },
            { label: '在运监测终端数量', prop: 'runTerminalNum', width: 130 },
            { label: '所属站别下的监测点数', prop: 'stationMonitorNum', width: 160 },
            { label: '在运监测点个数', prop: 'runMonitorNum', width: 130 },
            { label: '在线监测点个数', prop: 'onlineMonitorNum', width: 130 },
            { label: '监测点在线率%', prop: 'onlineMonitorRate', width: 130 },
            { label: '数据应收数', prop: 'expectCollectNum', width: 130 },
            { label: '数据实收数', prop: 'actualCollectNum', width: 130 },
            { label: '数据完整率%', prop: 'dataFullRate', width: 130, sortable: true }
          ]
        },
        {
          label: '母线基准水平评估',
          url: '/harmonic-boot/upload/getEvaluationData',
          feedUrl: '/harmonic-boot/upload/uploadEvaluationData',
          canDataFeed: false,
          tableColumn: [
            { label: '省级单位', prop: 'provinceName', width: 200 },
            { label: '市级单位', prop: 'cityName', width: 200 },
            { label: '县级单位', prop: 'countyName', width: 200 },
            { label: '统计日期', prop: 'statisticalDate', width: 130 },
            { label: '电压等级', prop: 'voltageLevel', width: 130 },
            { label: '指标类型', prop: 'indexType', width: 130 },
            { label: '谐波次数', prop: 'harmonicNum', width: 130 },
            { label: '监测母线数量', prop: 'monitorBusNum', width: 130 },
            { label: '在运母线数量', prop: 'onlineBusNum', width: 130 },
            { label: '母线监测率(%)', prop: 'monitorBusRate', width: 130 },
            { label: '均值', prop: 'avgValue', width: 130 },
            { label: '标准差', prop: 'standardDeviation', width: 130 }
          ]
        },
       
        {
          label: '变电站监测统计',
          url: '/harmonic-boot/upload/getSubstationStatisticalData',
          feedUrl: '/harmonic-boot/upload/uploadSubstationStatisticalData',
          canDataFeed: false,
          tableColumn: [
            { label: '省级单位名称', prop: 'provinceName', width: 200 },
            { label: '市级单位名称', prop: 'cityName', width: 200 },
            { label: '县级单位名称', prop: 'countyName', width: 200 },
            { label: '统计日期', prop: 'statisticalDate', width: 130 },
            { label: '变电站总数量', prop: 'substationCount', width: 130 },
            { label: '在运变电站数量', prop: 'runSubstationNum', width: 130 },
            { label: '监测变电站数量', prop: 'monitorSubstaionNum', width: 130 },
            { label: '监测率%', prop: 'monitoringRate', width: 130 },
            { label: '覆盖率%', prop: 'coverageRate', width: 130 },
            { label: '测试变电站数量', prop: 'testSubstaionNum', width: 130 },
            { label: '在线监测点数', prop: 'onlineMonitorNum', width: 130 }
          ]
        },
        {
          label: '典型源荷指标统计',
          url: '/harmonic-boot/pqTypicalSourceCreate/queryPage',
          feedUrl: '/harmonic-boot/pqTypicalSourceCreate/send',
          tableColumn: [
            { label: '所属网省名称', prop: 'provinceName', width: 200 },
            { label: '所属地市名称', prop: 'cityName', width: 200 },
            { label: '所属区县名称', prop: 'countyName', width: 200 },
            { label: '统计日期', prop: 'statisticalDate', width: 150 },

            { label: '统计类型', prop: 'statisticalType', width: 150 },
            { label: '典型源荷用户类型', prop: 'indexType', width: 150 },
            { label: '干扰源数量', prop: 'interferenceSourceNum', width: 150 },
            { label: '实现监测数量', prop: 'monitorNum', width: 150 },
            { label: '监测率', prop: 'monitoringRate', width: 150 },
            { label: '行业分类', prop: 'industryType', width: 150 },
            { label: '平均超标天数', prop: 'averageOvDays', width: 150 },
            { label: '总超标数量', prop: 'ovNum', width: 150 },
            { label: '超标占比', prop: 'ovRate', width: 150 },

            { label: '闪变超标数', prop: 'flickerOvNum', width: 150 },
            { label: '闪变平均超占比', prop: 'flickerAvgOvRate', width: 150 },
            { label: '闪变超标占比', prop: 'flickerOvRate', width: 150 },

            { label: '谐波电流超标数', prop: 'iovNum', width: 150 },
            { label: '谐波电流平均超标占比', prop: 'iavgOvRate', width: 180 },
            { label: '谐波电流超标占比', prop: 'iovRate', width: 180 },

            { label: '负序电流超标数', prop: 'inseqOvNum', width: 150 },
            { label: '负序电流平均超标占比', prop: 'inseqAvgOvRate', width: 180 },
            { label: '负序电流超标占比', prop: 'inseqOvRate', width: 150 },


            { label: '三相不平衡超标数', prop: 'unbanOvNum', width: 150 },
            { label: '三相不平衡超标占比', prop: 'unbanOvRate', width: 180 },
            { label: '谐波电压平均超标占比', prop: 'vavgOvRate', width: 180 },
            { label: '谐波电压超标数', prop: 'vovNum', width: 160 },
            { label: '谐波电压超标占比', prop: 'vovRate', width: 160 },
            { label: '三相不平衡平均超标占比', prop: 'unbanAvgOvRate', width: 180 },
            { label: '累计超标天数合计', prop: 'ovDayCount', width: 160 }
          ]
        },
        {
          label: '网公司上送统计',
          url: '/harmonic-boot/rUploadDataLog/getList',
          tableColumn: [
            { label: '统计时间', prop: 'statisticDate', width: 200 },
            { label: '功能', prop: 'smallType', width: 200 },
            { label: '描述', prop: 'resultMsg', width: 1000, showOverflow: true },
          ]
        }
      ],

      uploadButton: false,
      voltageLevelOptions: [],
      multipleSelection: [],

      stationType: [],
      industryType: []
    }
  },
  created() {
    this.init()
    this.voltageLevelOptions = dicData('Dev_Voltage', [])

    this.stationType = dicData('Station_Type', [])
    this.industryType = dicData('industry_type', [])
    listRoleMenu({
      id: JSON.parse(window.sessionStorage.getItem('Info')).roleList[0]
    }).then(response => {
      this.storeList.forEach(item => {
        item.canDataFeed = response.data.some(item2 => item2.routePath === item.feedUrl)
      })
    })

    this.voltageLevelList = dicData('Dev_Voltage', [])
    this.targetList = [{ name: '电压', id: '01' }, { name: '长时闪变', id: '02' }, {
      name: '三相电压不平衡',
      id: '03'
    }, { name: '电压总谐波畸变率', id: '04' }, { name: '各次谐波电压', id: '05' }, { name: '负序电流', id: '06' }]

    this.harmNum = []
    for (let i = 2; i < 51; i++) {
      this.harmNum.push(i)
    }

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

  beforeDestroy() {
    window.removeEventListener('resize', this.setHeight)
  },
  methods: {


    targetChange(val) {


      if (val == '05') {
        this.harmShowFlag = true
      } else {
        this.harmShowFlag = false
        store.params.harmCount = null
      }

    },

    setHeight() {
      this.tableHeight = window.sessionStorage.getItem('appheight') - 200
    },
    checCheckboxkMethod({ row }) {
      // return row.cityId == '/' && row.countyId == '/'
      return row.countyId == '/'
    },
    //导出
    exportEvent() {
      if (this.store.data.length === 0) {
        this.$message({
          type: 'warning',
          message: '暂无数据'
        })
        return
      }
      this.store.export(data => {
        this.$refs.table.exportData({
          filename: 'export', // 文件名字
          sheetName: 'Sheet1',
          type: 'xlsx', //导出文件类型 xlsx 和 csv
          useStyle: true,
          data, // 数据源
          columnFilterMethod: function (column, $columnIndex) {
            return !(column.$columnIndex === 0)
          }
        })
      })
    },
    timeChange() {
      let day = new Date()
      day.setDate(day.getDate() - 1)
      if (this.store.params.dataType == '01') {
        this.uploadButton = true;
        this.store.params.searchBeginTime = this.$tools.formatDate(day, 'yyyy-MM-dd').substring(0, 5) + '01-01'
        this.store.params.searchEndTime = this.store.params.searchBeginTime.substring(0, 5) + '12-30'
      } else if (this.store.params.dataType == '02') {

        this.uploadButton = true;
        this.store.params.searchBeginTime = this.$tools.formatDate(day, 'yyyy-MM-dd').substring(0, 8) + '01'
        this.store.params.searchEndTime =
          this.$tools.formatDate(day, 'yyyy-MM-dd').substring(0, 8) +
          this.getDaysInMonth(
            this.store.params.searchBeginTime.substring(5, 7) - 0,
            this.store.params.searchBeginTime.substring(0, 4) - 0
          )
      } else {
        this.uploadButton = false;
        this.store.params.searchBeginTime = this.$tools.formatDate(day, 'yyyy-MM-dd')
        this.store.params.searchEndTime = this.store.params.searchBeginTime
      }
    },
    dateChange(e) {
      this.store.params.searchEndTime = this.store.params.searchBeginTime
    },
    monthChange(e) {
      // this.store.params.searchEndTime = this.store.params.searchBeginTime
      this.store.params.searchEndTime =
        this.store.params.searchBeginTime.substring(0, 8) +
        this.getDaysInMonth(e.substring(5, 7), e.substring(0, 4))
    },
    yearChange(e) {
      this.store.params.searchEndTime = this.store.params.searchBeginTime.substring(0, 5) + '12-30'
    },
    getDaysInMonth(month, year) {
      return new Date(year, month, 0).getDate()
    },
    feed() {
      if (this.multipleSelection.length === 0) {
        this.$confirm('是否上送全部监测点?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.store.loading = true
          request
            .post(this.storeList[this.activeName].feedUrl, {
              list: [],
              time:
                this.store.params.dataType == '01'
                  ? this.store.params.searchBeginTime.substring(0, 4)
                  : this.store.params.dataType == '02'
                    ? this.store.params.searchBeginTime.substring(0, 7)
                    : this.store.params.searchBeginTime
            })
            .then(res => {
              if (res && res.code === 'A0000') {
                this.$message({
                  message: '上送成功!',
                  type: 'success'
                })
                this.multipleSelection = []
                this.store.search()
              }
              this.store.loading = false
            })
            .catch(err => {
              this.store.loading = false
            })
        })
      } else {
        this.store.loading = true
        request
          .post(this.storeList[this.activeName].feedUrl, {
            list: this.multipleSelection,
            time:
              this.store.params.dataType == '01'
                ? this.store.params.searchBeginTime.substring(0, 4)
                : this.store.params.dataType == '02'
                  ? this.store.params.searchBeginTime.substring(0, 7)
                  : this.store.params.searchBeginTime
          })
          .then(res => {
            if (res && res.code === 'A0000') {
              this.$message({
                message: '上送成功!',
                type: 'success'
              })
              this.multipleSelection = []
              this.store.search()
            }
            this.store.loading = false
          })
          .catch(err => {
            this.store.loading = false
          })
      }
    },

    //重新计算四个算法
    reCalUpload(type) {
      if (this.store.params.dataType === '02') {
        if (type == null || type === '') {
          this.$message({
            message: '请选择类型',
            type: 'warning'
          })
          return false;
        }
        let dateMonth = this.store.params.searchBeginTime.substring(0, 7)
        //月
        request
          .get('/prepare-boot/dimGlobal/reCalMonthUploadAlgorithm?statisticDate=' + dateMonth + '&type=1')
          .then(res => {
            if (res && res.code === 'A0000') {
              this.$message({
                message: '请求重新计算指令成功!请等待大约20s后刷新页面',
                type: 'success'
              })
            }
          }).catch(err => {
          })
      } else {
        request
          .get('/prepare-boot/dimGlobal/reCalUploadAlgorithm?statisticDate=' + this.store.params.searchBeginTime + '&type=1')
          .then(res => {
            if (res && res.code === 'A0000') {
              this.$message({
                message: '请求重新计算指令成功!请等待大约20s后刷新页面',
                type: 'success'
              })
            }
          }).catch(err => {
          })
      }

    },
    init(data = {}) {
      this.store = this.dataSource(this.storeList[this.activeName].url)
      console.log("🚀 ~ init ~ this.store:", this.store)
      let day = new Date()
      day.setDate(day.getDate() - 1)
      this.store.params.dataType = '03'
      if (this.activeName === '2' || this.activeName === '4') {
        //电站只有月和年
        this.store.params.dataType = '02'

      }
      if (this.store.params.dataType == '01') {
        if (this.activeName == '2') {
          this.uploadButton = false;
        } else {
          this.uploadButton = true;
        }

        this.store.params.searchBeginTime = this.$tools.formatDate(day, 'yyyy-MM-dd').substring(0, 5) + '01-01'
        this.store.params.searchEndTime = this.store.params.searchBeginTime.substring(0, 5) + '12-30'
      } else if (this.store.params.dataType == '02') {
        if (this.activeName == '2') {
          this.uploadButton = false;
        } else {
          this.uploadButton = true;
        }

        this.store.params.searchBeginTime = this.$tools.formatDate(day, 'yyyy-MM-dd').substring(0, 8) + '01'
        this.store.params.searchEndTime =
          this.$tools.formatDate(day, 'yyyy-MM-dd').substring(0, 8) +
          this.getDaysInMonth(
            this.store.params.searchBeginTime.substring(5, 7) - 0,
            this.store.params.searchBeginTime.substring(0, 4) - 0
          )
      } else {
        this.uploadButton = false;
        this.store.params.searchBeginTime = this.$tools.formatDate(day, 'yyyy-MM-dd')
        this.store.params.searchEndTime = this.store.params.searchBeginTime
      }

      this.store.tableColumn = this.storeList[this.activeName].tableColumn
      this.store.params.deptIndex = ''
      this.store.params.orgId = ''
      this.store.params.searchState = ''
      this.multipleSelection = []
      this.store.loadCallback = () => {
        this.store.data.forEach(item => {
          for (let key in item) {
            if (item[key] === null || item[key] === '') {
              item[key] = '/'
            } else if (item[key] === 3.1415926) {
              item[key] = '暂无数据'
            }
            // if (key === 'uploadStatus' || key === 'isUploadHead') {
            //     item['uploadStatus'] = item[key] === 0 ? '未上送' : '已上送'
            // }
            else if (key === 'indexType') {
              let arr =
                this.store.url === '/harmonic-boot/upload/getEvaluationData'
                  ? [
                    { label: '电压', value: '01' },
                    { label: '长时间闪变', value: '02' },
                    { label: '三相电压不平衡', value: '03' },
                    { label: '电压总谐波畸变率', value: '04' },
                    { label: '各次谐波电压', value: '05' },
                    { label: '负序电流', value: '06' }
                  ]
                  : [
                    { label: '牵引站', value: '01' },
                    { label: '风电场用户', value: '02' },
                    { label: '光伏场站用户', value: '03' },
                    { label: '其他干扰源用户', value: '04' }
                  ]
              item[key] =
                arr.find(item2 => item2.value === item[key]) &&
                arr.find(item2 => item2.value === item[key]).label
            } else if (key === 'voltageLevel') {
              item[key] =
                this.voltageLevelOptions.find(item2 => item2.value === item[key]) &&
                this.voltageLevelOptions.find(item2 => item2.value === item[key]).label
            }
          }
        })
      }
    },
    handleNodeClick(data) {
      console.log(data)
      if (!this.store.params.deptIndex && !this.store.params.orgId) {
        this.store.params.deptIndex = data.code
        this.store.params.orgId = data.code
        this.store.reload()
      } else {
        this.store.params.deptIndex = data.code
        this.store.params.orgId = data.code
      }
    },
    handleClick(tab, event) {
      this.init()
      this.$refs.area.init()
    },
    handleSelectionChange({ records }) {
      console.log(records)
      this.multipleSelection = records.map(item => item.id)
    },



    // 数据过滤
    formFilter(row, column) {
      //   console.log(row)
      if (row.column.property == 'statisticalType') {
        return row.row.statisticalType == '01'
          ? '年数据'
          : row.row.statisticalType == '02'
            ? '月数据'
            : '日数据'
      } else if (row.column.property == 'stationType') {
        let name
        this.stationType.forEach(item => {
          if (item.value == row.row.stationType) {
            name = item.name
          }
        })
        return name
      } else if (row.column.property == 'industryType') {
        let name
        this.industryType.forEach(item => {
          if (item.gvalue == row.row.industryType) {
            name = item.name
          }
        })
        return name
      } else if (row.column.property == 'smallType') {
        if (row.row.smallType == 0) {
          return '母线基准水平评估'
        } else if (row.row.smallType == 1) {
          return '主网监测点统计'
        } else if (row.row.smallType == 2) {
          return '变电站监测统计'
        } else if (row.row.smallType == 3) {
          return '典型源荷指标统计'
        }

      } else if (row.column.property == 'result') {
        if (row.row.result == 0) {
          return '失败'
        } else if (row.row.result == 1) {
          return '成功'
        }

      } else {
        return row.row[row.column.property]
      }
    }
  }
}
</script>
<style lang="sass"></style>
