<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 v-if='detailData.serviceManagementType==3' 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">
				<view class="left">运输方式</view>
				<view class="right">{{detailData.outType}}</view>
			</view>
			<view v-if='detailData.outType=="汽运"||detailData.outType=="集装箱船"' class="row">
				<view class="left">箱号-1</view>
				<view class="right">{{detailData.qualityInspectionManagement.boxNo}}</view>
			</view>
			<view v-if='detailData.outType=="汽运"||detailData.outType=="集装箱船"' class="row">
				<view class="left">封号-1</view>
				<view class="right">{{detailData.qualityInspectionManagement.titleNo}}</view>
			</view>
			<view  v-if='detailData.outType=="汽运"||detailData.outType=="集装箱船"'class="row">
				<view class="left">箱号-2</view>
				<view class="right">{{detailData.qualityInspectionManagement.boxNoOther}}</view>
			</view>
			<view v-if='detailData.outType=="汽运"||detailData.outType=="集装箱船"' class="row  row-bottom">
				<view class="left">封号-2</view>
				<view class="right">{{detailData.qualityInspectionManagement.titleNoOther}}</view>
			</view>
			<view v-if='detailData.outType=="散船"' class="row">
				<view class="left">船名</view>
				<view class="right">{{detailData.qualityInspectionManagement.shipName}}</view>
			</view>
			<view v-if='detailData.outType=="散船"' class="row row-bottom">
				<view class="left">航次</view>
				<view class="right">{{detailData.qualityInspectionManagement.shipNumber}}</view>
			</view>
			<view v-if='detailData.outType=="火运"' class="row">
				<view class="left">车厢号-1</view>
				<view class="right">{{detailData.qualityInspectionManagement.wingNumber}}</view>
			</view>
			<view v-if='detailData.outType=="火运"' class="row row-bottom">
				<view class="left">车厢号-2</view>
				<view class="right">{{detailData.qualityInspectionManagement.wingNumberOther}}</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>
	import {
	    mapState 
	} from 'vuex';
	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.qualityInspectionManagement.carModel=='单拖小柜'){
				this.detailData.receivableWeighingFee=80
				this.detailData.actualWeighingFee=80
			}else if(this.detailData.qualityInspectionManagement.carModel=='双拖小柜'){
				this.detailData.receivableWeighingFee=160
				this.detailData.actualWeighingFee=160
			}else if(this.detailData.qualityInspectionManagement.carModel=='大柜'){
				if((this.detailData.grossWeight/1000)<50){
					this.$set(this.detailData,'receivableWeighingFee',120)
					this.detailData.actualWeighingFee=120
				}else if((this.detailData.grossWeight/1000)>50||(this.detailData.grossWeight/1000)<65){
					this.detailData.receivableWeighingFee=150
					this.detailData.actualWeighingFee=150
				}else if((this.detailData.grossWeight/1000)>65||(this.detailData.grossWeight/1000)<75){
					this.detailData.receivableWeighingFee=170
					this.detailData.actualWeighingFee=170
				}else if((this.detailData.grossWeight/1000)>75||(this.detailData.grossWeight/1000)<80){
					this.detailData.receivableWeighingFee=190
					this.detailData.actualWeighingFee=190
				}else if((this.detailData.grossWeight/1000)>80||(this.detailData.grossWeight/1000)<85){
					this.detailData.receivableWeighingFee=210
					this.detailData.actualWeighingFee=210
				}else if((this.detailData.grossWeight/1000)>85||(this.detailData.grossWeight/1000)<95){
					this.detailData.receivableWeighingFee=240
					this.detailData.actualWeighingFee=240
				}else if((this.detailData.grossWeight/1000)>95||(this.detailData.grossWeight/1000)<105){
					this.detailData.receivableWeighingFee=260
					this.detailData.actualWeighingFee=260
				}else if((this.detailData.grossWeight/1000)>105||(this.detailData.grossWeight/1000)<150){
					this.detailData.receivableWeighingFee=300
					this.detailData.actualWeighingFee=300
				}
			}else if(this.detailData.qualityInspectionManagement.carModel=='挂车'){
				if((this.detailData.grossWeight/1000)<50){
					this.detailData.receivableWeighingFee=180
					this.detailData.actualWeighingFee=180
				}else if((this.detailData.grossWeight/1000)>50||(this.detailData.grossWeight/1000)<65){
					this.detailData.receivableWeighingFee=200
					this.detailData.actualWeighingFee=200
				}else if((this.detailData.grossWeight/1000)>65||(this.detailData.grossWeight/1000)<75){
					this.detailData.receivableWeighingFee=250
					this.detailData.actualWeighingFee=250
				}else if((this.detailData.grossWeight/1000)>75||(this.detailData.grossWeight/1000)<85){
					this.detailData.receivableWeighingFee=350
					this.detailData.actualWeighingFee=350
				}else if((this.detailData.grossWeight/1000)>85||(this.detailData.grossWeight/1000)<95){
					this.detailData.receivableWeighingFee=400
					this.detailData.actualWeighingFee=400
				}else if((this.detailData.grossWeight/1000)>95||(this.detailData.grossWeight/1000)<105){
					this.detailData.receivableWeighingFee=450
					this.detailData.actualWeighingFee=450
				}else if((this.detailData.grossWeight/1000)>105||(this.detailData.grossWeight/1000)<120){
					this.detailData.receivableWeighingFee=500
					this.detailData.actualWeighingFee=500
				}else if((this.detailData.grossWeight/1000)>120||(this.detailData.grossWeight/1000)<130){
					this.detailData.receivableWeighingFee=550
					this.detailData.actualWeighingFee=550
				}else if((this.detailData.grossWeight/1000)>130||(this.detailData.grossWeight/1000)<150){
					this.detailData.receivableWeighingFee=700
					this.detailData.actualWeighingFee=700
				}
			}else if(this.detailData.qualityInspectionManagement.carModel=='冷藏箱（不抠箱）'){
				if((this.detailData.grossWeight/1000)<50){
					this.detailData.receivableWeighingFee=120
					this.detailData.actualWeighingFee=120
				}else if((this.detailData.grossWeight/1000)>50||(this.detailData.grossWeight/1000)<65){
					this.detailData.receivableWeighingFee=150
					this.detailData.actualWeighingFee=150
				}else if((this.detailData.grossWeight/1000)>65||(this.detailData.grossWeight/1000)<75){
					this.detailData.receivableWeighingFee=170
					this.detailData.actualWeighingFee=170
				}else if((this.detailData.grossWeight/1000)>75||(this.detailData.grossWeight/1000)<80){
					this.detailData.receivableWeighingFee=190
					this.detailData.actualWeighingFee=190
				}else if((this.detailData.grossWeight/1000)>80||(this.detailData.grossWeight/1000)<85){
					this.detailData.receivableWeighingFee=210
					this.detailData.actualWeighingFee=210
				}else if((this.detailData.grossWeight/1000)>85||(this.detailData.grossWeight/1000)<95){
					this.detailData.receivableWeighingFee=240
					this.detailData.actualWeighingFee=240
				}else if((this.detailData.grossWeight/1000)>95||(this.detailData.grossWeight/1000)<105){
					this.detailData.receivableWeighingFee=260
					this.detailData.actualWeighingFee=260
				}else if((this.detailData.grossWeight/1000)>105||(this.detailData.grossWeight/1000)<120){
					this.detailData.receivableWeighingFee=300
					this.detailData.actualWeighingFee=300
				}
			}else if(this.detailData.qualityInspectionManagement.carModel=='冷藏箱（抠箱）'){
				if((this.detailData.grossWeight/1000)<50){
					this.detailData.receivableWeighingFee=360
					this.detailData.actualWeighingFee=360
				}else if((this.detailData.grossWeight/1000)>50||(this.detailData.grossWeight/1000)<65){
					this.detailData.receivableWeighingFee=390
					this.detailData.actualWeighingFee=390
				}else if((this.detailData.grossWeight/1000)>65||(this.detailData.grossWeight/1000)<75){
					this.detailData.receivableWeighingFee=410
					this.detailData.actualWeighingFee=410
				}else if((this.detailData.grossWeight/1000)>75||(this.detailData.grossWeight/1000)<80){
					this.detailData.receivableWeighingFee=430
					this.detailData.actualWeighingFee=430
				}else if((this.detailData.grossWeight/1000)>80||(this.detailData.grossWeight/1000)<85){
					this.detailData.receivableWeighingFee=450
					this.detailData.actualWeighingFee=450
				}else if((this.detailData.grossWeight/1000)>85||(this.detailData.grossWeight/1000)<95){
					this.detailData.receivableWeighingFee=480
					this.detailData.actualWeighingFee=480
				}else if((this.detailData.grossWeight/1000)>95||(this.detailData.grossWeight/1000)<105){
					this.detailData.receivableWeighingFee=500
					this.detailData.actualWeighingFee=500
				}else if((this.detailData.grossWeight/1000)>105||(this.detailData.grossWeight/1000)<120){
					this.detailData.receivableWeighingFee=540
					this.detailData.actualWeighingFee=540
				}
			}else {
				this.detailData.receivableWeighingFee=''
			}
			if (!this.detailData.buckleMiscellaneous) {
				this.detailData.buckleMiscellaneous = 0
			}
		},
		computed: {
			...mapState(['hasLogin', 'userInfo']),
		},
		methods: {
			changeInput() {
				this.detailData.netWeight = (parseFloat(this.detailData.grossWeight) - parseFloat(this.detailData.tare) -
					parseFloat(this.detailData.buckleMiscellaneous)).toFixed(3)
			},
			submit() {
				if (this.detailData.qualityInspectionManagement.confirm==0) {
					this.$refs.uToast.show({
						title: '该条质检信息未确认',
						type: 'error'
					})
				    return
				}
				let that = this;
				uni.showModal({
					content: "确定提交检斤信息?",
					success() {
						if(that.detailData.serviceManagementType==1){
							// that.$api.doRequest('post', '/weighingManagement/api/editTare',that.detailData).then(res => {
								that.$api.doRequest('get', '/warehouseInOutInfo/getInfo',
								{id:that.detailData.warehouseInOutId}).then(res => {
									var data=res.data.data
									data.statusFlag=3
									data.inOutFlag=2
									data.secretaryWeigher=that.userInfo.userName;
									data.warehouseType=that.detailData.warehouseType
									// data.baseId=that.detailData.warehouseInOutId
									data.grossWeight=that.detailData.grossWeight/1000
									data.tare=that.detailData.tare/1000
									data.netWeight=that.detailData.netWeight/1000
									data.deductionAmount=that.detailData.deductionAmount*1000
									data.deductionWeight=that.detailData.deductionWeight/1000
									data.weighingManagement=JSON.parse(JSON.stringify(that.detailData))
									that.$api.doRequest('post',
									'/warehouseInOutInfo/api/newInOutWarehouse', data).then(res => {
										if (res.data.code == 200) {
											that.$refs.uToast.show({
												title: '提交成功',
												type: 'success'
											})
											uni.navigateBack({delta:1})
										} else {
											that.$refs.uToast.show({
												title: '提交失败',
												type: 'error',
											})
										}
										})
									})
								// })
						}else{
							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({delta:1})
													} 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>
