<template>

    <view class="result-card">
        <view class="flex align-center justify-between">
            <view class="cup mr-8">🏆</view>
            <view>
                <view>
                    <text class="recommend mr-4">推荐方案:</text>
                    <text class="plan">集中回收模式（大型中心）</text>
                </view>

                <view class="comprehensive">
                    <!-- <text class="mr-4">综合得分：</text>
                    <text class="total">{{ result.total }} 分</text> -->

                    <view class="star-box">
                        <view class="star-item" v-for="i in 5" :key="i">
                            <text class="star-gray">★</text>
                            <text class="star-yellow" :style="{ width: getStarWidth(i) }">★</text>
                        </view>
                    </view>
                </view>
            </view>
        </view>

        <view>
            <view class="wave-circle">
                <view class="water" :style="{ height: `${result.total}%` }">
                    <view class="wave wave1"></view>
                    <view class="wave wave2"></view>
                </view>
                <view class="score">
                    {{ result.total }}
                </view>
            </view>
        </view>
    </view>

    <view class="result-card">
        <view style="width: 100%;">
            <view class="title"> <text class="dot"></text>评估结果区 （多元价值评分）</view>
            <view class="flex justify-between align-center">
                <view>
                    <view class="big-score">{{ result.total }}</view>
                    <view class="level">（良好）</view>
                </view>

                <view class="star-box">
                    <view class="star-item" v-for="i in 5" :key="i">
                        <text class="star-gray">★</text>
                        <text class="star-yellow" :style="{ width: getStarWidth(i) }">★</text>
                    </view>
                </view>
            </view>

            <view v-for="item in result.scoreCards" :key="item.label" class="score-card">
                <view class="flex justify-between align-center">
                    <view class="card-title">{{ item.label }}</view>
                    <view class="score-num" :style="{ color: item.color }">
                        {{ item.value }}
                    </view>
                </view>
                <uv-line-progress :percentage="item.value" activeColor="#006569"></uv-line-progress>
            </view>

            <view class="desc-box">
                <view class="card-title">评价等级说明</view>
                <text>90-100：优秀（ <text class="stars">★★★★★</text> ）</text>
                <text>75-89：良好（ <text class="stars">★★★★</text> ）</text>
                <text>60-74：一般（ <text class="stars">★★★</text> ）</text>
                <text>0-59：较差（ <text class="stars">★★</text> ）</text>
            </view>
        </view>
    </view>

    <view class="result-card">
        <view style="width: 100%;">
            <view class="title"> <text class="dot"></text>模式对比区 （不同回收模式综合对比）</view>
            <!-- 横向滚动包裹层 -->
            <scroll-view class="table-scroll" scroll-x="true" :show-scrollbar="false">
                <!-- 固定宽度，实现超长横向滚动 -->
                <view class="uni-table-container">
                    <view class="uni-table">
                        <view class="table-tr table-th">
                            <view class="table-td" style="width:50rpx">评价维度</view>
                            <view class="table-td" style="width:100rpx">集中回收模式<br />（大型中心）</view>
                            <view class="table-td" style="width:100rpx">分散回收模式<br />（多个小型站点）</view>
                            <view class="table-td" style="width:200rpx">对比结果</view>
                        </view>
                        <view class="table-tr" v-for="(row, idx) in modeTable" :key="idx">
                            <view class="table-td" style="width:50rpx">{{ row.dimension }} <br />{{ row.desc }}</view>
                            <view class="table-td" style="width:100rpx">
                                <view class="mode-score green">{{ row.centralScore }}</view>
                                <view class="mode-desc">{{ row.centralDesc }}</view>
                            </view>
                            <view class="table-td" style="width:100rpx">
                                <view class="mode-score blue">{{ row.distributedScore }}</view>
                                <view class="mode-desc">{{ row.distributedDesc }}</view>
                            </view>
                            <view class="table-td" style="width:100rpx">
                                <span class="good">☑ {{ row.result }}</span>
                            </view>
                        </view>
                    </view>
                </view>
            </scroll-view>

            <view class="summary-row">
                <view>综合得分（加权）</view>
                <view class="central">79.1</view>
                <view class="distributed">74.2</view>
                <view class="final-result">集中回收模式更优 👍</view>
            </view>
        </view>
    </view>

    <view class="result-card">
        <view style="width: 100%;">

            <view class="title"> <text class="dot"></text> 推荐结论区 （系统推荐与说明）</view>
            <view class="desc-box">
                <h4>推荐理由：</h4>
                <text>1. 经济效益更高：规模化运营降低单位处理成本，综合成本优势明显；</text><br />
                <text>2. 资源利用效率更高：集中处理有利于提高资源回收率和再生利用水平；</text><br />
                <text>3. 管理效率更优：集中监管与运营，便于规范管理与风险控制。</text>
            </view>

            <view class="desc-box">
                <h4>建议措施：</h4>
                <text>✓ 加强运输过程的风险管控与环保措施</text><br />
                <text>✓ 优化回收中心布局，合理覆盖服务区域</text><br />
                <text>✓ 推动技术升级，提高资源化利用效率</text>
            </view>
        </view>

    </view>
