<template>
    <ele-modal
        :model-value="visible"
        title="助力详情"
        width="900px"
        @update:modelValue="updateVisible"
        :footer="null"
    >
        <el-table :data="tableData" border stripe v-loading="loading">
            <el-table-column prop="userId" label="用户ID" align="center" />
            <el-table-column prop="nickName" label="用户昵称" align="center" />
            <el-table-column prop="orderStatus" label="是否下单" align="center">
                <template #default="{ row }">
                    {{ row.orderStatus == 1 ? '是' : '否' }}
                </template>
            </el-table-column>
            <el-table-column
                prop="totalNum"
                label="订单总本数"
                align="center"
                width="120"
            />
            <el-table-column
                prop="totalMoney"
                label="订单总金额"
                align="center"
                width="120"
            />
            <el-table-column
                prop="reduceMoney"
                label="降价金额"
                align="center"
                width="120"
            />
        </el-table>
    </ele-modal>
</template>

<script setup>
    import { ref } from 'vue';
    import { ElMessage } from 'element-plus';
    import request from '@/utils/request';

    const visible = ref(false);
    const loading = ref(false);
    const tableData = ref([]);

    const updateVisible = (val) => {
        visible.value = val;
    };

    const handleOpen = async (data) => {
        visible.value = true;
        loading.value = true;
        tableData.value = [];
        try {
            // 使用 orderId 获取助力详情
            const res = await request.get(
                `/activity/activityReduceInfo/orderHelpList/${data.orderId}`
            );
            if (res.data.code === 200) {
                tableData.value = res.data.data || [];
            } else {
                ElMessage.error(res.data.msg || '获取助力详情失败');
            }
        } catch (error) {
            console.error(error);
            ElMessage.error('获取助力详情失败');
        } finally {
            loading.value = false;
        }
    };

    defineExpose({
        handleOpen
    });
</script>
