<template>
	<xn-form-container :title="'充值记录详情'" :width="800" v-model:open="open" :destroy-on-close="true" @close="onClose">
		<a-form ref="formRef" :model="formData">
			<a-descriptions :column="2" bordered>
				<a-descriptions-item label="姓名">{{ formData.name }}</a-descriptions-item>
				<a-descriptions-item label="手机号">{{ formData.phone }}</a-descriptions-item>
				<a-descriptions-item label="充值金额">{{ formData.rechargeAmount + '元' }}</a-descriptions-item>
				<a-descriptions-item label="充值时间">{{ formData.rechargeTime }}</a-descriptions-item>
				<a-descriptions-item label="原账户糕点">{{ formData.oldAccountBalance + '个' }}</a-descriptions-item>
				<a-descriptions-item label="新账户糕点">{{ formData.newAccountBalance + '个' }}</a-descriptions-item>
				<a-descriptions-item label="返利金额" v-if="formData.rebateAmount != null">{{
					formData.rebateAmount
				}}</a-descriptions-item>
				<a-descriptions-item label="蛋糕券数量" v-if="formData.couponNum != null">{{
					formData.couponNum
				}}</a-descriptions-item>
				<a-descriptions-item label="订单号">{{ formData.orderNo }}</a-descriptions-item>
				<a-descriptions-item label="是否支付">{{ formData.isPay == '0'?'待支付': formData.isPay == '1'?'已支付':'已取消' }}</a-descriptions-item>
				<a-descriptions-item label="充值方案说明：" v-if="formData.rechargePlanId != null">{{
					formData.rechargePlanDescribe
				}}</a-descriptions-item>
			</a-descriptions>
		</a-form>
<!--		<template #footer>
			<a-button style="margin-right: 8px" @click="onClose">关闭</a-button>
			<a-button type="primary" @click="onSubmit" :loading="submitLoading">保存</a-button>
		</template>-->
	</xn-form-container>
</template>

<script setup name="bizRechargeRecordForm">
	import { cloneDeep } from 'lodash-es'
	import { required } from '@/utils/formRules'
	import bizRechargeRecordApi from '@/api/biz/bizRechargeRecordApi'
	// 抽屉状态
	const open = ref(false)
	const emit = defineEmits({ successful: null })
	const formRef = ref()
	// 表单数据
	const formData = ref({})
	const submitLoading = ref(false)

	// 打开抽屉
	const onOpen = (record) => {
		open.value = true
		if (record) {
			let recordData = cloneDeep(record)
			formData.value = Object.assign({}, recordData)
		}
	}
	// 关闭抽屉
	const onClose = () => {
		formRef.value.resetFields()
		formData.value = {}
		open.value = false
	}
	// 默认要校验的
	const formRules = {}
	// 验证并提交数据
	const onSubmit = () => {
		formRef.value
			.validate()
			.then(() => {
				submitLoading.value = true
				const formDataParam = cloneDeep(formData.value)
				bizRechargeRecordApi
					.bizRechargeRecordSubmitForm(formDataParam, formDataParam.id)
					.then(() => {
						onClose()
						emit('successful')
					})
					.finally(() => {
						submitLoading.value = false
					})
			})
			.catch(() => {})
	}
	// 抛出函数
	defineExpose({
		onOpen
	})
</script>
