<template>
	<view class="p-content1">
		<view class="p-head" v-if="detailData">
			<view>
				<view>
					<text>销售单号：</text>
					<text style="color: crimson;">{{detailData.salesBillNo}}</text>
				</view>
			</view>
			<view>
				<view>
					<text>客户名称：</text>
					<view>
						 {{ detailData&&detailData.buyerNameCurrent?detailData.buyerName?detailData.buyerName==detailData.buyerNameCurrent?detailData.buyerNameCurrent:detailData.buyerNameCurrent+'（'+detailData.buyerName+'）':detailData.buyerNameCurrent:'--' }}
					</view>
				</view>
			</view>
			<view>
				<view>
					<text>客户地址：</text>
					<view>
						<div v-if="detailData&&(detailData.shippingAddressProvinceName || detailData.shippingAddressCityName || detailData.shippingAddressCountyName || detailData.shippingAddress)">
						  {{ detailData&&detailData.shippingAddressProvinceName || '' }}
						  {{ detailData&&detailData.shippingAddressCityName || '' }}
						  {{ detailData&&detailData.shippingAddressCountyName || '' }}
						  {{ detailData&&detailData.shippingAddress || '' }}
						</div>
						<span v-else>--</span>
					</view>
				</view>
			</view>
			<view>
				<view>
					<text>收款方式：</text>
					<view>
						 {{detailData.settleStyleSnDictValue||'--'}}
					</view>
				</view>
			</view>
			<view>
				<view>
					<text>联系电话：</text>
					<view>
						 {{detailData.consigneeTel||'--'}}
					</view>
				</view>
			</view>
			<view>
				<view>
					<text>备注：</text>
					<view>
						 {{detailData.remarks||'--'}}
					</view>
				</view>
			</view>
			<view>
				<view>
					<text>制单人：</text>
					<view>
						 {{detailData.operatorName||'--'}}
					</view>
				</view>
			</view>
			<view>
				<view>
					<text>业务员：</text>
					<view>
						 {{detailData.salesManName||'--'}}
					</view>
				</view>
			</view>
			<view>
				<view>
					<text>来源：</text>
					<view>
						 {{detailData.sourceTypeDictValue||'--'}}
					</view>
				</view>
			</view>
			<view v-if="detailData&&detailData.sourceType=='PURCHASE'">
				<view>
					<text>下级采购单号：</text>
					<view>
						 {{ detailData&&detailData.purchaseBillNo || '--' }}
					</view>
				</view>
			</view>
			<view>
				<view>
					<text>业务状态：</text>
					<view>
						 {{detailData.billStatusDictValue||'--'}}
					</view>
				</view>
			</view>
			<view>
				<view>
					<text>财务状态：</text>
					<view>
						 {{detailData.financialStatusDictValue||'--'}}
					</view>
				</view>
			</view>
			<view v-if="detailData" style="justify-content: flex-start;flex-wrap: wrap;">
				<view>总款数：{{detailData.totalCategory||0}}</view>
				<view>总数量：{{detailData.totalQty||0}}</view>
				<view>总赠品数量：{{detailData.giftQty||0}}</view>
				<view>急件总款数：{{detailData.oosCategory||0}}</view>
				<view>急件总数量：{{detailData.oosQty||0}}</view>
				<view>总售价：￥{{detailData.totalAmount||0}}</view>
				<view>总成本：￥{{detailData.totalCost||0}}</view>
				<view>总毛利：￥{{detailData.grossProfit||0}}</view>
				<view>折后总售价：￥{{detailData.discountedAmount||0}}</view>
				<view>折扣：{{detailData.discountRate||0}}%</view>
				<view>折扣金额：￥{{detailData.discountAmount||0}}</view>
			</view>
		</view>
		<view class="p-body">
			<uni-table style="width: 100%;" border emptyText="暂无数据" :loading="loading" >
				<!-- 表头行 -->
				<uni-tr>
					<uni-td align="center">产品编码</uni-td>
					<uni-td align="center">产品名称</uni-td>
					<uni-td align="center">数量</uni-td>
					<uni-td align="center">售价</uni-td>
				</uni-tr>
				<!-- 表格数据行 -->
				<uni-tr v-for="item in detailList" :key="item.id">
					<uni-td width="30%" align="center">{{item.dealerProductEntity.code}}</uni-td>
					<uni-td width="30%" align="center">{{item.dealerProductEntity.name}}</uni-td>
					<uni-td width="20%" align="center">{{item.qty}}</uni-td>
					<uni-td width="20%" align="center"><u--text mode="price" :text="item.price"></u--text></uni-td>
				</uni-tr>
			</uni-table>
		</view>
	</view>
</template>

<script>
	import { salesDetail, salesDetailList } from '@/config/api.js'
	export default {
		data() {
			return {
				loading: false,
				detailData: null,
				detailList:[],
				code:'',
				salesBillSn: null,
				salesId: null,
			};
		},
		onLoad(opts) {
		  this.salesBillSn = opts.salesBillSn
		  this.salesId = opts.id
		  this.getDetail()
		  this.getDetailList()
		},
		methods: {
			// 详情
			getDetail(){
				salesDetail({salesBillSn: this.salesBillSn}).then(res => {
					console.log(res,'详情')
					if(res.status == 200){
						this.detailData = res.data
					}
				})
			},
			// 产品明细列表
			getDetailList(){
				salesDetailList({pageNo:1,pageSize:1000,salesBillSn:this.salesBillSn,orderBy: 'sales_bill_detail.CREATE_DATE desc'}).then(res => {
					console.log(res,'已添加产品列表')
					if(res.status == 200){
						this.detailList = res.data.list
					}
				})
			},
		},
	}
</script>

<style lang="scss">
	.p-content1{
		.p-head{
			font-size: 32upx;
			color: $uni-text-color;
			>view{
				display: flex;
				align-items: center;
				padding: 10upx 20upx;
				border-bottom: 1px solid #eee;
				> view{
					display: flex;
					padding: 0 10upx;
					align-items: center;
				}
			}
		}
		.p-body{
			overflow: auto;
		}
		.p-footer{
			padding:20upx 30upx;
			display: flex;
			> button{
				width: 30%;
			}
		}
	}
</style>
