<!--
 * @Author: Kane
 * @Date: 2023-03-07 23:22:13
 * @LastEditors: Kane
 * @FilePath: /task_schedule/src/components/ArchievementCompleteRateComponent.vue
 * @Description: 业绩完成率组件
 *
 * Copyright (c) ${2022} by Kane, All Rights Reserved.
-->
<template>
    <div class="complete-rate-wrapper">
        <el-progress
            type="circle"
            :percentage="ui.percentage"
            :status="ui.warningLevel"
        >
            <template #default>
                <span class="percentage-label">{{ ui.indicator }}</span>
                <span :class="warningLevelClass">{{ percentage }}%</span>
            </template>
        </el-progress>
    </div>
</template>

<script lang="ts">
import { reactive, computed } from "vue";
export default {
    name: "ArchievementCompleteRateComponent",
    props: {
        percentage: {
            type: String,
            require: true,
            default: () => "0",
        },
        indicator: {
            type: String,
            default: "",
        },
        warningLevel: { // 警告等级
            type: String,
            default: "success",
        },
    },
    setup( props )
    {
        const percentage = Number( props.percentage ).valueOf();

        const warningLevelClass = computed((): string =>
        {
            let textClass = "";

            if ( props.warningLevel === "success" )
            {
                textClass = "percentage-value";
            }
            else if ( props.warningLevel === "warning" )
            {
                textClass = "percentage-value-warning";
            }
            else if ( props.warningLevel === "exception" )
            {
                textClass = "percentage-value-exception";
            }

            return textClass;
        });

        const ui = reactive({
            percentage,
            indicator: props.indicator,
            warningLevel: props.warningLevel,
        });

        return { ui, warningLevelClass, };
    },
};
</script>

<style lang="scss">
.complete-rate-wrapper {
    // display: flex;
    // flex-direction: column;
    // justify-content: center;
    // align-items: center;

    span {
        display: block;
        width: 100%;
        color: #fff;
    }

    .el-progress {
        margin: 5px;
    }

    .percentage-value {
        display: block;
        margin-top: 10px;
        font-size: 28px;
    }

    .percentage-value-warning {
        display: block;
        margin-top: 10px;
        font-size: 28px;
        color: #e59f46;
    }

    .percentage-value-exception {
        display: block;
        margin-top: 10px;
        font-size: 28px;
        color: red;
        // color: #f3666b;
    }

    .percentage-label {
        display: block;
        margin-top: 10px;
        font-size: 12px;
    }

}
</style>
