<template>
    <div class="windframconfig">
        <div class="windframBtn">
            <p class="titleSty">预测上报管理</p>
            <div class="periodSeach">
                <div class="exceed">
                    <span style="margin-top: 3px;">场站名称：</span>
                    <el-select v-model="regionaWh" placeholder="请选择">
                        <el-option
                        v-for="item in regionaloptions"
                        :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="typeWh" placeholder="请选择">
                        <el-option
                        v-for="item in typeoptions"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value">
                        </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="regionalBtn">
                    <el-col :span="1.5">
                        <el-button
                        type="primary"
                        plain
                        icon="Plus"
                        size="mini"
                        @click="handleAdd"
                        >新增</el-button>
                    </el-col>
                    <el-col :span="1.5">
                        <el-button
                        type="success"
                        plain
                        icon="Edit"
                        size="mini"
                        @click="handleUpdate"
                        >修改</el-button>
                    </el-col>
                    <el-col :span="1.5">
                        <el-button
                        type="danger"
                        plain
                        icon="Delete"
                        size="mini"
                        @click="handleDelete"
                        >删除</el-button>
                    </el-col>
                    <!-- <el-col :span="1.5">
                        <el-button
                        type="warning"
                        plain
                        icon="el-icon-document-copy"
                        size="mini"
                        @click="handleReport"
                        >重新生成文件</el-button>
                    </el-col> -->
                </el-row>
            </div>
            <div class="windframTableData">
                <el-table :data="windframtableData.slice((page.currentPage-1)*page.pagesize, page.currentPage*page.pagesize)" border style="width: 100%" @row-click="rowClick">
                    <el-table-column label="操作" width="60" align="center">
                        <template #default="scope">
                            <el-radio v-model="windframradio" :label="scope.row"></el-radio>
                        </template>
                    </el-table-column>
                    <el-table-column label="场站名称">
                        <template #default="scope">
                            <span>{{scope.row.terminalNameW || scope.row.terminalNameP}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="类型名称">
                        <template #default="scope">
                            <span>{{showType(scope.row.terminalType)}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="上报时间">
                        <template #default="scope">
                            <span>{{scope.row.reportTime}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="数据时间">
                        <template #default="scope">
                            <span>{{scope.row.dataTime}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="上报状况">
                        <template #default="scope">
                            <span>{{scope.row.statTag === 1 ? '成功' : '失败'}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="重新上报">
                        <template #default="scope">
                            <el-icon style="color: green;font-size:20px;cursor:pointer;position:relative;top: 3px;" @click="uploadMsg(scope.row)">
                                <Upload />
                            </el-icon>
                            <!-- <i class="Upload" style="color: green;font-size:20px;cursor:pointer"></i> -->
                        </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>
        <el-dialog :title="title" v-model="dialogVisible" width="600px" :close-on-click-modal="false" @close="closeDialog">
            <div class="windframFrom">
                <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
                    <el-form-item label="场站名称" prop="station">
                        <el-select v-model="ruleForm.station" placeholder="请选择场站">
                            <el-option
                            v-for="item in regionaloptions"
                            :key="item.no"
                            :label="item.stationName"
                            :value="item.no">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="类型名称" prop="type">
                        <el-select v-model="ruleForm.type" placeholder="请选择类型">
                            <el-option
                            v-for="item in typeoptions"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <!-- <el-form-item label="上传时间" prop="picker">
                        <el-date-picker
                            v-model="ruleForm.picker"
                            type="datetime"
                            placeholder="选择日期时间">
                        </el-date-picker>
                    </el-form-item>
                    <el-form-item label="文件路径">
                        <el-upload
                            class="upload-demo"
                            action="https://jsonplaceholder.typicode.com/posts/"
                            :on-change="handleChange"
                            :file-list="ruleForm.fileList">
                            <el-button size="small" type="primary">点击上传</el-button>
                            <div slot="tip" class="el-upload__tip">只能上传jpg/png文件，且不超过500kb</div>
                        </el-upload>
                    </el-form-item> -->
                </el-form>
            </div>
            <template #footer>
                <span class="dialog-footer">
                    <el-button @click="resetForm" v-if="!single">重 置</el-button>
                    <el-button @click="dialogVisible = false" v-else>取 消</el-button>
                    <el-button type="primary" @click="submitForm('ruleForm')">确 定</el-button>
                </span>
            </template>
        </el-dialog>
    </div>
</template>

<script>
import {apiGetgetForecastReportList, apiGetaddForecastReport, apiGetupdateForecastReport, apiGetStation,
apiGetdeleteForecastReport} from '../../api/api'
export default {
    data() {
        return {
            title:'',
            windframtableData:[],
            windframradio: {},
            single: false,
            multiple: false,
            isCopy: false,
            dialogVisible:false,
            regionaWh: '',
            typeWh: '',
            regionaloptions:[],
            typeoptions: [],
            page:{
                pagesize: 10,
                currentPage: 1,
                total: 0
            },
            ruleForm: {
                station: '',
                type: '',
                // picker: '',
                // fileList: []
            },
            rules: {
                station: [
                    { required: true, message: '请选择场站', trigger: 'change' }
                ],
                type: [
                    { required: true, message: '请选择类型', trigger: 'change' }
                ]
            }
        }
    },
    created() {
        this.typeoptions = [
            {
                label: '短期功率',
                value: 1
            },
            {
                label: '超短期功率',
                value: 2
            },
            {
                label: '理论超短期功率',
                value: 3
            },
            {
                label: '气象站数据',
                value: 4
            }
        ]
    },
    mounted() {
        this.getWindplantList()
        this.getRegionalData()
    },
    methods:{
        getSeachData() {
            this.page.currentPage = 1
            this.getWindplantList('seach')
        },
        showType(val) {
            let str = ''
            if (val) {
                this.typeoptions.forEach(item =>{
                    if (item.value === val) {
                        str = item.label
                    }
                })
            }
            return str
        },
        reset() {
            this.regionaWh = ''
            this.typeWh = ''
            this.page = {
                pagesize: 10,
                currentPage: 1,
                total: 0
            }
            this.getWindplantList()
        },
        handleSizeChange(val){
            this.page.pagesize = val
            // this.getWindplantList()
        },
        handleCurrentChange(val){
            this.page.currentPage =val
            // this.getWindplantList()
        },
        handleChange(file, fileList) {
            this.ruleForm.fileList = fileList.slice(-3);
        },
        closeDialog() {
            this.$refs['ruleForm'].clearValidate()
        },
        submitForm(formName) {
            this.$refs[formName].validate((valid) => {
                if (valid) {
                    let that = this
                    that.addOrUpdatewindframDate()
                }
            });
        },
        uploadMsg(row) {
            let that = this
            that.single = true
            let params = {
                terminalNo: row.terminalNo,
                terminalType: row.terminalType,
                reportTag: 1
            }
            apiGetupdateForecastReport(params).then(datas =>{
                if (datas.msg === '操作成功') {
                    that.$message({
                        message: '重新上报成功',
                        type: 'success'
                    });
                    that.single = false
                    that.getWindplantList('seach')
                }
            })
        },
        // 新增/修改风电场配置
        addOrUpdatewindframDate() {
            let that = this
            let params = {
                terminalNo: that.ruleForm.station,
                terminalType: that.ruleForm.type
            }
            if (!that.single) {
                apiGetaddForecastReport(params).then(datas =>{
                    that.changeshowData(datas)
                })
            } else {
                apiGetupdateForecastReport(params).then(datas =>{
                    that.changeshowData(datas)
                })
            }
        },
        changeshowData(datas) {
            if (datas.msg === '操作成功') {
                this.dialogVisible = false
                if (!this.single) {
                    this.$message({
                        message: '预测上报新增成功',
                        type: 'success'
                    });
                } else {
                    this.$message({
                        message: '预测上报修改成功',
                        type: 'success'
                    });
                }
                this.single = false
                this.getWindplantList('seach')
            }
        },
        resetForm() {
            this.ruleForm = {
                station: '',
                type: ''
            }
        },
        // 新增区域信息
        handleAdd() {
            this.dialogVisible = true
            this.single = false
            this.title = '新增预测上报'
            this.$nextTick(() =>{
                this.resetForm()
                this.$refs['ruleForm'].clearValidate()
            })
        },
        // 获取风场数据
        getRegionalData() {
            let that = this
            apiGetStation().then(datas =>{
                if (datas && datas.data && datas.data.list) {
                    that.regionaloptions = datas.data.list
                }
            })
        },
        // 修改区域信息
        handleUpdate() {
            this.dialogVisible = true
            this.single = true
            this.title = '修改预测上报'
            this.ruleForm = {
                station: this.windframradio.terminalNo,
                type: this.windframradio.terminalType,
            }
        },
        rowClick(row, column, event) {
            this.windframradio = row
        },
        handleReport() {},
        // 删除区域信息
        handleDelete() {
            this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                let that = this
                let params = {
                    terminalNo: that.windframradio.terminalNo,
                    terminalType: that.windframradio.terminalNo
                }
                apiGetdeleteForecastReport(params).then(datas =>{
                    if (datas.msg === '操作成功') {
                        that.getWindplantList()
                    }
                })
                if (that.windframtableData.length>0) {
                    that.windframradio = that.windframtableData[0]
                }
                that.$message({
                    type: 'success',
                    message: '删除成功!'
                });
            })
        },
        //获取风电场列表数据
        getWindplantList(type) {
            let that = this
            let params = {}
            if (type) {
                params = {
                    terminalNo: that.regionaWh,
                    terminalType: that.typeWh
                }
            }
            apiGetgetForecastReportList(params).then(datas =>{
                if (datas && datas.rows) {
                    that.windframtableData = datas.rows
                    that.windframradio = datas.rows[0]
                    that.page.total = datas.total
                }
            })
        }
    }
}
</script>

<style lang="less">
.windframconfig{
  .windframBtn{
      background: #fff;
      padding: 10px 20px 0 20px;
      .titleSty{
          border-left: 4px solid #2996da;
          padding-left: 5px;
          font-size: 14px;
          margin-left:20px;
      }
      .periodSeach{
          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;
                        }
                    }
                }
            }
      }
      span{
          font-size:14px;
      }
      .regionalBtn{
          padding-left: 10px;
      }

      .exceed{
          display: flex;
          margin-right:20px;
          .exTime{
              width: 240px;
              .el-select__tags{
                  left: 1px;
                  background:#fff;
              }
          }
      }
      .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;
          }
      }
  }
  .windframTableData{
    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;
          }
      }
      .windframFrom{
          .el-select{
              width: 100%;
          }
      }
  }
}
</style>