<template>
    <div class="reportConpanyPage">
        <van-nav-bar title="单位考评报告" />
        <div class="mobeilVant">
            <div class="mobeilTop">
                <div class="topLeft">
                    <!-- <van-icon name="star" size="20" /> -->
                    <img :src="logoImg" alt="">
                    <span>全业务域考评系统</span>
                </div>
                <div class="topRight">
                    <span>系统导航</span>
                    <!-- <van-icon name="wap-nav"  size="23" /> -->
                    <img :src="daohangImg" alt="" @click="chooseMenu">
                </div>
            </div>
            <div class="reportConpanyMain">
                <div class="mainSeach">
                    <div class="seachFrom" @click="showPopup">
                        <span>搜索栏</span>
                    </div>
                    <van-popup v-model:show="showVanPopup" position="top">
                        <div class="vanForm">
                            <van-form>
                                <van-field
                                v-model="form.company"
                                label="单位名称"
                                placeholder="单位名称"
                                />
                                <van-field
                                    v-model="form.checkCycle"
                                    is-link
                                    readonly
                                    label="考评周期"
                                    placeholder="点击考评周期"
                                    @click="showcheckCycle = true"
                                    />
                                <van-popup v-model:show="showcheckCycle" position="bottom">
                                    <van-picker
                                        :columns="checkCycleSection"
                                        @confirm="selectcheckCycle"
                                        @cancel="showcheckCycle = false"
                                    />
                                </van-popup>
                                <van-field
                                    v-model="form.binSection"
                                    is-link
                                    readonly
                                    label="业务属性"
                                    placeholder="点击业务属性"
                                    @click="showSelect = true"
                                    />
                                <van-popup v-model:show="showSelect" position="bottom">
                                    <van-picker
                                        :columns="columnSection"
                                        :columns-field-names="{
                                            text: 'sectionName',
                                            value: 'id'
                                        }"
                                        @confirm="selectConfirm"
                                        @cancel="showSelect = false"
                                    />
                                </van-popup>
                                <van-field
                                    v-model="form.time"
                                    is-link
                                    readonly
                                    name="datePicker"
                                    label="时间选择"
                                    placeholder="点击选择时间"
                                    @click="showDatePicker = true"
                                    />
                                <van-popup v-model:show="showDatePicker" position="bottom">
                                    <van-date-picker
                                        v-model="datePickerData"
                                        :columns-type="['year', 'month']"
                                        @confirm="confirmFn"
                                        @cancel="cancelpickerFn"
                                        />
                                </van-popup>
                                <div style="margin: 16px;display: flex;justify-content: space-between;">
                                    <div class="seachBtnFrom" @click="seachmobeilReportData">
                                        <span>搜索</span>
                                    </div>
                                    <div class="restBtnFrom" @click="restSeach">
                                        <span>重置</span>
                                    </div>
                                </div>
                            </van-form>
                        </div>
                    </van-popup>
                </div>
                <div class="mainModel">
                    <el-table :data="mobeilReportData" style="width: 100%" @row-click="rowDetail">
                        <el-table-column type="index" label="序号" align="center"></el-table-column>
                        <el-table-column label="报告名称" prop="evaluateReportName" width="330" />
                        <el-table-column label="业务属性" prop="binSectionName" width="150" />
                        <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" align="center" />
                    </el-table>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
import logoImg from '../assets/mobeilImg/logo.png'
import daohangImg from '../assets/mobeilImg/daohang.png'
import dateImg from '../assets/mobeilImg/date.png'
import sortImg from '../assets/mobeilImg/sort.png'
import seachImg from '../assets/mobeilImg/seach.png'
import topImg from '../assets/getwayImg/topNewS.png'
import botImg from '../assets/getwayImg/botNewS.png'
import cenImg from '../assets/getwayImg/cenNew.png'

