<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.depotGrainName }}</a-descriptions-item>
				<a-descriptions-item label="放款单号">{{ formData.loanOrderNo }}</a-descriptions-item>
				<a-descriptions-item label="粮食种类">{{ formData.grainGroup }}</a-descriptions-item>
				<a-descriptions-item label="入库价格(元/吨)">{{ formData.orderDryPrice }}</a-descriptions-item>
				<a-descriptions-item label="入库实际价格(元/吨)">{{ formData.orderPrice }}</a-descriptions-item>
				<a-descriptions-item label="入库重量(吨)">{{ formData.orderDryWeight }}</a-descriptions-item>
				<a-descriptions-item label="入库实际重量(吨)">{{ formData.orderWeight }}</a-descriptions-item>
				<a-descriptions-item label="入库总金额(元)">{{ formData.orderAmount }}</a-descriptions-item>
				<a-descriptions-item label="质押价格(元/吨)">{{ formData.loanPrice }}</a-descriptions-item>
				<a-descriptions-item label="质押率(%)">{{ formData.loanRatio }}</a-descriptions-item>
				<a-descriptions-item label="放款金额(元)">{{ formData.loanAmount }}</a-descriptions-item>
				<a-descriptions-item label="放款状态">{{ formData.loanState }}</a-descriptions-item>
				<a-descriptions-item label="平均质押价格(元/吨)">{{ formData.loanPriceAvg }}</a-descriptions-item>
				<a-descriptions-item label="车量">{{ formData.loanTruckCount }}</a-descriptions-item>
				<a-descriptions-item label="审批状态">{{ formData.bankOpApprovalState }}</a-descriptions-item>
				<a-descriptions-item label="审批时间">{{ formData.approvalTime }}</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.approvalMsg }}</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 depotLoanGrantApi from '@/api/biz/depotLoanGrantApi'
import sysConfig from "@/config";
import DetailFormLeft from '../depotLoanOrder/detailFormLeft.vue'

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

const tableData = ref([])
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) {
		let recordData = cloneDeep(record)
		formData.value = Object.assign({}, recordData)
		// 让其回显
		/*if (formData.value.keeperCitizenPic)
			formData.value.keeperCitizenPic = sysConfig.API_URL + formData.value.keeperCitizenPic*/
		depotLoanGrantApi.depotLoanGrantDetail({id: record.id}).then((data) => {
			formData.value = data
		})
	}
}
// 关闭抽屉
const onClose = () => {
	formRef.value.resetFields()
	formData.value = {}
	visible.value = false
}
// 默认要校验的
const formRules = {}
// 抛出函数
defineExpose({
	onOpen
})
</script>
