<template>
    <div id="limit" class="card">
        <date @change="onChangeDate" :showRight="true" @rightAction="onRightAction"></date>
        <div class="info">
            <div class="txt txt2 pointer" @click="onShowTableDialog(1)">
                <span>立改总数</span>
                <span>{{immediate}}</span>
            </div>
            <div class="txt txt1 pointer" @click="onShowTableDialog(2)">
                <span>限改总数</span>
                <span>{{limit}}</span>
            </div>
        </div>
        <div class="card-mt15" :style="barStyle" id="limit-bar"></div>
    </div>
</template>

<script>
import Date from './Date.vue';
import { showLimit } from '../config/bar';
import { getCorrect } from '@/api/home';
import homeMixin from '@/mixin/home';

export default {
    components: {
        Date,
    },
    mixins: [homeMixin],
    data () {
        return {
            immediate: 56152,
            limit: 56152,
            dateRange: [],
            jobType: '',
            barHeight: 100,
        }
    },
    computed: {
        barStyle() {
            return {
                height: `${this.barHeight}px`,
                maxHeight: `${this.barHeight}px`,
            }
        }
    },
    methods: {
        onChangeDate(range) {
            this.dateRange = range;
            this.loadData();
            const vm = this;
            window.onresize = function() {
                vm.resize();
            };
            this.resize();
        },
        resize() {
            const e = document.querySelector('#limit');
            let h = 150;
            if (document.body.clientWidth < 1700) {
                h = 130;
            }
            if (document.body.clientWidth < 1400) {
                h = 100;
            }
            this.barHeight = e.clientHeight - h;
        },
        onRightAction(data) {
            this.jobType = data || '';
            this.loadData();
        },
        loadData() {
            let start = '', end = '';
            if (this.dateRange && this.dateRange.length > 1) {
                start = this.dateRange[0];
                end = this.dateRange[1];
            }
            getCorrect({
                start_date: start,
                end_date: end,
                enforce_org_id: this.orgId,
                job_type: this.jobType,
            }).then(res => {
                let lg = 0, xg = 0;
                if (res && res.data) {
                    let list = [];
                    let lgNum = 0, xgNum = 0;
                    res.data.map(item => {
                        lgNum = parseInt(item.immediately_num);
                        xgNum = parseInt(item.deadline_num);
                        list.push([item.enforce_org_name, lgNum, xgNum]);
                        lg += lgNum;
                        xg += xgNum;
                    });
                    showLimit('limit-bar', list);
                }
                this.immediate = lg;
                this.limit = xg;
            });
        },
        onShowTableDialog(type) {
            this.$emit('table-action', this.dateRange, type == 1);
        },
    }
}
</script>

<style lang="scss" scoped>
.card {
    background: #FFFFFF;
    border: 1px solid #E9EAF8;
    border-radius: 4px;
    padding: 10px;
}
.info {
    margin-top: 25px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    .txt {
        width: 175px;
        height: 50px;
        line-height: 50px;
        border-radius: 4px;
        display: flex;
        justify-content: space-between;
        align-items: center;
        &>span:first-child {
            margin-left: 20px;
            color: #333333;
            font-size: 14px;
            font-weight: 400;
        }
        &>span:last-child {
            margin-right: 20px;
            font-size: 26px;
            font-family: 'FZZongYi-M05S';
            font-weight: bold;
        }
    }
    .txt1 {
        margin-left: 10px;
        background: #FFF4F2;
        border: 1px dashed #EB623B;
        &>span:last-child {
            color: #FF8162;
        }
    }
    .txt2 {
        background: #EEF4FF;
        border: 1px dashed #437CDD;
        &>span:last-child {
            color: #1F5FCD;
        }
    }
}
@media screen and (min-width: 1608px) {
    .card {
        margin-left: 10px;
        margin-top: 10px;
    }
    .info {
        margin-top: 15px;
        .txt1 {
            margin-left: 10px;
        }
        .txt {
            &>span:first-child {
                margin-left: 20px;
                font-size: 14px;
            }
            &>span:last-child {
                margin-right: 20px;
                font-size: 26px;
            }
        }
    }
}
@media screen and (max-width: 1600px) {
    .card {
        margin-left: 7px;
        margin-top: 5px;
    }
    .info {
        margin-top: 10px;
        .txt1 {
            margin-left: 7px;
        }
        .txt {
            &>span:first-child {
                margin-left: 16px;
                font-size: 14px;
            }
            &>span:last-child {
                margin-right: 16px;
                font-size: 26px;
            }
        }
    }
}
@media screen and (max-width: 1300px) {
    .card {
        margin-left: 4px;
        margin-top: 5px;
    }
    .info {
        margin-top: 5px;
        .txt1 {
            margin-left: 4px;
        }
        .txt {
            &>span:first-child {
                margin-left: 12px;
                font-size: 14px;
            }
            &>span:last-child {
                margin-right: 12px;
                font-size: 26px;
            }
        }
    }
}
@import '@/styles/home.scss';
</style>