<!-- 查询管理-内部订单查询-线下交收单查询-详情 -->
<template>
    <app-drawer :title="t('query.internal.offlinedelivery.details.title')" width="960" v-model:show="show">
        <app-table-details :data="data" :label-width="160" :cell-props="detailProps" :column="2">
            <!-- 申请交收数量 -->
            <template #deliveryqty v-if="data">
                <span>{{ data.deliveryqty }}</span>
                <span>{{ goodsunitEnum.getEnumTypeName(data.goodunitid) }}</span>
            </template>
            <!-- 实际交收数量 -->
            <template #sucdeliveryqty v-if="data">
                <span>{{ data.sucdeliveryqty }}</span>
                <span>{{ goodsunitEnum.getEnumTypeName(data.goodunitid) }}</span>
            </template>
            <!-- 撤销交收数量 -->
            <template #cancledeliveryqty v-if="data">
                <span>{{ data.cancledeliveryqty }}</span>
                <span>{{ goodsunitEnum.getEnumTypeName(data.goodunitid) }}</span>
            </template>
        </app-table-details>
        <template #footer>
            <el-button @click="onCancel">{{ t('operation.close') }}</el-button>
        </template>
    </app-drawer>
</template>

<script lang="ts" setup>
import { shallowRef, PropType, computed } from 'vue'
import { ElMessage } from 'element-plus'
import { formatDate } from '@/filters'
import { useEnum } from '@/hooks/enum'
import { useRequest } from '@/hooks/request'
import { queryOfflineDetail } 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.OfflineRsp>,
        required: true
    }
})

const { t } = i18n.global
const buyOrSellEnum = useEnum('buyOrSell') // 方向
const goodsunitEnum = useEnum('goodsunit')
const deliveryOrderStatusEnum = useEnum('deliveryOrderStatus')
const show = shallowRef(true)

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

const detailProps = computed<CellProp[]>(() => [
    { prop: 'deliveryorderid', label: 'query.internal.offlinedelivery.details.deliveryorderid' },
    { prop: 'username', label: 'query.internal.offlinedelivery.details.username' },
    { prop: 'goodscode', label: 'query.internal.offlinedelivery.details.goodsdisplay' },
    { prop: 'buyorsell', label: 'query.internal.offlinedelivery.details.buyorsell', formatValue: (val) => buyOrSellEnum.getEnumTypeName(val) },
    { prop: 'deliveryqty', label: 'query.internal.offlinedelivery.details.deliveryqty' },
    { prop: 'sucdeliveryqty', label: 'query.internal.offlinedelivery.details.sucdeliveryqty' },
    { prop: 'cancledeliveryqty', label: 'query.internal.offlinedelivery.details.cancledeliveryqty' },
    { prop: 'deliveryprice', label: 'query.internal.offlinedelivery.details.deliveryprice' },
    { prop: 'deliveryamount', label: 'query.internal.offlinedelivery.details.deliveryamount' },
    { prop: 'matchname', label: 'query.internal.offlinedelivery.details.matchname' },
    { prop: 'deliveryinfo', label: 'query.internal.offlinedelivery.details.deliveryinfo' },
    { prop: 'reqtime', label: 'query.internal.offlinedelivery.details.reqtime', formatValue: (val) => formatDate(val) },
    { prop: 'orderstatus', label: 'query.internal.offlinedelivery.details.orderstatusdisplay', formatValue: (val) => deliveryOrderStatusEnum.getEnumTypeName(val) },
    { prop: 'remark', label: 'query.internal.offlinedelivery.details.remark' },
    { prop: 'deliverycharge', label: 'query.internal.offlinedelivery.details.deliverycharge' },
    { prop: 'totalpricemove', label: 'query.internal.offlinedelivery.details.totalpricemove', show: !!data.value?.totalpricemove },
    { prop: 'totalshippingfee', label: 'query.internal.offlinedelivery.details.totalshippingfee', show: !!data.value?.totalshippingfee },
    { prop: 'totalotherfee', label: 'query.internal.offlinedelivery.details.totalotherfee', show: !!data.value?.totalotherfee },
    { prop: 'closetime', label: 'query.internal.offlinedelivery.details.closetime', formatValue: (val) => formatDate(val) },
])

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