<template>
    <div class="evaluationCombination">
        <div class="evaluationCombinationBtn">
            <div class="collectSeach" :style="$utils.collectSeachSty()">
                <div class="exceed">
                    <span class="exceedSpan">组合名称：</span>
                    <el-input v-model="combinationS" placeholder="请输入组合名称"></el-input>
                </div>
                <seachs @handleSeach="getSeachData" @handleRest="resetSeach"></seachs>
            </div>
            <div class="PeriodBtn" :style="$utils.PeriodBtnSty()">
                <btns
                :showImport="false"
                :showExport="false"
                :showAdd="$utils.havePurview('multiSequence:oneLevel:add')"
                :showSave="$utils.havePurview('multiSequence:oneLevel:save')"
                :showDelete="$utils.havePurview('multiSequence:oneLevel:delete')"
                :disSave="changeDateSelect.length === 0 || changeDateSelect.length>1"
                :disDelete="changeDateSelect.length === 0"
                :disImport="true"
                :disExport="true"
                @handleAdd="handleAdd"
                @handleEdit="handleEdit"
                @handleDelete="handleDelete"
                ></btns>
            </div>
            <div class="evaluationCombinationDataC">
                <el-table :data="evaluationCombinationData" style="width: 100%" :class="multisequenceTableSty()"
                 @select="rowClick" @select-all="rowClick">
                    <el-table-column type="selection" label="操作" align="center"></el-table-column>
                    <el-table-column label="组合名称" prop="citeCalculationName" />
                    <el-table-column label="所属板块" prop="binSectionName" />
                    <el-table-column label="指标名称" prop="indicatorNames" />
                    <el-table-column label="排序" prop="orderNum" />
                </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>
            <el-dialog :title="title" v-model="dialogVisible" width="600px" :close-on-click-modal="false">
                <div class="periodFrom">
                    <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm" :validate-on-rule-change="false">
                        <el-form-item label="组合名称" prop="combination">
                            <el-input v-model="ruleForm.combination" placeholder="请输入组合名称"></el-input>
                        </el-form-item>
                        <el-form-item label="业务属性" prop="sectionName">
                            <el-select v-model="ruleForm.sectionName" placeholder="请选择业务属性" @change="changeIndicItem">
                                <el-option
                                v-for="item in binSectionOptions"
                                :key="item.id"
                                :label="item.sectionName"
                                :value="item.id">
                                </el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="指标名称" prop="indicItemName">
                            <el-select v-model="ruleForm.indicItemName" multiple collapse-tags placeholder="请选择指标名称">
                                <el-option
                                v-for="item in indicItemoptions"
                                :key="item.id"
                                :label="item.indicatorName"
                                :value="item.id">
                                </el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="排序">
                            <el-input-number v-model="ruleForm.serialNumber" :min="1" />
                        </el-form-item>
                        <!-- <el-form-item label="描述" prop="desc">
                            <el-input v-model="ruleForm.desc" :rows="5" type="textarea" placeholder="请输入描述"></el-input>
                        </el-form-item> -->
                    </el-form>
                </div>
                <template #footer>
                    <span class="dialog-footer">
                        <el-button @click="dialogVisible = false">取 消</el-button>
                        <el-button type="primary" @click="saveevaluationPersonMsg('ruleForm')">确 定</el-button>
                    </span>
                </template>
            </el-dialog>
        </div>
    </div>
</template>

<script>
import btns from '../elbuttonS.vue'
import seachs from '../seachGroup.vue'
import {apiGetcitecalculationList, apiPostcitecalculationSave, apiPostcitecalculationRemove,
 apiGetbinsectionList, apiGetindicatorListAll} from '../../api/api'