import {apiGetEvalReportList, apiGetbinsectionList} from '../api/api'
export default {
    data() {
        return {
            logoImg: logoImg,
            daohangImg: daohangImg,
            dateImg: dateImg,
            sortImg: sortImg,
            seachImg: seachImg,
            topImg: topImg,
            botImg: botImg,
            cenImg: cenImg,
            showDatePicker: false,
            showSelect: false,
            showcheckCycle: false,
            showVanPopup: false,
            form: {
                company: '',
                checkCycle: '',
                binSection: '',
                time: ''
            },
            mobeilReportData: [],
            columnSection: [],
            checkCycleSection: [],
            datePickerData: []
        }
    },
    created() {
        this.getReportData()
        this.getBinSectionData()
        this.datePickerData = [new Date().getFullYear(), new Date().getMonth()]
        this.checkCycleSection = [
            { text: '月度考评', value: 'YDKP' },
            { text: '季度考评', value: 'JDKP' },
            { text: '年度考评', value: 'NDKP' }
        ]
    },
    methods: {
        // 获取考评报告数据
        getReportData() {
            let that = this
            that.mobeilReportData = []
            let binSectionStr = ''
            let checkCycleStr = ''
            that.columnSection.forEach(it =>{
                if (it.sectionName === that.form.binSection) {
                    binSectionStr = it.id
                }
            })
            that.checkCycleSection.forEach(it =>{
                if (it.text === that.form.checkCycle) {
                    checkCycleStr = it.value
                }
            })
            let params = {
                pageNum: 1,
                pageSize: 500,
                evaluateReportName: that.form.company,
                binSection: binSectionStr,
                checkCycle: checkCycleStr,
                year: that.datePickerData[0],
                month: that.datePickerData[1]
            }
            apiGetEvalReportList(params).then(datas =>{
                if (datas && datas.data) {
                    that.mobeilReportData = datas.data.records
                }
            })
        },
        getBinSectionData() {
            let that = this
            apiGetbinsectionList().then(datas =>{
                if (datas && datas.data) {
                    that.columnSection = datas.data
                }
            })
        },
        rowDetail(row) {
            let detailObj = JSON.stringify(row)
            this.$router.push({ path: "/reportDetail", query: {row: detailObj}})
        },
        seachmobeilReportData() {
            this.showVanPopup = false
            this.getReportData()
        },
        restSeach() {
            this.form = {
                company: '',
                checkCycle: '',
                binSection: '',
                time: ''
            }
            this.showVanPopup = false
            this.getReportData()
        },
        showPopup() {
            this.showVanPopup = true
        },
        chooseMenu() {
            this.$router.push({ path: "/menu"})
        },
        confirmFn(val) {
            this.form.time = val.selectedValues[0]+'年'+val.selectedValues[1]+'月'
            this.datePickerData = val.selectedValues
            this.cancelpickerFn()
        },
        selectConfirm({selectedOptions}) {
            this.form.binSection =  selectedOptions[0].sectionName
            this.showSelect = false
        },
        selectcheckCycle({selectedOptions}) {
            this.form.checkCycle = selectedOptions[0].text
            this.showcheckCycle = false
        },
        cancelpickerFn() {
            this.showDatePicker = false
        },
    }
}
</script>

<style lang="less">
.reportConpanyPage {
    background-color: #184FB4;
    .van-nav-bar{
        width: 100%;
        background-color: #184FB4;
        color: #fff;
        position: fixed;
        top: 0;
        z-index: 111111;
        .van-nav-bar__content{
            .van-nav-bar__left{
                .van-nav-bar__text{
                    color: #fff;
                }
            }
        }
    }
    .mobeilVant{
        height: 100%;
        margin-top: 45px;
        border-radius: 10px 10px 0 0;
        background-color: #fff;
        .mobeilTop{
            height: 60px;
            display: flex;
            justify-content: space-around;
            .topLeft{
                display: flex;
                img{
                    width: 24px;
                    height: 28px;
                    position: relative;
                    top: 18px;
                    left: -10px;
                }
                span{
                    font-family: MicrosoftYaHei;
                    font-weight: 600;
                    font-size: 16px;
                    color: #444950;
                    line-height: 60px;
                }
            }
            .topRight{
                display: flex;
                img{
                    width: 22px;
                    height: 18px;
                    position: relative;
                    top: 21px;
                    left: 5px;
                }
                span{
                    font-family: MicrosoftYaHei;
                    font-weight: 400;
                    font-size: 14px;
                    color: #545960;
                    line-height: 60px;
                    margin-right: 5px;
                }
            }
        }
        .reportConpanyMain{
            // height: 50px;
            background-color: #ededf5;
            padding: 17px 20px;
            width: calc(100% - 40px);
            .mainSeach{
                display: flex;
                // justify-content: space-between;
                .seachFrom{
                    width: 100%;
                    height: 40px;
                    background: #184FB4;
                    border-radius: 5px;
                    margin-bottom: 15px;
                    text-align: center;
                    span{
                        display: inline-block;
                        color: #fff;
                        line-height: 40px;
                    }
                }
                .vanForm{
                    margin-top: 60px;
                    .seachBtnFrom{
                        width: 65%;
                        height: 40px;
                        background: #184FB4;
                        border-radius: 5px;
                        margin-bottom: 15px;
                        text-align: center;
                        span{
                            display: inline-block;
                            color: #fff;
                            line-height: 40px;
                        }
                    }
                    .restBtnFrom{
                        width: 30%;
                        height: 40px;
                        background: #838DAB;
                        border-radius: 5px;
                        margin-bottom: 15px;
                        text-align: center;
                        span{
                            display: inline-block;
                            color: #fff;
                            line-height: 40px;
                        }
                    }
                }
            }
            .mainModel{
                background: #fff;
                border-radius: 5px;
                padding: 5px 0;
                .el-table{
                    .el-table__header-wrapper{
                        .el-table__header{
                            tr{
                                .cell{
                                    line-height: 18px !important;
                                }
                            }
                        }
                    }
                    .el-table__body-wrapper{
                        .el-table__body{
                            tr{
                                .cell{
                                    img{
                                        width: 20px;
                                        height: 20px;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
</style>