<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-input v-model="windTurbines" placeholder="请输入测点类型"></el-input>
                </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 label="操作" width="60" align="center">
                        <template slot-scope="scope">
                            <el-radio v-model="windframradio" :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.itemType}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="测点编号" width="400">
                        <template #default="scope">
                            <span>{{scope.row.itemNo}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="测点描述">
                        <template #default="scope">
                            <span>{{scope.row.itemName}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="描述简称">
                        <template #default="scope">
                            <span>{{scope.row.itemRef}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="备注">
                        <template #default="scope">
                            <span>{{scope.row.note}}</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 {apiGetgetStandardPointManagementList, apiGetdeleteStandardPointManagement} from '../../api/api'
export default {
  components: { importDailog },
    data() {
        return {
            windframradio: {},
            deleteSelect: [],
            changeDateSelect: [],
            loadingImport: false,
            windTurbines:'',
            collecttableData:[],
            single: false,
            regionaloptions:[],
            page:{
                pagesize: 12,
                currentPage: 1,
                total: 0
            }
        }
    },
    mounted() {
        this.getCollectorwireprojectList()
    },
    methods:{
        getSeachData() {
            this.page.currentPage = 1
            this.getCollectorwireprojectList('seach')
        },
        successImport(val) {
            this.loadingImport = false
            this.getCollectorwireprojectList()
        },
        importLoading(val) {
            this.loadingImport = true
        },
        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.windframradio = {}
            this.deleteSelect = []
            this.changeDateSelect = []
            if (selection.length === 1) { 
                this.windframradio = selection[0]
            }
            if (selection.length > 0) {
                selection.forEach(item =>{
                    this.deleteSelect.push(item.itemNo)
                    this.changeDateSelect.push(item.itemNo)
                })
            }
        },
        allSelect(selection) {
            this.deleteSelect = []
            this.changeDateSelect = []
            if (selection.length > 0) {
                selection.forEach(item =>{
                    this.deleteSelect.push(item.itemNo)
                    this.changeDateSelect.push(item.itemNo)
                })
            }
        },
        reset() {
            this.windTurbines = ''
            this.page = {
                pagesize: 12,
                currentPage: 1,
                total: 0
            }
            this.getCollectorwireprojectList()
        },
        handleDelete() {
            this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                let that = this
                let params = {
                    itemNos: this.deleteSelect.join(',')
                }
                apiGetdeleteStandardPointManagement(params).then(datas =>{
                    if (datas.msg === '操作成功') {
                        that.getCollectorwireprojectList()
                    }
                })
                if (that.collecttableData.length>0) {
                    that.windframradio = that.collecttableData[0]
                }
                this.$message({
                    type: 'success',
                    message: '删除成功!'
                });
            })
        },
        handleExport() {
            this.$utils.downloadPer('predict/api/smpmc/standardPointManagementExport', '规范测点信息数据.xlsx', this.changeDateSelect)
        },
        handleImport() {
            this.$refs.importPage.upload.title = "规范测点信息导入"
            this.$refs.importPage.upload.open = true
            this.$refs.importPage.upload.url = '/predict/api/smpmc/standardPointManagementImport'
            this.$refs.importPage.upload.urlName = 'standardPointManagementImport'
            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.wpNo = that.windTurbines
                params.projectNo = that.windProject
                params.collectorwireNo = that.windCollect
            }
            apiGetgetStandardPointManagementList(params).then(datas =>{
                if (datas && datas.rows) {
                    that.collecttableData = datas.rows
                    that.windframradio = datas.rows[0]
                    that.page.total = datas.total
                    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-input{
                    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>