<!-- 交易服务-出境检测-确认预付款 -->
<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="单据编号">{{ selectedRow.orderidstr }}</el-descriptions-item>
            <el-descriptions-item label="GIA检测费">{{ details.giarmbfee }}</el-descriptions-item>
            <el-descriptions-item label="海关税费">{{ details.customsfee }}</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 { useAccountStore } from '@/stores'
import { useCJJCOrderOperate, useCJJCMemberOperate } from '@/business/customs/exit'
import AppDrawer from '@pc/components/base/drawer/index.vue'

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

const { details, getGzcjjcorderoperate } = useCJJCOrderOperate(props.selectedRow)
const { loading, formData, formSubmit } = useCJJCMemberOperate(props.selectedRow.orderidstr)
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 = 4
    formSubmit().then(() => {
        ElMessage.success('提交成功')
        onCancel(true)
    }).catch((err) => {
        ElMessage.error('提交失败：' + err)
    })
}

getGzcjjcorderoperate()
</script>