<template>
	<view class="warp">
		<view class="title">
			基本信息
		</view>
		<view class="content">
			<view class="row">
				<view class="left">仓库</view>
				<view class="right">{{detailData.warehouseName}}</view>
			</view>
			<view class="row">
				<view class="left">编号</view>
				<view class="right">{{detailData.number}}</view>
			</view>
			<view class="row">
				<view class="left">客户</view>
				<view class="right">{{detailData.customer}}</view>
			</view>
			<view class="row">
				<view class="left">车牌号</view>
				<view class="right">{{detailData.carNumber}}</view>
			</view>
			<view class="row">
				<view class="left">仓位号</view>
				<view class="right">{{detailData.binNumber}}</view>
			</view>
			<view class="row">
				<view class="left">囤位号</view>
				<view class="right">{{detailData.storageNumber}}</view>
			</view>
			<view class="row">
				<view class="left">货名</view>
				<view class="right">{{detailData.goodsName}}</view>
			</view>
			<view class="row row-bottom">
				<view class="left">毛重（公斤）</view>
				<view class="right">{{detailData.grossWeight}}</view>
			</view>
			<view class="row row-bottom">
				<view class="left">皮重（公斤）</view>
				<input class="right-bottom" placeholder="输入皮重" @input="changeInput" v-model="detailData.tare"></input>
			</view>
			<view v-if="detailData.qualityInspectionManagement.paramType == '2'" class="row row-bottom">
				<view class="left">扣重（公斤）</view>
				<input class="right-bottom" placeholder="输入扣重" @input="changeInput"
					v-model="detailData.buckleMiscellaneous"></input>
			</view>
			<view class="row row-bottom" style="border: 0;">
				<view class="left">净重（公斤）</view>
				<input class="right-bottom" disabled placeholder="自动计算" v-model="detailData.netWeight"></input>
			</view>
			<view  class="row row-bottom">
				<view class="left">应收卸车过磅费（元）</view>
				<input disabled class="right-bottom" placeholder="未获取到卸车过磅费金额"
					v-model="detailData.receivableWeighingFee"></input>
			</view>
			<view class="row row-bottom" style="border: 0;">
				<view class="left">实收卸车过磅费（元）</view>
				<input disabled class="right-bottom" placeholder="输入卸车过磅费"
					v-model="detailData.actualWeighingFee"></input>
			</view>
		</view>
		<u-button type="primary" class="submit" @click="submit">提交</u-button>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				detailData: {
					tare: 0,
					buckleMiscellaneous: 0,
					qualityInspectionManagement:{}
				},
				purchasePriceList: []
			}
		},
		onShow() {
			
			this.$api.doRequest('get', '/qualityInspectionManagement/api/goodsName', {
				warehouseId: this.detailData.warehouseId
			}).then(res => {
				if (res.data.code == 200) {
					this.purchasePriceList = res.data.data
				}
			})
		},
		onLoad(options) {
			this.detailData = JSON.parse(options.detailData)
			console.log(this.detailData)
			if (!this.detailData.buckleMiscellaneous) {
				this.detailData.buckleMiscellaneous = 0
			}
		},
		methods: {
			changeInput() {
				this.detailData.netWeight = (parseFloat(this.detailData.grossWeight) - parseFloat(this.detailData.tare) -
					parseFloat(this.detailData.buckleMiscellaneous)).toFixed(3)
			},
			submit() {
				let that = this;
				uni.showModal({
					content: "确定提交检斤信息?",
					success() {
						that.$api.doRequest('get', '/paymentManagement/cumulant', {
							compId: JSON.parse(localStorage.getItem('pcUserInfo')).data.compId,
							customerNumberCard: that.detailData.customerNumberCard,
							goodsName: that.detailData.goodsName,
						}).then(res => {
							if (res.data.code == 200) {
								for (let i = 0; i < that.purchasePriceList.length; i++) {
									if (
										that.detailData.goodsName == that.purchasePriceList[i]
										.goodsName
									) {
										let count = (that.purchasePriceList[i].saleLimit -
											res.data.data / 1000).toFixed(2)
										if (count <= 0) {
											count = 0
											that.$api.msg('该客户累计销售' + this.detailData.goodsName + (
													res.data.data / 1000).toFixed(2) +
												'吨，还可售粮' +
												count + '吨', )

										} else {
											that.$api.doRequest('post', '/weighingManagement/api/editTare',
												that.detailData).then(res => {
												if (res.data.code == 200) {
													that.$refs.uToast.show({
														title: '提交成功',
														type: 'success'
													})
													uni.navigateBack({})
												} else {
													that.$refs.uToast.show({
														title: '提交失败',
														type: 'error',
													})
												}
											})
										}
									}
								}
							}
						})
					}
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	uni-page-body {
		overflow: hidden;
	}

	.warp {
		background: white;
		margin: 20rpx;
		padding: 20rpx;
		border-radius: 20rpx;

		.title {
			font-size: 28rpx;
			font-weight: 500;
			color: #333333;
		}
	}

	.content {
		.row {
			display: flex;
			justify-content: space-between;
			padding: 21rpx 0;

			.right {
				font-size: 28rpx;
				// font-weight: 600;
				color: #333333;
			}
		}

		.row-bottom {

			// border: 0;
			.right-bottom {
				width: 300rpx;
				font-size: 28rpx;
				font-weight: 600;
				color: #333333;
				text-align: right;
			}
		}
	}

	.submit {
		position: fixed;
		bottom: 40rpx;
		width: 90%;
		background: #22C572;
		border-radius: 50rpx;

	}
</style>