</template>

<script setup>
import { onMounted } from 'vue';
import { ref } from "vue";

const result = ref()

// 表格数据
const modeTable = [
    {
        dimension: '经济价值',
        desc: '（成本/收益）',
        centralScore: 80.1,
        centralDesc: '成本较低，规模效益明显',
        distributedScore: 63.2,
        distributedDesc: '建设与运营成本较高',
        result: '集中回收更优'
    },
    {
        dimension: '环境价值',
        desc: '（污染/生态）',
        centralScore: 72.4,
        centralDesc: '运输距离较长，排放略高',
        distributedScore: 85.6,
        distributedDesc: '就近处理，环境影响较小',
        result: '分散回收更优'
    },
    {
        dimension: '社会价值',
        desc: '（安全/就业）',
        centralScore: 76.3,
        centralDesc: '管理集中，就业带动中等',
        distributedScore: 78.7,
        distributedDesc: '就近服务，就业带动较好',
        result: '分散回收更优'
    },
    {
        dimension: '资源价值',
        desc: '（再生利用）',
        centralScore: 83.2,
        centralDesc: '资源集中，利用效率高',
        distributedScore: 75.1,
        distributedDesc: '资源分散，利用效率一般',
        result: '集中回收更优'
    }
]

onMounted(() => {
    const res = uni.getStorageSync('app_integratedModeAssessment_result')
    if (res) result.value = res
})

// 半星计算 保留原有
const getStarWidth = (index) => {
    const score = Number(result.value?.total || 0)
    const perStar = 20
    const current = index * perStar
    const prev = (index - 1) * perStar

    if (score >= current) return '100%'
    if (score > prev) return `${((score - prev) / perStar) * 100}%`
    return '0%'
}
</script>

<style lang="scss" scss>
$gw-green: #006569;
$gw-light: #409E99;
$gw-bg: #e8f2f1;

/* 标题小圆点 */
.dot {
    width: 12rpx;
    height: 12rpx;
    background-color: $gw-green;
    // border-radius: 50%;
    display: inline-block;
    margin-right: 12rpx;
}

.result-card {
    margin: 20rpx;
    background-color: #fff;
    padding: 20rpx;
    border-radius: 32rpx;
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16rpx;
}

.wave-circle {
    width: 80rpx;
    height: 80rpx;
    border-radius: 50%;
    background-color: #f5f7f9;
    overflow: hidden;
    position: relative;
    border: 1rpx solid #eee;
}

.water {
    position: absolute;
    left: 0;
    bottom: 0;
    width: 100%;
    background: linear-gradient(360deg, $gw-green 0%, $gw-light 100%);
    transition: height 0.8s ease;
}

.wave {
    width: 200%;
    height: 24rpx;
    position: absolute;
    top: -12rpx;
    left: -50%;
    background: $gw-bg;
    border-radius: 50%;
    opacity: 0.8;
}

.wave1 {
    animation: wave-animate 4s linear infinite;
}