export default {
  components: { btns, seachs },
    data() {
        return {
            dialogVisible: false,
            title: '',
            isSave: false,
            changeDateSelect: [],
            combinationS: '',
            evaluationCombinationData:[],
            ruleForm: {
                combination: '',
                sectionName: '',
                indicItemName: [],
                serialNumber: 1,
                desc: ''
            },
            rules: {
                combination: [
                    { required: true, message: '请输入组合名称', trigger: 'blur' }
                ],
                sectionName: [
                    { required: true, message: '请选择业务属性', trigger: 'change' }
                ],
                indicItemName: [
                    { required: true, message: '请选择指标名称', trigger: 'change' }
                ],
                desc: [
                    { required: true, message: '请输入描述', trigger: 'blur' }
                ],
            },
            page:{
                pagesize: 12,
                currentPage: 1,
                total: 0
            },
            evalradio: {},

            binSectionOptions: [],
            indicItemoptions: [],
            winPix: window.devicePixelRatio,
            innerWidth: window.innerWidth
        }
    },
    created() {
        this.getcitecalculationData()
        this.getDataBinSection()
    },
    methods:{
        // 查询人员配置数据
        getcitecalculationData() {
            let that = this
            let params = {
                pageNum: that.page.currentPage,
                pageSize: that.page.pagesize,
                // personnelName: that.combinationS
            }
            apiGetcitecalculationList(params).then(datas =>{
                if (datas && datas.data) {
                    that.evaluationCombinationData = datas.data.records
                    that.page.total = datas.data.total
                }
            })
        },
        // 查询属性
        getDataBinSection() {
            let that = this
            let params = {
                type: '1'
            }
            apiGetbinsectionList().then(datas =>{
                if (datas && datas.data) {
                    that.binSectionOptions = datas.data
                }
            })
        },
        changeIndicItem(val) {
            this.getIndListAll(val)
        },
        //查询指标
        getIndListAll(id) {
            let that = this
            let params = {
                binSection: id
            }
            apiGetindicatorListAll(params).then(datas =>{
                if (datas && datas.data) {
                    that.indicItemoptions = datas.data
                }
            })
        },
        handleAdd() {
            this.dialogVisible = true
            this.isSave = false
            this.title = '新增多序列计算指标'
            this.$nextTick(() =>{
                this.ruleForm = {
                    combination: '',
                    sectionName: '',
                    indicItemName: [],
                    serialNumber: 1,
                }
            })
        },
        handleEdit() {
            this.dialogVisible = true
            this.isSave = true
            this.title = '修改多序列计算指标'
            this.evalradio = this.changeDateSelect[0]
            this.ruleForm = {
                combination: this.evalradio.combination,
                sectionName: this.evalradio.binSection,
                indicItemName: this.evalradio.indicatorIds.spilt(','),
                serialNumber: this.evalradio.serialNumber
            }
        },
        saveevaluationPersonMsg(formName) {
            let that = this
            that.$refs[formName].validate((valid) => {
                if (valid) {
                    that.saveAndEditIndicatorData()
                }
            });
        },
        //新增/修改指标数据
        saveAndEditIndicatorData() {
            let that = this
            let indNames = []
            that.ruleForm.indicItemName.forEach(iv =>{
                that.indicItemoptions.forEach(it =>{
                    if (iv === it.id) {
                        indNames.push(it.indicatorName)
                    }
                })
            })
            let params = {
                citeCalculationName: that.ruleForm.combination,
                binSection: that.ruleForm.sectionName,
                indicatorNames: indNames.join(','),
                indicatorIds: that.ruleForm.indicItemName.join(','),
                orderNum: that.ruleForm.serialNumber
            }
            if (that.isSave) {
                params.id = that.evalradio.id
            }
            apiPostcitecalculationSave(params).then(datas =>{
                if (!datas.success) {
                    that.$message({
                        message: datas.message,
                        type: 'error'
                    });
                } else {
                    if (!that.isSave) {
                        that.$message({
                            message: '多序列计算指标新增成功',
                            type: 'success'
                        });
                    } else {
                        that.$message({
                            message: '多序列计算指标修改成功',
                            type: 'success'
                        });
                    }
                    that.dialogVisible = false
                    that.changeDateSelect = []
                    that.getcitecalculationData()
                }
            })
        },
        //删除指标数据
        handleDelete() {
            this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                let that = this
                let paramsArr = []
                that.changeDateSelect.forEach(it =>{
                    paramsArr.push(it.id)
                })
                apiPostcitecalculationRemove(paramsArr.join(',')).then(datas =>{
                    if (datas) {
                        that.$message({
                            type: 'success',
                            message: '删除成功!'
                        });
                        that.changeDateSelect = []
                        that.getcitecalculationData()
                    }
                })
            })
        },        
        rowClick(selection, row) {
            this.changeDateSelect = selection
        },
        getSeachData() {
            this.page.currentPage = 1
            this.getcitecalculationData()
        },
        resetSeach() {
            this.page.currentPage = 1
            this.combinationS = ''
            this.getcitecalculationData()
        },
        handleSizeChange(val){
            this.page.pagesize = val
            this.getcitecalculationData()
        },
        handleCurrentChange(val){
            this.page.currentPage =val
            this.getcitecalculationData()
        },
        multisequenceTableSty() {
            if (this.winPix === 1.25 || this.innerWidth < 1800) {
                return 'multisequence125Table'
            } else {
                return 'multisequence100Table'
            }
        }
    }
}
</script>

<style lang="less">
.evaluationCombination{
  .evaluationCombinationBtn{
        .collectSeach{
            display: flex;
            padding: 24px 20px;
            border-bottom: 1px solid#D6DBEA;
                .exceed{
                    display: flex;
                    .exceedSpan{
                        width: 100px;
                        height: 12px;
                        font-size: 14px;
                        font-family: Microsoft YaHei;
                        font-weight: 400;
                        color: #8991B0;
                        line-height: 12px;
                        margin-top: 14px;
                    }
                    .el-input{
                        margin-right:10px;
                        .el-input__inner{
                            height:30px;
                        }
                        .el-input__suffix{
                            .el-select__caret{
                                line-height:30px;
                            }
                        }
                    }
                }
                .el-select{
                    margin-right:10px;
                    .el-input__inner{
                        height:30px;
                    }
                    .el-input__suffix{
                        .el-select__caret{
                            line-height:30px;
                        }
                    }
                }
        }
        span{
            font-size:14px;
        }
        .PeriodBtn{
            display: flex;
            justify-content: flex-end;
            padding: 20px 0;
        }
        .el-button{
            height: 30px;
            // width:100px;
            padding: 0 30px ;
            // padding-top: 8px;
            span{
                margin:0;
            }
        }
        .el-overlay{
            .el-dialog{
                .el-dialog__body{
                    padding: 30px 60px 30px 20px !important;
                    .periodFrom{
                        .el-select, .el-input{
                            width: 100%;
                        }
                        .el-input{
                            height: 30px;
                        }
                    }
                }
            }
        }
    }
  .evaluationCombinationDataC{
      .multisequence125Table{
          .el-table__body-wrapper{
              height: 53vh !important;
          }
      }
      .multisequence100Table{
          .el-table__body-wrapper{
              height: 60vh !important;
          }
      }
    .el-table{
        .el-input__inner{
            height: 30px !important;
        }
        .el-radio__label{
            display: none;
        }
        
        .indicitem{
            color: #409EFF;
            font-size: 12px;
            margin-right: 20px;
            cursor:pointer;
            &:hover{
                text-decoration: underline;
            }
        }
    }
    .el-pagination{
        margin-top: 20px;
        text-align: end;
        position: relative;
    }
    }
    
}
</style>