<template>
    <div class="card">
        <date @change="onChangeDate"></date>
        <div class="info">
            <template v-for="(item, index) in list">
                <div :key="item.id" class="item">
                    <el-image class="item-icon" :src="item.icon"></el-image>
                    <div class="column">
                        <div class="row" :class="item.color">
                            <span class="row-title" :style="`font-size: ${fontSize}px;`">{{item.num}}</span>
                            <span class="row-num">个</span>
                        </div>
                        <div class="row">
                            <span class="row-name">{{item.name}}</span>
                        </div>
                    </div>
                </div>
                <el-divider v-if="index < list.length - 1" :key="index" direction="vertical"></el-divider>
            </template>
        </div>
    </div>
</template>

<script>
import Date from './Date.vue';

import { getInfoTotal } from '@/api/home';

import homeMixin from '@/mixin/home';

export default {
    components: {
        Date,
    },
    mixins: [homeMixin],
    data () {
        return {
            list: [
                {
                    id: '10',
                    name: '全部单位',
                    num: 0,
                    icon: require('@/assets/home/menu1.png'),
                    color: 'num-blue',
                },
                {
                    id: "20",
                    name: '执法人员数',
                    num: 0,
                    icon: require('@/assets/home/menu2.png'),
                    color: 'num-green',
                },
                {
                    id: '30',
                    name: '不合格单位数',
                    num: 0,
                    icon: require('@/assets/home/menu3.png'),
                    color: 'num-red',
                },
                {
                    id: '40',
                    name: '任务总数',
                    num: 0,
                    icon: require('@/assets/home/menu4.png'),
                    color: 'num-yellow',
                }
            ],
            dateRange: [],
        }
    },
    computed: {
        fontSize() {
            let size = 28;
            const clientWidth = window.innerWidth || document.documentElement.clientWidth|| document.body.clientWidth;
            if (clientWidth) {
                size = clientWidth / 1920 * size;
            }
            return size;
        },
    },
    methods: {
        onChangeDate(range) {
            this.dateRange = range;
            this.loadData();
        },
        loadData() {
            let start = '', end = '';
            if (this.dateRange && this.dateRange.length > 1) {
                start = this.dateRange[0];
                end = this.dateRange[1];
            }
            getInfoTotal({
                start_date: start,
                end_date: end,
                enforce_org_id: this.orgId,
            }).then(res => {
                if (res && res.data) {
                    this.list[0].num = res.data.enforce_obj_num;
                    this.list[1].num = res.data.enforce_person_num;
                    this.list[2].num = res.data.un_pass_enforce_obj_num;
                    this.list[3].num = res.data.job_num;
                }
            });
        }
    }
}
</script>

<style lang="scss">
.info {
    .el-divider--vertical {
        height: 74px;
    }
}
</style>

<style lang="scss" scoped>
.card {
    background: #FFFFFF;
    border: 1px solid #E9EAF8;
    border-radius: 4px;
    padding: 10px;
}
.info {
    margin-top: 15px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    .item {
        display: flex;
        align-items: center;
        .column {
            display: flex;
            flex-direction: column;
            margin-left: 8px;
        }
        .row {
            display: flex;
            justify-content: space-between;
            &-title {
                font-size: 28px;
                font-family: 'Microsoft YaHei';
                font-weight: bold;
            }
            &-num {
                font-size: 14px;
                font-weight: 400;
                margin-top: 11px;
                margin-left: 10px;
            }
            &-name {
                font-size: 14px;
                font-weight: 400;
                color: #333333;
            }
        }
    }
}
.num-blue {
    color: #3A8FEA;
}
.num-green {
    color: #36CFC9;
}
.num-red {
    color: #EA3A3A;
}
.num-yellow {
    color: #F09A33;
}
@media screen and (min-width: 1608px) {
    .card {
        margin-left: 10px;
    }
    .info {
        margin-top: 15px;
        .item-icon {
            width: 66px;
        }
        .row-title {
            font-size: 28px;
        }
    }
}
@media screen and (max-width: 1600px) {
    .card {
        margin-left: 7px;
    }
    .info {
        margin-top: 10px;
        .item-icon {
            width: 50px;
        }
        .row-title {
            font-size: 24px;
        }
    }
}
@media screen and (max-width: 1300px) {
    .card {
        margin-left: 4px;
    }
    .info {
        margin-top: 5px;
        .item-icon {
            width: 44px;
        }
        .row-title {
            font-size: 20px;
        }
    }
}
@import '@/styles/home.scss';
</style>