<template>
    <div class="periodCollect" v-loading="loadingImport">
        <div class="periodCollectBtn">
            <p class="titleSty">场站功率测点管理</p>
            <div class="collectSeach">
                <div class="exceed">
                    <span style="margin-top: 3px;">风场名称：</span>
                    <el-select v-model="windTurbines" placeholder="请选择" @change="changeStation">
                        <el-option
                        v-for="item in windFramoptions"
                        :key="item.no"
                        :label="item.stationName"
                        :value="item.no">
                        </el-option>
                    </el-select>
                </div>
                <el-button type="primary" style="margin-left: 10px;" @click="getSeachData">搜索</el-button>
                <el-button style="margin-left: 10px;" @click="reset">重置</el-button>
            </div>
            <div style="display:flex;justify-content: space-between;padding: 10px;">
                <el-row :gutter="10" class="PeriodBtn">
                    <el-col :span="1.5">
                        <el-button
                        type="danger"
                        plain
                        icon="Delete"
                        size="mini"
                        :disabled="deleteSelect.length === 0"
                        @click="handleDelete"
                        >批量删除</el-button>
                    </el-col>
                    <el-col :span="1.5">
                        <el-button
                        type="info"
                        plain
                        icon="Upload"
                        size="mini"
                        @click="handleImport"
                        >导入</el-button>
                    </el-col>
                    <el-col :span="1.5">
                        <el-button
                            type="warning"
                            plain
                            icon="Download"
                            size="mini"
                            @click="handleExport"
                        >导出</el-button>
                    </el-col>
                </el-row>
            </div>
            <div class="periodCollectTableData">
                <el-table :data="collecttableData" border style="width: 100%" @select="rowClick" @select-all="allSelect">
                    <el-table-column type="selection" label="操作" align="center"></el-table-column>
                    <el-table-column label="所属场站">
                        <template #default="scope">
                            <span>{{scope.row.windplantName}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="测点代码" width="400">
                        <template #default="scope">
                            <span>{{scope.row.name}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="描述">
                        <template #default="scope">
                            <span>{{scope.row.ref}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="倍率">
                        <template #default="scope">
                            <span>{{scope.row.ratio}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="统一测点">
                        <template #default="scope">
                            <span>{{scope.row.unifiedPoint}}</span>
                        </template>
                    </el-table-column>
                </el-table>
                <el-pagination
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :current-page="page.currentPage"
                    :page-size="page.pagesize"
                    layout="total, prev, pager, next, jumper"
                    :total="page.total">
                </el-pagination>
            </div>
        </div>
        <import-dailog ref="importPage" @successImport="successImport" @importLoading="importLoading"></import-dailog>
    </div>
</template>

<script>
import importDailog from './importPage/importDailog.vue'
import {apiGetStation, apiGetgetStationPowerMeasurementPointList, apiGetdeleteStationPowerMeasurementPoint} from '../../api/api'
export default {
  components: { importDailog },
    data() {
        return {
            changeDateSelect: [],
            changeBcrSelect: [],
            changeMvSelect: [],
            loadingImport: false,
            title:'',
            windTurbines:'',
            collecttableData:[],
            windFramoptions:[], //风电场数据
            projectNooptions: [], //期次数据
            collectradio: {},
            deleteSelect: [],
            deleteBcrSelect: [],
            deleteMvSelect: [],
            ashModify: true,
            regionaloptions:[],
            page:{
                pagesize: 12,
                currentPage: 1,
                total: 0
            }
        }
    },
    mounted() {
        this.getWindFramData()
        this.getCollectorwireprojectList()
    },
    methods:{
        changeStation(val) {
            this.windTurbines = val
        },
        getSeachData() {
            this.page.currentPage = 1
            this.getCollectorwireprojectList('seach')
        },
        successImport(val) {
            this.loadingImport = false
            this.getCollectorwireprojectList()
        },
        importLoading(val) {
            this.loadingImport = true
        },
        reset() {
            this.windTurbines = ''
            this.page = {
                pagesize: 12,
                currentPage: 1,
                total: 0
            }
            this.getCollectorwireprojectList()
        },
        handleSizeChange(val){
            this.page.pagesize = val
            if (this.windTurbines != '') {
                this.getCollectorwireprojectList('seach')
            } else {
                this.getCollectorwireprojectList()
            }
        },
        handleCurrentChange(val){
            this.page.currentPage =val
            if (this.windTurbines != '') {
                this.getCollectorwireprojectList('seach')
            } else {
                this.getCollectorwireprojectList()
            }
        },
        rowClick(selection, row) {
            this.collectradio = {}
            this.deleteSelect = []
            this.deleteBcrSelect = []
            this.deleteMvSelect = []

            this.changeDateSelect = []
            this.changeBcrSelect = []
            this.changeMvSelect = []
            if (selection.length === 1) { 
                this.collectradio = selection[0]
                this.ashModify = false
            } else {
                this.ashModify = true
            }
            if (selection.length > 0) {
                selection.forEach(item =>{
                    this.deleteSelect.push(item.collectorwireNo)
                    this.changeDateSelect.push(item.collectorwireNo)
                    if (item.type === 1) {
                        this.deleteMvSelect.push(item.pointNo)
                        this.changeMvSelect.push(item.pointNo)
                    } else {
                        this.deleteBcrSelect.push(item.pointNo)
                        this.changeBcrSelect.push(item.pointNo)
                    }
                })
            }
        },
        allSelect(selection) {
            this.ashModify = true
            this.deleteSelect = []
            this.deleteBcrSelect = []
            this.deleteMvSelect = []

            this.changeDateSelect = []
            this.changeBcrSelect = []
            this.changeMvSelect = []
            if (selection.length > 0) {
                selection.forEach(item =>{
                    this.deleteSelect.push(item.collectorwireNo)
                    this.changeDateSelect.push(item.collectorwireNo)
                    if (item.type === 1) {
                        this.deleteMvSelect.push(item.pointNo)
                        this.changeMvSelect.push(item.pointNo)
                    } else {
                        this.deleteBcrSelect.push(item.pointNo)
                        this.changeBcrSelect.push(item.pointNo)
                    }
                })
            }
        },
        // 获取风电场数据
        getWindFramData() {
            let that = this
            apiGetStation().then(datas =>{
                if (datas && datas.data && datas.data.list) {
                    that.windFramoptions = datas.data.list
                }
            })
        },
        handleDelete() {
            this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                let that = this
                let params = {
                    bcrPointNos: that.deleteBcrSelect.join(','),
                    mvPointNos: that.deleteMvSelect.join(','),
                }
                apiGetdeleteStationPowerMeasurementPoint(params).then(datas =>{
                    if (datas.msg === '操作成功') {
                        that.getCollectorwireprojectList()
                    }
                })
                if (that.collecttableData.length>0) {
                    that.collectradio = that.collecttableData[0]
                }
                this.$message({
                    type: 'success',
                    message: '删除成功!'
                });
            })
        },
        handleExport() {
            this.$utils.downloadPer('predict/api/spmpmc/stationPowerMeasurementPointExport', '场站功率测点管理.xlsx',  this.changeMvSelect, this.changeBcrSelect)
        },
        handleImport() {
            this.$refs.importPage.upload.title = "场站功率测点信息导入"
            this.$refs.importPage.upload.open = true
            this.$refs.importPage.upload.url = '/predict/api/spmpmc/stationPowerMeasurementPointImport'
            this.$refs.importPage.upload.urlName = 'stationPowerMeasurementPointImport'
            this.$refs.importPage.upload.proName = '场站功率测点信息模板.xlsx'
        },
        getCollectorwireprojectList(type) {
            let that = this
            let params = {
                pageNum: that.page.currentPage,
                pageSize: that.page.pagesize
            }
            if (type === 'seach') {
                params.windplantNo = that.windTurbines
            }
            apiGetgetStationPowerMeasurementPointList(params).then(datas =>{
                if (datas && datas.rows) {
                    that.collecttableData = datas.rows
                    that.collectradio = datas.rows[0]
                    that.page.total = datas.total
                    that.ashModify = true
                    that.deleteSelect = []
                }
            })
        }
    }
}
</script>

<style lang="less">
.periodCollect{
  .periodCollectBtn{
      background: #fff;
      padding: 10px 20px 0 20px;
      .collectSeach{
          display: flex;
          margin:20px;
            .exceed{
                display: flex;
                margin-right:20px;
                .el-select{
                    width: 200px;
                    margin-right:10px;
                    .el-input__inner{
                        height:30px;
                    }
                    .el-input__suffix{
                        .el-select__caret{
                            line-height:30px;
                        }
                    }
                }
            }
      }
      .titleSty{
          border-left: 4px solid #2996da;
          padding-left: 5px;
          font-size: 14px;
          margin-left:20px;
      }
      span{
          font-size:14px;
      }
      .PeriodBtn{
          padding-left: 10px;
      }
      .el-select{
          width: 160px;
          margin-right:10px;
          .el-input__inner{
              height:30px;
          }
          .el-input__suffix{
              .el-select__caret{
                  line-height:30px;
              }
          }
      }
      .el-button{
          height: 30px;
          // width:100px;
          padding: 0 30px ;
          // padding-top: 8px;
          span{
              margin:0;
          }
      }
  }
  .periodCollectTableData{
    padding: 10px 20px;
    .el-table{
      .el-table__body-wrapper{
        .el-table__empty-block{
          height: 550px !important;
        }
      }
      .el-input__inner{
          height: 30px !important;
      }
      .el-radio__label{
          display: none;
      }
    }
    .el-pagination{
        margin-top: 20px;
        text-align: end;
        position: relative;
    }
  }
  .el-dialog__wrapper{
      .el-dialog{
          .el-dialog__body{
              padding: 30px 60px 30px 20px !important;
          }
      }
      .periodFrom{
          .el-select, .el-date-editor{
              width: 100%;
          }
      }
  }
}
</style>