<!-- 查询管理-内部订单查询-线下交收单查询-支付 -->
<template>
    <app-drawer title="提示" v-model:show="show" :loading="loading" :refresh="refresh">
        <div class="g-text-message">确认交收服务商向卖方支付货款？</div>
        <template #footer>
            <el-button @click="onCancel(false)">取消</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 { sellGoods } from '@/services/api/order'
import AppDrawer from '@pc/components/base/drawer/index.vue'

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

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

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

const onSubmit = () => {
    loading.value = true
    sellGoods({
        data: {
            deliveryorderid: props.record.deliveryorderid,
            marketid: props.record.marketid
        }
    }).then(() => {
        ElMessage.success('提交成功')
        onCancel(true)
    }).catch((err) => {
        ElMessage.error('提交失败：' + err)
        onCancel()
    }).finally(() => {
        loading.value = false
    })
}
</script>