<template>
	<view style="font-size: 32rpx;">
		<table style="width: 100%;">
			<!-- 表头行 -->
			<tr>
				<th align="center" colspan="4">{{tenantName}}销售单</th>
			</tr>
			<tr>
				<th align="left" colspan="4">NO.{{form.sysNo}}</th>
			</tr>
			<tr>
				<th align="left" colspan="2">客户:{{form.corpsName}}</th>
				<th align="right" colspan="2">销售日期:{{form.businesDate?form.businesDate.slice(0, 10):''}}</th>
			</tr>
			<!-- 表格数据行 -->
			<tr>
				<td align="center" style="width: 25%;">产品</td>
				<td align="center" style="width: 25%;">数量</td>
				<td align="center" style="width: 25%;">单价</td>
				<td align="center" style="width: 25%;">金额</td>
			</tr>
			<tr v-for="(item,index) in form.orderItemsList" :key="index">
				<td align="left" colspan="4" style="padding: 0;border: none;">
					<table style="width: 100%;border-collapse: collapse;">
						<tr>
							<td align="left" colspan="4">{{item.cname}}</td>
						</tr>
						<tr style="border-bottom: 1rpx solid #000;">
							<td align="center" style="width: 25%;"></td>
							<td align="center" style="width: 25%;">{{Number(item.storageInQuantity)}}</td>
							<td align="center" style="width: 25%;">{{Number(item.price).toFixed(2)}}</td>
							<td align="center" style="width: 25%;">{{item.amount}}</td>
						</tr>
					</table>
				</td>
			</tr>
			<tr>
				<td colspan="2">合计金额(小):{{amountNumber.amount}}</td>
				<td colspan="2">合计金额(大):{{amountNumber.amountDX}}</td>
			</tr>
			<tr>
				<td colspan="4">订货电话:{{form.clientAttn}}</td>
			</tr>
			<tr>
				<!-- <td colspan="2">制单人:{{form.client}}</td> -->
				<td colspan="2">制单人:{{userInfoName}}</td>
				<td colspan="2">收货人(签字):</td>
			</tr>
		</table>
	</view>
</template>

<script>
	import {
		DX
	} from '@/common/dateFormat.js';
	export default {
		data() {
			return {
				form:{},
				amountNumber:{},
				tenantName:'',
				userInfoName:'',
			}
		},
		onLoad(options) {
			this.tenantName = uni.getStorageSync('information').tenantName
			this.userInfoName = uni.getStorageSync('userInfo').account
			this.form = JSON.parse(options.data)
			this.amountNumber = {
				deliveryAll: 0, //送货总数量
				cost: 0, //成本
				grossProfit: 0, //毛利
				delivery: 0, //送货
				saleAll: 0, //销售数量
				amount: 0
			}
			for (let item of this.form.orderItemsList) {
				this.amountNumber.saleAll += Number(item.storageInQuantity)
				this.amountNumber.cost += Number(item.storageInQuantity) * Number(item.purchasePrice)
				this.amountNumber.delivery += Number(item.actualQuantity)
				this.amountNumber.deliveryAll += Number(item.actualQuantity)
				this.amountNumber.amount += Number(item.amount)
				this.amountNumber.grossProfit += Number(item.amount) - (item.purchasePrice ? Number(item.storageInQuantity) * Number(item.purchasePrice) : 0)
			}
			this.form.purchaseAmount = this.amountNumber.amount
			this.amountNumber.amountDX = DX(this.amountNumber.amount)
		}
	}
</script>

<style scoped>
	page {
		background-color: #fff !important;
	}
</style>
