<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="regionaWh" placeholder="请选择" @change="changeRegion">
                        <el-option
                        v-for="item in regionaloptions"
                        :key="item.areaNo"
                        :label="item.name"
                        :value="item.areaNo">
                        </el-option>
                    </el-select>
                </div>
                <div class="exceed">
                    <span style="margin-top: 3px;">风场名称：</span>
                    <el-select v-model="windTurbines" placeholder="请选择" :disabled="!stationShow" @change="changeStation">
                        <el-option
                        v-for="item in windFramoptions"
                        :key="item.no"
                        :label="item.stationName"
                        :value="item.no">
                        </el-option>
                    </el-select>
                </div>
                <div class="exceed">
                    <span style="margin-top: 3px;">期次名称：</span>
                    <el-select v-model="windProject" placeholder="请选择" :disabled="!projectShow" @change="changeProject">
                        <el-option
                        v-for="item in windProjectoptions"
                        :key="item.projectNo"
                        :label="item.projectName"
                        :value="item.projectNo">
                        </el-option>
                    </el-select>
                </div>
                <div class="exceed">
                    <span style="margin-top: 3px;">集电线名称：</span>
                    <el-select v-model="windCollect" placeholder="请选择" :disabled="!collectShow">
                        <el-option
                        v-for="item in windCollectoptions"
                        :key="item.collectorwireNo"
                        :label="item.wireName"
                        :value="item.collectorwireNo">
                        </el-option>
                    </el-select>
                </div>
                <!-- <div class="exceed">
                    <span style="margin-top: 3px;">机组名称：</span>
                    <el-select v-model="windCrew" placeholder="请选择" :disabled="!collectShow">
                        <el-option
                        v-for="item in windCrewoptions"
                        :key="item.collectorwireNo"
                        :label="item.wireName"
                        :value="item.collectorwireNo">
                        </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="el-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="el-icon-upload2"
                        size="mini"
                        @click="handleImport"
                        >导入</el-button>
                    </el-col>
                    <el-col :span="1.5">
                        <el-button
                            type="warning"
                            plain
                            icon="el-icon-download"
                            size="mini"
                            @click="handleExport"
                        >导出</el-button>
                    </el-col>
                </el-row>
                <el-button type="primary" style="margin-right: 10px;" @click="toWtgMang">机组网络组态设计</el-button>
            </div>
            <div class="periodCollectTableData">
                <el-table :data="collecttableData" border style="width: 100%" @select="rowClick" @select-all="allSelect">
                    <!-- <el-table-column label="操作" width="60" align="center">
                        <template slot-scope="scope">
                            <el-radio v-model="collectradio" :label="scope.row"></el-radio>
                        </template>
                    </el-table-column> -->
                    <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="150">
                        <template #default="scope">
                            <span>{{scope.row.projectName}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="所属集电线">
                        <template #default="scope">
                            <span>{{scope.row.collectorwireName}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="机组代码">
                        <template #default="scope">
                            <span>{{scope.row.wtgIssue}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="机组名称">
                        <template #default="scope">
                            <span>{{scope.row.name}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="风机类型">
                        <template #default="scope">
                            <span>{{scope.row.typeName}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="机组经度">
                        <template #default="scope">
                            <span>{{scope.row.longtitude}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="机组纬度">
                        <template #default="scope">
                            <span>{{scope.row.latitude}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="海拔高度">
                        <template #default="scope">
                            <span>{{scope.row.elevation}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="装机容量(MW)" width="120">
                        <template #default="scope">
                            <span>{{scope.row.ratedPower}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="切入风速" width="80">
                        <template #default="scope">
                            <span>{{scope.row.cutInWspeed}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="切出风速" width="80">
                        <template #default="scope">
                            <span>{{scope.row.cutOutWspeed}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="额定风速" width="80">
                        <template #default="scope">
                            <span>{{scope.row.ratedWpeed}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="低温切出">
                        <template #default="scope">
                            <span>{{scope.row.lTemperature}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="高温切出">
                        <template #default="scope">
                            <span>{{scope.row.hTemperature}}</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 {apiGetgetStationsByAreaNo, apiGetgetAreaAll, apiGetdeleteWtur, 
apiGetgetWturList,apiGetCollectorwireprojectByProjectNo, apiGetWindplantprojectListByWindplantNo} from '../../api/api'
export default {
  components: { importDailog },
    data() {
        return {
            changeDateSelect: [],
            loadingImport: false,
            title:'',
            windTurbines:'',
            collecttableData:[],
            windFramoptions:[], //风电场数据
            projectNooptions: [], //期次数据
            windProject: '',
            stationShow: false, //场站是否能搜索
            projectShow: false, //期次是否能搜索
            windProjectoptions: [], // 搜索中期次的数据
            windCollect: '',
            collectShow:false,
            windCollectoptions: [], // 搜索中集电线的数据
            windCrew: '', 
            windCrewoptions: [], // // 搜索中机组的数据
            collectradio: {},
            deleteSelect: [],
            single: false,
            multiple: true,
            ashModify: true,
            dialogVisible:false,
            regionaWh: '',
            regionaloptions:[],
            page:{
                pagesize: 10,
                currentPage: 1,
                total: 0
            },
            ruleForm: {
                wpNo: '',
                projectNo: '',
                wireName:'',
                analogNo: '',
                wireCapacity: '',
                statSpeedTime:''
            },
            rules: {
                wpNo: [
                    { required: true, message: '请选择风场', trigger: 'change' }
                ],
                projectNo: [
                    { required: true, message: '请输入期次编号', trigger: 'blur' }
                ],
                wireName: [
                    { required: true, message: '请输入集电线名称', trigger: 'blur' }
                ],
                analogNo: [
                    { required: true, message: '请输入有功功率遥测号', trigger: 'blur' }
                ],
                wireCapacity: [
                    { required: true, message: '请输入装机容量', trigger: 'blur' }
                ],
                statSpeedTime: [
                    { type: 'date', required: true, message: '请选择日期', trigger: 'change' }
                ]
            }
        }
    },
    mounted() {
        this.getRegionalData()
    },
    methods:{
        toWtgMang() {
            this.$router.push({name: 'configurationDesign'})
        },
        getSeachData() {
            this.page.currentPage = 1
            this.getWturList('seach')
        },
        successImport(val) {
            this.loadingImport = false
            this.getWturList()
        },
        importLoading(val) {
            this.loadingImport = true
        },
        reset() {
            this.regionaWh = ''
            this.stationShow = false
            this.windTurbines = ''
            this.windProject = ''
            this.projectShow = false
            this.windCollect = ''
            this.collectShow = false
            this.page = {
                pagesize: 10,
                currentPage: 1,
                total: 0
            }
            this.getWturList()
        },
        handleSizeChange(val){
            this.page.pagesize = val
            if (this.windTurbines != '') {
                this.getWturList('seach')
            } else {
                this.getWturList()
            }
        },
        handleCurrentChange(val){
            this.page.currentPage =val
            if (this.windTurbines != '') {
                this.getWturList('seach')
            } else {
                this.getWturList()
            }
        },
        rowClick(selection, row) {
            this.collectradio = {}
            this.deleteSelect = []
            this.changeDateSelect = []
            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.wturNo)
                    this.changeDateSelect.push(item.wturNo)
                })
            }
        },
        allSelect(selection) {
            this.ashModify = true
            this.deleteSelect = []
            this.changeDateSelect = []
            if (selection.length > 0) {
                selection.forEach(item =>{
                    this.deleteSelect.push(item.wturNo)
                    this.changeDateSelect.push(item.wturNo)
                })
            }
        },
        // 获取风电场数据
        getWindFramData(val) {
            let that = this
            let params = {
                areaNo: val
            }
            apiGetgetStationsByAreaNo(params).then(datas =>{
                if (datas && datas.data && datas.data.list) {
                    that.windFramoptions = datas.data.list
                }
            })
        },
        // 获取风区数据
        getRegionalData() {
            let that = this
            apiGetgetAreaAll().then(datas =>{
                if (datas && datas.data && datas.data.list) {
                    that.regionaloptions = datas.data.list
                    that.getWturList('seach')
                }
            })
        },
        // 选择区域后
        changeRegion(val) {
            this.stationShow = true
            this.getWindFramData(val)
        },
        // 选择风电场后
        changeWindData(val) {
            if (!this.single) {
                this.multiple = false
                this.getprojectNoData(val)
            }
        },
        // 选择搜索中的风电场
        changeStation(val) {
            this.projectShow = true
            this.windProject = ''
            this.getprojectNoData(val, 'seach')
        },
        // 获取风电场期次数据
        getprojectNoData(val, type) {
            let that = this
            let params = {
                stationNo: val
            }
            apiGetWindplantprojectListByWindplantNo(params).then(datas =>{
                if (datas && datas.data && datas.data.list) {
                    if (type) {
                        that.windProjectoptions = datas.data.list
                    } else {
                        that.projectNooptions = datas.data.list
                    }
                }
            })
        },
        // 选择搜索中的期次
        changeProject(val) {
            this.collectShow = true
            this.getCollector(val)
        },
        // 根据期次查询集电线
        getCollector(num) {
            let that = this
            let params = {
                stationNo: that.windTurbines,
                projectNo: num.toString()
            }
            apiGetCollectorwireprojectByProjectNo(params).then(datas=>{
                if (datas && datas.data && datas.data.list.length>0) {
                    that.windCollectoptions = datas.data.list
                }
            })
        },
        handleDelete() {
            this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                let that = this
                let params = {
                    wturNos: this.deleteSelect.join(',')
                }
                apiGetdeleteWtur(params).then(datas =>{
                    if (datas.msg === '操作成功') {
                        that.getWturList()
                    }
                })
                if (that.collecttableData.length>0) {
                    that.collectradio = that.collecttableData[0]
                }
                this.$message({
                    type: 'success',
                    message: '删除成功!'
                });
            })
        },
        handleExport() {
            this.$utils.downloadPer('/predict/api/cmc/wturExport', '机组管理信息.xlsx', this.changeDateSelect)
        },
        handleImport() {
            this.$refs.importPage.upload.title = "机组管理信息导入"
            this.$refs.importPage.upload.open = true
            this.$refs.importPage.upload.url = '/predict/api/cmc/wturImport'
            this.$refs.importPage.upload.urlName = 'wturImport'
            this.$refs.importPage.upload.proName = '机组管理信息模板.xlsx'
        },
        getWturList(type) {
            let that = this
            let params = {
                pageNum: that.page.currentPage,
                pageSize: that.page.pagesize
            }
            if (type === 'seach') {
                params.areaNo = that.regionaWh
                params.windplantNo = that.windTurbines
                params.projectNo = that.windProject
                params.collectorwireNo = that.windCollect
            }
            apiGetgetWturList(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 .el-input__inner{
                        height:30px !important;
                    }
                    .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>