<!-- 文件下载 -->
<template>
    <app-drawer title="下载" :width="800" v-model:show="show">
        <app-table :data="dataList" :loading="loading" :columns="columns" :show-toolbar="false" border>
            <!-- 生成时间 -->
            <template #operatetime="{ value }">
                {{ formatDate(value) }}
            </template>
            <!-- 操作 -->
            <template #operate="{ row }">
                <el-button size="small" @click="downloadFile(row.fileaddress)">下载</el-button>
            </template>
        </app-table>
    </app-drawer>
</template>

<script lang="ts" setup>
import { shallowRef, PropType } from 'vue'
import { getUrl, formatDate } from '@/filters'
import { useGZCJBSOrderFileList } from '@/business/customs/bonded'
import AppDrawer from '@pc/components/base/drawer/index.vue'
import AppTable from '@pc/components/base/table/index.vue'

const props = defineProps({
    selectedRow: {
        type: Object as PropType<{ orderidstr: string; orderid: string }>,
        required: true
    },
})

const getOrderId = () => {
    const { orderidstr, orderid } = props.selectedRow
    return orderidstr ?? orderid
}

const { loading, dataList, columns, getGZCJBSOrderFileList } = useGZCJBSOrderFileList(getOrderId())
const show = shallowRef(true)

const downloadFile = (file?: string) => {
    if (file) {
        window.location.href = getUrl(file).href
    }
}

getGZCJBSOrderFileList()
</script>