<!-- 查询管理-订单管理-交收单管理-详情 -->
<template>
    <app-drawer :title="t('query.order.delivery.details.title')" width="960" v-model:show="show">
        <app-table-details :data="data" :label-width="160" :cell-props="detailProps1" :column="2" />
        <template #footer>
            <el-button @click="onCancel">{{ t('operation.close') }}</el-button>
        </template>
    </app-drawer>
</template>

<script lang="ts" setup>
import { shallowRef, PropType } from 'vue'
import { ElMessage } from 'element-plus'
import { formatDate } from '@/filters'
import { useEnum } from '@/hooks/enum'
import { useRequest } from '@/hooks/request'
import { queryDeliveryOrderListDetail } from '@/services/api/order'
import { CellProp } from '@pc/components/base/table-details/types'
import AppDrawer from '@pc/components/base/drawer/index.vue'
import AppTableDetails from '@pc/components/base/table-details/index.vue'
import { i18n } from '@/stores'

const props = defineProps({
    record: {
        type: Object as PropType<Model.DeliveryOrderListRsp>,
        required: true
    }
})

const buyOrSellEnum = useEnum('buyOrSell') // 方向
const deliveryOrderStatusSellEnum = useEnum('deliveryOrderStatus') // 单据状态

const { t } = i18n.global
const show = shallowRef(true)

const { data } = useRequest(queryDeliveryOrderListDetail, {
    params: {
        deliveryorderid: props.record.deliveryorderid
    },
    onError: (err) => {
        ElMessage.error(err)
    }
})

const detailProps1: CellProp[] = [
    { prop: 'deliveryorderid', label: 'query.order.delivery.details.deliveryorderid' },
    { prop: 'username', label: 'query.order.delivery.details.username' },
    { prop: 'goodscode', label: 'query.order.delivery.details.goodsdisplay' },
    { prop: 'buyorsell', label: 'query.order.delivery.details.buyorselldisplay', formatValue: (val) => buyOrSellEnum.getEnumTypeName(val) },
    { prop: 'deliveryqty', label: 'query.order.delivery.details.deliveryqty' },
    { prop: 'sucdeliveryqty', label: 'query.order.delivery.details.sucdeliveryqty' },
    { prop: 'cancledeliveryqty', label: 'query.order.delivery.details.cancledeliveryqty' },
    { prop: 'deliveryprice', label: 'query.order.delivery.details.deliveryprice' },
    { prop: 'deliveryamount', label: 'query.order.delivery.details.deliveryamount' },
    { prop: 'matchname', label: 'query.order.delivery.details.matchname' },
    { prop: 'deliveryinfo', label: 'query.order.delivery.details.deliveryinfo' },
    { prop: 'reqtime', label: 'query.order.delivery.details.reqtime', formatValue: (val) => formatDate(val) },
    { prop: 'orderstatus', label: 'query.order.delivery.details.orderstatusdisplay', formatValue: (val) => deliveryOrderStatusSellEnum.getEnumTypeName(val) },
    { prop: 'remark', label: 'query.order.delivery.details.remark' },
    { prop: 'deliverycharge', label: 'query.order.delivery.details.deliverycharge' },
    { prop: 'closetime', label: 'query.order.delivery.details.closetime', formatValue: (val) => formatDate(val) },
]

const onCancel = () => {
    show.value = false
}
</script>