<!-- WMS结算单-支付 -->
<template>
    <app-drawer title="确认支付" :width="400" v-model:show="show" :loading="loading" :refresh="refresh">
        <app-table-details :title="`WMS结算单【${selectedRow.reckonmonth}】`" :label-width="110" :data="selectedRow"
            :cell-props="cellProps" />
        <template #footer>
            <el-button @click="onCancel(false)" plain>取消</el-button>
            <el-button type="primary" @click="onSubmit">确认</el-button>
        </template>
    </app-drawer>
</template>

<script lang="ts" setup>
import { shallowRef, PropType } from 'vue'
import { ElMessage } from 'element-plus'
import { bsWMSReckonPay } from '@/services/api/bonded'
import AppDrawer from '@pc/components/base/drawer/index.vue'
import AppTableDetails from '@pc/components/base/table-details/index.vue'

const props = defineProps({
    selectedRow: {
        type: Object as PropType<Ermcp.GzbscreckonorderRsp>,
        required: true
    },
})

const show = shallowRef(true)
const refresh = shallowRef(false)
const loading = shallowRef(false)

const cellProps = [
    { prop: 'servicefee', label: '分拣室服务费', decimal: 2 },
    { prop: 'storagefee', label: '仓储费', decimal: 2 },
    { prop: 'premium', label: '保险费', decimal: 2 },
    { prop: 'powerfee', label: '分拣室电费', decimal: 2 },
    { prop: 'customsfee', label: '报关费', decimal: 2 },
    { prop: 'totalfee', label: '合计费用', decimal: 2 },
]

const onCancel = (isRefresh = false) => {
    show.value = false
    refresh.value = isRefresh
}

const onSubmit = () => {
    loading.value = true
    bsWMSReckonPay({
        OrderID: props.selectedRow.orderid
    }).then(() => {
        ElMessage.success('提交成功')
        onCancel(true)
    }).catch((err) => {
        ElMessage.error('提交失败：' + err)
    }).finally(() => {
        loading.value = false
    })
}
</script>