<template>
	<xn-form-container title="流水" :width="1300" :visible="visible" :destroy-on-close="true" @close="onClose">
		<s-table
			ref="tableRef"
			:columns="columns"
			:data="loadData"
			bordered
			:row-key="(record) => record.id"
		>
			<template #operator class="table-operator">
<!--				<a-space>
					<a-button type="dashed" class="snowy-buttom-left" @click="exportData()" v-if="hasPerm('bizRecordBatchExport')"
					><export-outlined />记录导出</a-button
					>
				</a-space>-->
			</template>
			<template #bodyCell="{ column, record }">
				<template v-if="column.dataIndex === 'licensePlate'">
					<span v-if="record.plateColor === '蓝色'" class="blue-background">{{ record.licensePlate }}</span>
					<span v-else-if="record.plateColor === '黄色'" class="yellow-background">{{ record.licensePlate }}</span>
					<span v-else-if="record.plateColor === '绿色'" class="green-background">{{ record.licensePlate }}</span>
					<span v-else-if="record.plateColor === '白色'" class="white-background">{{ record.licensePlate }}</span>
					<span v-else-if="record.plateColor === '黑色'" class="black-background">{{ record.licensePlate }}</span>
					<span v-else class="blue-background">{{ record.licensePlate }}</span>
				</template>

				<template v-if="column.dataIndex === 'enterTime'">
					<div class="time-list">
						<p>
							<span class="blueTag">过毛</span>
							<span style="font-weight: normal">{{ record.grossTime }}</span>
						</p>
						<p style="margin-bottom: 0">
							<span class="orangeTag">过皮</span>
							<span style="font-weight: normal">{{ record.tareTime }}</span>
						</p>
					</div>
				</template>

				<template v-if="column.dataIndex === 'weight'">
					<div class="time-list">
						<p>
							<span class="blueTag">毛重</span>
							<span class="showNum">{{ record.grossWeight }} </span>
						</p>
						<p>
							<span class="orangeTag">皮重</span>
							<span class="showNum">{{ record.tareWeight }}</span>
						</p>
						<p>
							<span class="greenTag">净重</span>
							<span class="showNum">{{ record.netWeight }}</span>
						</p>
					</div>
				</template>

				<template v-if="column.dataIndex === 'company'">
					<div class="company-list">
						<p>收货：{{ record.receiptCompany }}</p>
						<p>发货：{{ record.shippingCompany }}</p>
						<p style="margin-bottom: 0">运输：{{ record.transportCompany }}</p>
					</div>
				</template>

				<template v-if="column.dataIndex === 'goods'">
					<div class="time-list">
						<p>名称：{{ record.goodsName }}</p>
						<p style="margin-bottom: 0">规格：{{ record.goodsModel }}</p>
					</div>
				</template>

				<template v-if="column.dataIndex === 'driver'">
					<div class="time-list">
						<p>姓名：{{ record.driverName }}</p>
						<p style="margin-bottom: 0">电话：{{ record.driverMobile }}</p>
					</div>
				</template>
				<template v-if="column.dataIndex === 'orderInfo'">
					<div class="time-list">
						<p>名称：{{ record.orderName }}</p>
						<p style="margin-bottom: 0">编号：{{ record.orderNumber }}</p>
					</div>
				</template>

				<template v-if="column.dataIndex === 'action'">
					<a-space>
						<a @click="detailRef.onOpen(record)">详情</a>
					</a-space>
				</template>
			</template>
		</s-table>
	</xn-form-container>

	<Detail ref="detailRef" />
</template>

<script setup name="recordDoubleForm">
	import { cloneDeep } from 'lodash-es'
	import bizRecordApi from "@/api/biz/bizRecordApi";
	import Detail from "@/views/biz/record/detail.vue";
	// 默认是关闭状态
	const visible = ref(false)
	const formData = ref({})
	const table = ref()
	const resultJson = ref()
	const detailRef = ref()

	const labelStyle = {
		width: '20%'
	}
	const contentStyle = {
		width: '30%'
	}

	const labelCol4 = ref({span: 4, style: 'width: 26%; line-height: 20px; white-space: normal',})
	const labelCol8 = ref({span: 8, style: 'width: 26%; line-height: 20px; white-space: normal',})
	const wrapperCol20 = ref({span: 20})

	const columns = [
		{
			title: '车次编码',
			dataIndex: 'carNumber',
			width: 120,
			align: 'center'
		},
		{
			title: '车牌号码',
			dataIndex: 'licensePlate',
			width: '130px',
			align: 'center'
		},
		{
			title: '过车时间',
			dataIndex: 'enterTime',
			width: '130px'
		},
		{
			title: '重量（吨）',
			dataIndex: 'weight',
			align: 'center'
		},
		{
			title: '订单信息',
			dataIndex: 'orderInfo'
		},
		{
			title: '客户名称',
			dataIndex: 'customerName',
			align:'center'
		},
		{
			title: '货品',
			dataIndex: 'goods'
		},
		{
			title: '司机信息',
			dataIndex: 'driver',
			width: '200px'
		}
	]

	// 操作栏通过权限判断是否显示
	columns.push({
		title: '操作',
		dataIndex: 'action',
		align: 'center',
		width: 150
	})

	const orderId = ref()
	// 打开抽屉
	const onOpen = (record) => {
		visible.value = true
		if(record){
			let recordData = cloneDeep(record)
			formData.value = Object.assign({}, recordData)
			orderId.value = record.id
		}

	}

	const loadData = (parameter) => {
		let param = {
			orderId:orderId.value
		}
		return bizRecordApi.bizRecordPage(param).then((data) => {
			return data
		})
	}

	// 关闭抽屉
	const onClose = () => {
		resultJson.value = ''
		visible.value = false
	}
	// 调用这个函数将子组件的一些数据和方法暴露出去
	defineExpose({
		onOpen
	})
