<template>
    <div class="evaluationReport">
        <div class="evaluationReportBtn">
            <div class="collectSeach">
                <div class="exceed">
                    <span class="exceedSpan">考评周期：</span>
                    <!-- <el-input v-model="restype" placeholder="请输入业务类别"></el-input> -->
                    <el-select v-model="rescycle" placeholder="请选择考评周期">
                        <el-option
                        v-for="item in periodData"
                        :key="item.keyValue"
                        :label="item.keyName"
                        :value="item.keyValue">
                        </el-option>
                    </el-select>
                </div>
                <div class="exceed">
                    <span class="exceedSpan">业务属性：</span>
                    <!-- <el-input v-model="resDes" placeholder="请输入业务简述"></el-input> -->
                    <el-select v-model="resbinSection" placeholder="请选择业务属性" :disabled="isDetail">
                        <el-option
                        v-for="item in moduleData"
                        :key="item.id"
                        :label="item.sectionName"
                        :value="item.id">
                        </el-option>
                    </el-select>
                </div>
                <el-button type="primary" style="margin-left: 10px;" @click="getSeachData">搜索</el-button>
                <el-button style="margin-left: 10px;" @click="resetSeach">重置</el-button>
            </div>
            <div class="PeriodBtn">
                <btns
                :showImport="false"
                :showExport="false"
                :showSave="false"
                :showAdd="false"
                :showDelete="false"
                :disDelete="changeDateSelect.length === 0"
                @handleExport="exportDataMsg"
                ></btns>
            </div>
            <div class="evaluationReportTableData">
                <el-table :data="evaluationReportData" style="width: 100%" @select="rowClick" @select-all="rowClick" @row-dblclick="getDetail">
                    <el-table-column type="selection" label="操作" align="center"></el-table-column>
                    <el-table-column label="报告名称" prop="evaluateReportName" width="330" />
                    <el-table-column label="业务属性" prop="binSectionName" />
                    <el-table-column label="业务类别">
                        <template #default="scope">
                            <span v-if="scope.row.checkCycle === 'YDKP'" style="font-size: 12px;">月度考评</span>
                            <span v-else-if="scope.row.checkCycle === 'JDKP'" style="font-size: 12px;">季度考评</span>
                            <span v-else style="font-size: 12px;">年度考评</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="年度" prop="year" />
                    <el-table-column label="月度/季度" prop="month" />
                    <el-table-column label="业务简述" prop="des" />
                    <el-table-column label="操作">
                        <template #default="scope">
                            <p class="indicitem" @click="getDetail(scope.row)">详情</p>
                        </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>
        <evaluation-report-table ref="reportTable"></evaluation-report-table>
    </div>
</template>

