<!-- 编辑弹窗 -->
<template>
    <ele-modal form :width="920" v-model="visible" title="短信记录">
        <ele-data-table row-key="id" :columns="columns" :data="smsRecords" />

        <template #footer>
            <el-button @click="handleCancel">关闭</el-button>
        </template>
    </ele-modal>
</template>

<script setup>
    import { ref, reactive, nextTick, getCurrentInstance } from 'vue';
    import { EleMessage } from 'ele-admin-plus/es';

    const { proxy } = getCurrentInstance();

    /** 弹窗是否打开 */
    const visible = defineModel({ type: Boolean });

    /** SMS记录数据 */
    const smsRecords = ref([]);

    /** 关闭弹窗 */
    const handleCancel = () => {
        visible.value = false;
    };

    /** 弹窗打开事件 */
    const handleOpen = (row) => {
        if (row.orderId) {
            visible.value = true;
            getSmsLogInfo(row.orderId);
        }
    };

    /** 获取短信记录信息 */
    const getSmsLogInfo = (orderId) => {
        proxy.$http.get(`/order/orderSmsLog/getInfo/${orderId}`).then((res) => {
            if (res.data.code === 200) {
                let data = res.data.data || [];
                smsRecords.value = data.smsLogList || [];
            } else {
                EleMessage.error(res.data.msg || '获取短信记录失败');
            }
        });
    };

    // 表格数据
    const columns = reactive([
        { label: '发送人', prop: 'createName', width: 100 },
        { label: '发送内容', prop: 'smsContent' },
        { label: '发送时间', prop: 'createTime', width: 170 }
    ]);

    defineExpose({
        handleOpen
    });
</script>