</script>

<style scoped>
	.imgDiv ::v-deep .ant-image {
		margin-left: 20px;
		margin-top: 10px;
	}
	.imgDiv ::v-deep .ant-image-mask-info {
		margin-left: 20px;
		margin-top: 10px;
	}

	/** 表头居中 */
	:deep .ant-table-thead > tr > th {
		text-align: center;
	}

	.time-list {
		-webkit-text-size-adjust: none;
		font-size: 13px;
		display: flex;
		flex-direction: column;

		p {
			white-space: nowrap;
			span {
				display: inline-block;
				font-weight: 600;
				height: 16px;
				line-height: 16px;
				border-radius: 5px;
				text-align: center;
				margin-right: 2px;
				padding: 0 5px;
			}
			.blueTag {
				color: #1890ff;
				background: rgba(24, 144, 255, 0.1);
			}
			.orangeTag {
				color: #ff7c18;
				background: rgba(24, 144, 255, 0.1);
			}
			.greenTag {
				color: rgb(82, 196, 26);
				background: rgba(82, 196, 26, 0.1);
			}
			.purpleTag {
				color: rgb(77, 26, 196);
				background: rgba(82, 196, 26, 0.1);
			}
			.showNum {
				display: inline-block;
				height: 16px;
				line-height: 16px;
				width: 45px;
				border-radius: 5px;
				text-align: center;
				margin-right: 2px;
				text-align: right;
			}
		}
	}

	.order-list,
	.company-list {
		-webkit-text-size-adjust: none;
		font-size: 13px;
		display: flex;
		flex-direction: column;
		p {
			white-space: nowrap;
			margin-bottom: 5px;
			.weightSpan,
			.company {
				display: inline-block;
				width: 17px;
				height: 17px;
				line-height: 16px;
				border-radius: 50%;
				color: #fff;
				text-align: center;
			}
			.company {
				margin-right: 5px;
			}
			.weight,
			.receiptCompany {
				background-color: #1890ff;
			}
			.tare {
				background-color: #2f54eb;
			}
			.netWeight,
			.shippingCompany {
				background-color: #52c41a;
			}
			.transportCompany {
				background-color: #c61263;
			}
			.showNum {
				display: inline-block;
				height: 16px;
				line-height: 16px;
				width: 45px;
				border-radius: 5px;
				text-align: center;
				margin-right: 2px;
				text-align: right;
			}
			em {
				font-style: normal;
			}
		}
	}
	.blue-background {
		background-color: #0d84ff;
		border-radius: 5px; /* 你可以根据需要调整圆角的大小 */
		padding: 5px; /* 可选：添加一些内边距 */
		color: white; /* 可选：设置文字颜色 */
		font-size: large;
	}
	.yellow-background {
		background-color: yellow;
		border-radius: 5px;
		padding: 5px;
		color: black;
		font-size: large;
	}
	.green-background {
		background: linear-gradient(to bottom, white, #39b54a);
		border-radius: 5px;
		padding: 5px;
		color: black; /* 文字颜色改为黑色以便在渐变背景上更清晰 */
		font-size: large;
		border: 1px solid #ccc; /* 增加边框 */
		box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); /* 增加阴影 */
	}

	.white-background {
		background-color: white;
		border-radius: 5px;
		padding: 5px;
		color: black;
		font-size: large;
		border: 1px solid #ccc; /* 增加边框 */
		box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); /* 增加阴影 */
	}

	.black-background {
		background-color: black;
		border-radius: 5px;
		padding: 5px;
		color: white;
		font-size: large;
	}
</style>