<script>
import btns from '../elbuttonS.vue'
import ExcelJS from 'exceljs'
import fileSave from 'file-saver'
import evaluationReportTable from './evaluationReportTable.vue'
import {apiGetEvalReportList, apiGetdatadictionaryList, apiGetbinsectionList} from '../../api/api'
export default {
    components: {
        btns,
        evaluationReportTable
    },
    data() {
        return {
            rescycle: '',
            resbinSection: '',
            periodData: [],
            moduleData: [],
            changeDateSelect: [],
            evaluationReportData:[],
            page:{
                pagesize: 12,
                currentPage: 1,
                total: 0
            }
        }
    },
    created() {
        this.getevaluStartList()
        this.getPeriodData()
        this.getBinSectionData()
    },
    methods:{
        // 查询列表页面
        getevaluStartList(type) {
            let that = this
            let params = {
                pageNum: that.page.currentPage,
                pageSize: that.page.pagesize
            }
            if (type) {
                params.responsibilityCode = that.rescode
                params.des = that.resDes
            }
            apiGetEvalReportList(params).then(datas =>{
                if (datas && datas.data) {
                    that.evaluationReportData = datas.data.records
                    that.page.total = datas.data.total
                }
            })
        },
        //考评周期
        getPeriodData() {
            let that = this
            let params = {
                superKey: 'KPZQ0001'
            }
            apiGetdatadictionaryList(params).then(datas =>{
                if (datas && datas.data) {
                    that.periodData = datas.data
                }
            })
        },
        getBinSectionData() {
            let that = this
            apiGetbinsectionList().then(datas =>{
                if (datas && datas.data) {
                    that.moduleData = datas.data
                }
            })
        },
        //明细
        getDetail(row) {
            this.$refs.reportTable.init(row)
        },
        getSeachData() {
            this.page.currentPage = 1
            this.getevaluStartList('seach')
        },
        resetSeach() {
            this.page.currentPage = 1
            this.rescycle = ''
            this.resbinSection = ''
            this.getevaluStartList()
        },
        handleSizeChange(val){
            this.page.pagesize = val
            this.getevaluStartList()
        },
        handleCurrentChange(val){
            this.page.currentPage =val
            this.getevaluStartList()
        },
        rowClick(selection, row) {
            this.changeDateSelect = selection
        },
        exportDataMsg() {
            let data = this.evaluationReportData  //接口返回数据
            let col = [
                { name: '报告名称'},
                { name: '业务属性'},
                { name: '考评周期'},
                { name: '年'},
                { name: '月'}
            ]
            let colEn = ['evaluateReportName', 'binSectionName', 'checkCycle', 'year', 'month']
            let rowData = []
            for(let i =0; i<data.length; i++) {
                let item = data[i]
                let arr = []
                for(let j =0; j<colEn.length; j++) {
                    let it = colEn[j]
                    arr.push(item[it])
                }
                rowData.push(arr)
            }
            const workbook = new ExcelJS.Workbook()
            const worksheet = workbook.addWorksheet('Sheet1')
            //定义表格标题
            const Targetrow = worksheet.getRow(1);
            Targetrow.height = 30;
            const Targetcell = worksheet.getCell(`A1`);
            worksheet.mergeCells(`A1:E1`);
            Targetcell.value = `测试表格`;
            Targetcell.font = { name: "宋体", family: 4, size: 11, bold: true }; // 字体
            Targetcell.alignment = { vertical: "middle", horizontal: "center" }; //对齐
            
            worksheet.columns = [
                { header: '月份', key: 'name', width: 24 },
                { header: '合计', key: 'statistic', width: 24 },
                { header: '一月', key: 'january' },
                { header: '二月', key: 'february' },
                { header: '三月', key: 'march' },
                { header: '四月', key: 'april' },
                { header: '五月', key: 'may' },
                { header: '六月', key: 'june' },
                { header: '七月', key: 'july' },
                { header: '八月', key: 'august' },
                { header: '九月', key: 'september' },
                { header: '十月', key: 'october' },
                { header: '十一月', key: 'november' },
                { header: '十二月', key: 'december' }
            ]
            worksheet.getRow(1).font = {
                size: 12,
                bold: true
            }
            worksheet.addRows(data)
            workbook.xlsx.writeBuffer().then(buffer => {
                //这里为type
                const blob = new Blob([buffer], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=UTF-8' })
                fileSave(blob, `数据导出.xlsx`)
            })
        }
    }
}
</script>

<style lang="less">
.evaluationReport{
    .evaluationReportBtn{
        .collectSeach{
                display: flex;
                padding: 24px 20px;
                border-bottom: 1px solid#D6DBEA;
                .exceed{
                    display: flex;
                    .exceedSpan{
                        width: 80px;
                        height: 12px;
                        font-size: 14px;
                        font-family: Microsoft YaHei;
                        font-weight: 400;
                        color: #8991B0;
                        line-height: 12px;
                        margin-top: 10px;
                    }
                    .el-input{
                        margin-right:10px;
                        height: 40px;
                        .el-input__inner{
                            height:40px;
                        }
                        .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: end;
                padding: 20px 0;
        }
        .el-button{
            height: 30px;
            // width:100px;
            padding: 0 20px ;
            // padding-top: 8px;
            span{
                margin:0;
            }
        }
        .evaluationReportTableData{
            .el-table{
                .el-table__body-wrapper{
                    height: 60vh !important;
                }
                .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;
            }
        }
        .el-overlay{
            .el-dialog{
                .el-dialog__body{
                    padding: 30px 60px 30px 20px !important;
                    .periodFrom{
                        .el-select, .el-input{
                            width: 100%;
                        }
                        .el-input{
                            height: 30px;
                        }
                    }
                }
            }
        }
    }
    
}
</style>