<template>
    <div class="earlyWarningPage">
        <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="earlyWarningMain">
                <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.warningMsg"
                                label="预警内容"
                                placeholder="预警内容"
                                />
                                <van-cell title="选择日期区间" class="calenderSty" :value="form.time" @click="showDatePicker = true" />
                                <van-calendar v-model:show="showDatePicker" type="range" :min-date="minDate" :max-date="maxDate" @confirm="confirmFn" />

                                <div style="margin: 16px;display: flex;justify-content: space-between;">
                                    <div class="seachBtnFrom" @click="getSeach">
                                        <span>搜索</span>
                                    </div>
                                    <div class="restBtnFrom" @click="restSeach">
                                        <span>重置</span>
                                    </div>
                                </div>
                            </van-form>
                        </div>
                    </van-popup>
                </div>
                <div class="mainModel">
                    <el-table :data="evaluationWaringData" style="width: 100%">
                        <el-table-column label="序号" type="index" align="center" />
                        <el-table-column label="考评单位" prop="company" width="200" />
                        <el-table-column label="指标类型" prop="title" width="200" />
                        <el-table-column label="预警内容" prop="content" />
                        <el-table-column label="目标值" prop="targetValue" width="100" />
                        <el-table-column label="完成值" prop="completeValue" width="100" />
                        <el-table-column label="预警时间" prop="createTime" />
                        <el-table-column label="确认人" prop="userName" />
                        <el-table-column label="确认时间" prop="confirmTime" />
                        <el-table-column label="状态" width="100">
                            <template #default="scope">
                                <span class="statusSty"
                                :style="scope.row.isConfirm ? 'background:#61C760':'background:#5093E1'">
                                {{scope.row.isConfirm?'已确认':'未确认'}}
                                </span>
                            </template>
                        </el-table-column>
                    </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 {apiGetevaluationwarninginfoList} from '../api/api'
export default {
    data() {
        return {
            logoImg: logoImg,
            daohangImg: daohangImg,
            dateImg: dateImg,
            sortImg: sortImg,
            seachImg: seachImg,
            showDatePicker: false,
            showVanPopup: false,
            currentDate: [],
            minDate: '',
            maxDate: '',
            form: {
                company: '',
                warningMsg: '',
                time: ''
            },
            evaluationWaringData: [],
        }
    },
    created() {
        this.minDate = new Date(`${new Date().getFullYear()-5}/${new Date().getMonth() + 1}/${new Date().getDate()}`)
        this.maxDate = new Date(`${new Date().getFullYear()+5}/${new Date().getMonth() + 1}/${new Date().getDate()}`)
        this.getevaluationWaringData()        
    },
    methods: {
        // 获取公告数据
        getevaluationWaringData() {
            let that = this
            let params = {
                pageNum: 1,
                pageSize: 100,
                company: that.form.company,
                content: that.form.warningMsg,
                st: that.form.time ? that.form.time.substring(0, that.form.time.indexOf(' - ')) : '',
                et: that.form.time ? that.form.time.substring(that.form.time.indexOf(' - ')+3, that.form.time.length) : ''
            }
            apiGetevaluationwarninginfoList(params).then(datas =>{
                if (datas && datas.data) {
                    that.evaluationWaringData = datas.data.records
                }
            })
        },
        getSeach() {
            this.getevaluationWaringData()
            this.showVanPopup = false
        },
        restSeach() {
            this.form = {
                company: '',
                warningMsg: '',
                time: ''
            }
            this.showVanPopup = false
            this.getevaluationWaringData()
        },
        showPopup() {
            this.showVanPopup = true
        },
        chooseMenu() {
            this.$router.push({ path: "/menu"})
        },
        confirmFn(val) {
            const [start, end] = val;
            this.form.time = `${this.$utils.getNYRTime(start)} / ${this.$utils.getNYRTime(end)}`;
            this.showDatePicker = false
        },
    }
}
</script>

<style lang="less">
.earlyWarningPage {
    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;
                }
            }
        }
        .earlyWarningMain{
            // 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;
                    .calenderSty{
                        .van-cell__title{
                            flex: none;
                            width: 40%;
                        }
                    }
                    .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;
                                    }
                                }
                            }
                        }
                    }
                    .statusSty{
                        width: 52px;
                        height: 21px;
                        line-height: 21px;
                        display: inline-block;
                        border-radius: 3px;
                        color: #fff;
                        padding: 0 0 0 10px;
                    }
                }
            }
        }
    }
}
</style>