<template>
	<view class="warp">
		<view class="title">
			基本信息
		</view>
		<view class="content">
			<view class="row">
				<view class="left">入库类型</view>
				<view class="right" v-if='detailData.serviceManagementType==3'>收购入库</view>
				<view class="right" v-if='detailData.serviceManagementType==1'>贸易入库</view>
			</view>
			<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">
				<view class="left">运输方式</view>
				<view class="right">{{detailData.outType}}</view>
			</view>
			<view class="row">
				<view class="left">箱号-1</view>
				<view class="right">{{detailData.qualityInspectionManagement.boxNo}}</view>
			</view>
			<view class="row">
				<view class="left">箱号-2</view>
				<view class="right">{{detailData.qualityInspectionManagement.boxNoOther}}</view>
			</view>
			<view class="row">
				<view class="left">封号-1</view>
				<view class="right">{{detailData.qualityInspectionManagement.titleNo}}</view>
			</view>
			<view class="row">
				<view class="left">封号-2</view>
				<view class="right">{{detailData.qualityInspectionManagement.titleNoOther}}</view>
			</view>
			<view class="row row-bottom">
				<view class="left">毛重（公斤）</view>
				<input class="right-bottom" placeholder="输入毛重" v-model="detailData.grossWeight"></input>
			</view>
		</view>
		<u-button v-if='tabbar' type="primary" class="submit" @click="submit">提交</u-button>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				tabbar: true,
				windowHeight: '',
				detailData: {
					grossWeight: ''
				},
				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) {
			uni.onWindowResize((res) => {
				if (res.size.windowHeight < this.windowHeight) {
					this.tabbar = false
				} else {
					this.tabbar = true
				}
			})
			this.detailData = JSON.parse(options.detailData)
			console.log(this.detailData)
			uni.getSystemInfo({
				success: (res) => {
					this.windowHeight = res.windowHeight;
					// console.log(res)
					this.system = res.system // ios
					this.platform = res.platform // 14.3
				}
			})
			console.log(this.detailData)
		},
		methods: {
			submit() {
			
				let that = this
				uni.showModal({
					content: "确定提交检斤信息?",
					success: function(res) {
						if (res.confirm) {
		
							if(that.detailData.serviceManagementType==1){
								that.$api.doRequest('post',
									'/weighingManagement/api/editGrossWeight', that
									.detailData).then(res => {
								that.detailData.inOutFlag = 2
								that.detailData.statusFlag=1
								that.detailData.grossWeight=that.detailData.grossWeight/1000
								that.detailData.warehouseInOutDetail={
									id:that.detailData.inOutDetailId,
									grade:that.detailData.qualityInspectionManagement.grade,
									reGrade:that.detailData.qualityInspectionManagement.reGrade,
									imperfectGrain:that.detailData.qualityInspectionManagement.imperfectGrain,
									reImperfectGrain:that.detailData.qualityInspectionManagement.reImperfectGrain,
									impurity:that.detailData.qualityInspectionManagement.impurity,
									reImpurity:that.detailData.qualityInspectionManagement.reImpurity,
									jiaorenli:that.detailData.qualityInspectionManagement.jiaorenli,
									reJiaorenli:that.detailData.qualityInspectionManagement.reJiaorenli,
									bulkDensity:that.detailData.qualityInspectionManagement.bulkDensity,
									reBulkDensity:that.detailData.qualityInspectionManagement.reBulkDensity,
									mildewGrain:that.detailData.qualityInspectionManagement.mildewGrain,
									reMildewGrain:that.detailData.qualityInspectionManagement.reMildewGrain,
								},
								that.$api.doRequest('post',
									'/warehouseInOutInfo/InOutWarehouse', 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',
											})
										}
										})
									})
							}else{
								that.$api.doRequest('get', '/paymentManagement/cumulant', {
									// compId: JSON.parse(localStorage.getItem('pcUserInfo')).data.compId,
									compId: uni.getStorageSync('pcUserInfo').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 (Number(count) - that.detailData.grossWeight / 1000 <= 0) {
													that.$api.msg('该客户累计销售' + that.detailData.goodsName + (
															res.data.data / 1000).toFixed(2) +
														'吨，还可售粮' +
														count + '吨', )
								
												} else {
													that.$api.doRequest('post',
														'/weighingManagement/api/editGrossWeight', 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',
																})
															}
													})
								
												}
											}
										}
									}
								})
							}
							
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				})
			}
		}
	}
</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 {
		margin-bottom:50px;
		.row {
			display: flex;
			justify-content: space-between;
			padding: 31rpx 0;

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

		.row-bottom {
			border: 0;

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

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

	}
</style>