.wave2 {
    animation: wave-animate 6s linear infinite reverse;
    opacity: 0.5;
    top: -18rpx;
}

.score {
    position: absolute;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16rpx;
    font-weight: bold;
    color: #fff;
    z-index: 99;
}

@keyframes wave-animate {
    0% {
        transform: translateX(0);
    }

    100% {
        transform: translateX(50%);
    }
}

.cup {
    font-size: 48rpx;
}

.recommend {
    font-size: 14rpx;
    color: $gw-green;
    font-weight: 600;
}

.plan {
    font-size: 16rpx;
    font-weight: 600;
    color: $gw-green;
}

.comprehensive {
    font-size: 14rpx;
    display: flex;
    align-items: center;
    gap: 10rpx;
    margin-top: 20rpx;

    .total {
        font-size: 16rpx;

    }
}

/* 五星精确评分（支持半星） */
.star-box {
    display: flex;
    align-items: center;
}

.star-item {
    position: relative;
    width: 20rpx;
    height: 20rpx;
    line-height: 20rpx;
    margin-right: 4rpx;
}

.star-gray,
.star-yellow {
    position: absolute;
    left: 0;
    top: 0;
    font-size: 20rpx;
}

.star-gray {
    color: #e0e0e0;
    z-index: 1;
}

.star-yellow {
    color: #f7b500;
    z-index: 2;
    overflow: hidden;
    white-space: nowrap;
}

.card-title {
    font-size: 14rpx;
}

.big-score {
    display: inline-block;
    font-size: 32rpx;
    color: #18a84f;
    font-weight: 700;
}

.level {
    display: inline-block;
    color: #18a84f;
    margin-left: 6rpx;
}

.score-num {
    font-size: 24rpx;
    font-weight: 700;
    margin-bottom: 10rpx;
}

.level-card {
    text-align: left;
    line-height: 1.7;
}

/* 说明面板 */
.desc-box {
    background: #f2f9f9;
    border-left: 6rpx solid $gw-green;
    border-radius: 8rpx;
    padding: 10rpx 24rpx;
    font-size: 14px;
    color: #333;
    margin-top: 20rpx;

    h4 {
        margin-bottom: 8rpx;
    }
}

/* =========== 新增 UniApp 表格样式 完全替代el-table =========== */
.uni-table {
    width: 100%;
    border: 1rpx solid #e5e7eb;
    border-radius: 16rpx;
    overflow: hidden;
    margin: 8rpx 0;
}

.table-tr {
    display: flex;
    width: 100%;
}

.table-th {
    background-color: #f5f7fa;
    font-weight: 500;
}

.table-td {
    flex: 1;
    text-align: center;
    font-size: 16rpx;
    padding: 16rpx 8rpx;
    border-right: 1rpx solid #eee;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.table-td:last-child {
    border-right: none;
}

.table-tr:not(.table-th) {
    border-top: 1rpx solid #eee;
}

.mode-score {
    font-size: 14rpx;
    font-weight: bold;
}

.mode-score.green {
    color: $gw-green;
}

.mode-score.blue {
    color: $gw-light;
}

.mode-desc {
    font-size: 12rpx;
    color: #666;
    margin-top: 6rpx;
    line-height: 1.4;
}

.good {
    color: $gw-green;
    font-weight: 500;
}

.summary-row {
    display: flex;
    justify-content: space-around;
    padding: 16rpx;
    background: #f8f9fa;
    border-radius: 12rpx;
    margin-top: 8rpx;
    font-size: 12rpx;
}

.central {
    color: $gw-green;
    font-weight: bold;
}

.distributed {
    color: $gw-light;
    font-weight: bold;
}

.final-result {
    color: $gw-green;
    font-weight: bold;
}

/* 横向滚动表格 */
.table-scroll {
    width: 100%;
}

.uni-table-container {
    width: fit-content;
    /* 最小总宽度，保证可以横向滚动 */
    min-width: 100%;
}

.title {
    margin-bottom: 8rpx;
    font-size: 16rpx;
}

.stars {
    margin-top: 8px;
    color: #f7b500;
    font-size: 12rpx;
}
</style>