<!-- 交易服务-保税服务-确认预付款 -->
<template>
    <app-drawer title="确认预付款" :width="800" v-model:show="show" :loading="loading" :refresh="refresh">
        <el-descriptions :column="2" border v-if="details">
            <el-descriptions-item label="单据编号">{{ handleNoneValue(selectedRow.orderno) }}</el-descriptions-item>
            <el-descriptions-item label="税费保证金">{{ details.taxmargin }}</el-descriptions-item>
            <el-descriptions-item label="汇款银行手续费">{{ details.bankfee }}</el-descriptions-item>
            <el-descriptions-item label="代缴物流保险费">{{ details.logisticsfee }}</el-descriptions-item>
            <el-descriptions-item label="综合服务费">{{ details.servicefee }}</el-descriptions-item>
            <el-descriptions-item label="其它费用">{{ details.otherfee }}</el-descriptions-item>
            <el-descriptions-item label="总共">{{ details.totalfee }}</el-descriptions-item>
            <el-descriptions-item label="预付款详情文件">请下载文件“预付款通知书”</el-descriptions-item>
            <el-descriptions-item label="账户可用余额">{{ accountStore.avaiableMoney.toFixed(2) }}</el-descriptions-item>
        </el-descriptions>
        <template #footer>
            <el-button @click="onCancel(false)" plain>取消</el-button>
            <el-button type="primary" :disabled="disabled" @click="onSubmit">确认</el-button>
        </template>
    </app-drawer>
</template>

<script lang="ts" setup>
import { shallowRef, PropType, computed } from 'vue'
import { ElMessage } from 'element-plus'
import { handleNoneValue } from '@/filters'
import { useAccountStore } from '@/stores'
import { useBSFWOrderOperate, useBSFWMemberOperate } from '@/business/customs/bonded'
import AppDrawer from '@pc/components/base/drawer/index.vue'

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

const { details, getFworderoperate } = useBSFWOrderOperate(props.selectedRow)
const { loading, formData, formSubmit } = useBSFWMemberOperate(props.selectedRow.orderid)
const accountStore = useAccountStore()
const show = shallowRef(true)
const refresh = shallowRef(false)

const disabled = computed(() => {
    const { totalfee = 0 } = details.value ?? {}
    return totalfee > accountStore.avaiableMoney
})

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

const onSubmit = () => {
    formData.OperateType = 3
    formSubmit().then(() => {
        ElMessage.success('提交成功')
        onCancel(true)
    }).catch((err) => {
        ElMessage.error('提交失败：' + err)
    })
}

getFworderoperate()
</script>