<template>
	<a-drawer
		:title="'出库还款详情'"
		:width="800"
		:visible="visible"
		:destroy-on-close="true"
		:footer-style="{ textAlign: 'right' }"
		@close="onClose"
	>
		<a-form ref="formRef" :model="formData" :rules="formRules" layout="vertical">
			※ 还款流程 ：申请还款单 → 银行审批
			<a-descriptions :column="1" size="middle" bordered class="mb-2">
				<a-descriptions-item label="银行审批">{{ formData.bankOpApprovalState }}</a-descriptions-item>
				<a-descriptions-item label="预约状态 ">{{ formData.bookFlag }}</a-descriptions-item>
				<a-descriptions-item label="单据状态">{{ formData.repayState }}</a-descriptions-item>
				<a-descriptions-item label="还款单号">{{ formData.repayOrderNo }}</a-descriptions-item>
				<a-descriptions-item label="还款本金(元)">{{ formData.repayPrincipal }}</a-descriptions-item>
				<a-descriptions-item label="利息(元)">{{ formData.repayInterest }}</a-descriptions-item>
				<a-descriptions-item label="还款单价(元/吨)">{{ formData.repayPrice }}</a-descriptions-item>
				<a-descriptions-item label="粮食种类">{{ formData.grainGroup }}</a-descriptions-item>
				<a-descriptions-item label="库位">{{ formData.shedName }}</a-descriptions-item>
				<a-descriptions-item label="本单出库量(吨)">{{ formData.repayTonThis }}</a-descriptions-item>
				<a-descriptions-item label="上次扭转余量(吨)">{{ formData.repayBeforeTonSurplus }}</a-descriptions-item>
				<a-descriptions-item label="总提货量(吨)">{{ formData.repayTonSum }}</a-descriptions-item>
				<a-descriptions-item label="已出库重量(吨)">{{ formData.repayTonOut }}</a-descriptions-item>
				<a-descriptions-item label="待出库重量(吨)">{{ formData.repayTonSurplus }}</a-descriptions-item>
				<a-descriptions-item label="车牌">{{ formData.licensePlate }}</a-descriptions-item>
				<a-descriptions-item label="授权提货人">{{ formData.keeperName }}</a-descriptions-item>
				<a-descriptions-item label="授权提货人身份证号">{{ formData.keeperCitizenId }}</a-descriptions-item>
				<a-descriptions-item label="授权提货人联系方式">{{ formData.keeperMobile }}</a-descriptions-item>
				<a-descriptions-item label="身份证照片">
					<a v-if="formData.keeperCitizenPic" :href="formData.keeperCitizenPic" target="_blank">
						<img :src="formData.keeperCitizenPic" alt="avatar" style="max-height: 100px; max-width: 100px"/></a>
				</a-descriptions-item>
				<a-descriptions-item label="还款审批状态">{{ formData.bankOpApprovalState }}</a-descriptions-item>
				<a-descriptions-item label="审批员">{{ formData.approvalUserName }}</a-descriptions-item>
				<a-descriptions-item label="审批员账号">{{ formData.approvalUserAccount }}</a-descriptions-item>
				<a-descriptions-item label="审批时间">{{ formData.bankOpApprovalTime }}</a-descriptions-item>
				<a-descriptions-item label="审批信息">{{ formData.bankOpApprovalMsg }}</a-descriptions-item>
			</a-descriptions>
			<br>
			车次信息：
			<a-table
				ref="table"
				size="small"
				:columns="columns"
				:data-source="formData.depotWorkList"
				:expand-row-by-click="true"
				bordered
			>
				<template #bodyCell="{ column, record }">
					<template v-if="column.dataIndex === 'action' ">
						<a @click="detailFormLeftRef.onOpen(record)">详情 </a>
					</template>
				</template>
			</a-table>
		</a-form>
		<template #footer>
			<a-button style="margin-right: 8px" @click="onClose">关闭</a-button>
		</template>
	</a-drawer>
	<DetailFormLeft ref="detailFormLeftRef"/>
</template>

<script setup name="depotRepayOrderForm">
import {message} from 'ant-design-vue'
import tool from '@/utils/tool'
import {cloneDeep} from 'lodash-es'
import {required, rules} from '@/utils/formRules'
import depotWorkApi from '@/api/biz/depotWorkApi'
import sysConfig from "@/config";
import DetailFormLeft from '../depotTruckWeighDouble/detailFormLeft.vue'
import depotTruckWeighDoubleApi from '@/api/biz/depotTruckWeighDoubleApi'
import depotRepayOrderApi from '@/api/biz/depotRepayOrderApi'

// 抽屉状态
const visible = ref(false)
const emit = defineEmits({successful: null})
const formRef = ref()
// 表单数据
const formData = ref({})
const detailFormLeftRef = ref()
const submitLoading = ref(false)

const columns = [
	{
		title: '车牌',
		dataIndex: 'licensePlate'
	},
	{
		title: '数量(吨)',
		dataIndex: 'depotTonCount'
	},
	{
		title: '总价(元)',
		dataIndex: 'orderAmount'
	},
	{
		title: '单据分类',
		dataIndex: 'billGroup'
	},
	{
		title: '时间',
		dataIndex: 'createTime'
	},
	{
		title: '操作',
		dataIndex: 'action',
		align: 'center',
		width: '50px'
	}
]

// 打开抽屉
const onOpen = (record) => {
	visible.value = true
	if (record)
		depotRepayOrderApi.depotRepayOrderDetail({id: record.id}).then((data) => {
			formData.value = data
		})
}
// 关闭抽屉
const onClose = () => {
	formRef.value.resetFields()
	formData.value = {}
	visible.value = false
}
// 默认要校验的
const formRules = {}
// 抛出函数
defineExpose({
	onOpen
})
</script>
