<template>
	<view class="warp">
		<view class="content">
				<view class="title">
					基本信息
				</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.contractNo}}</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.qualityInspectionManagement.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.inOutType}}</view>
			</view>
			<view class="row">
				<view class="left">货名</view>
				<view class="right">{{detailData.goodsName}}</view>
			</view>
		</view>
		<view class="content1">
			<view class="title">
				检斤信息
			</view>
			<view class="row row-bottom">
				<view class="left">皮重（公斤）</view>
				{{detailData.tare}}
			</view>
			<view class="row row-bottom">
				<view class="left">毛重（公斤）</view>
				<input @input='calculate' v-model='detailData.grossWeight' class="right-bottom" placeholder="输入毛重"></input>
			</view>
			<view class="row row-bottom" style="border: 0;">
				<view class="left">净重（公斤）</view>
				<input v-model='detailData.netWeight' class="right-bottom" disabled placeholder="自动计算"></input>
			</view>
		</view>
		<view class="content2">
			<view class="left">上传磅单</view>
			<upload class="upload" ref="upload" :action="action" :max-size="maxSize" :max-count="1"
				:size-type="['compressed']" @on-success="getImgUrl" @on-error="onError" @on-remove="onRemove"
				@on-uploaded="isAdd = true" :before-upload="filterFileType" @on-progress="onProgress"></upload>
		</view>
		<u-toast ref="uToast"/>
		<u-button type="primary" class="submit" @click="submit">提交</u-button>

	</view>
</template>

<script>
	import upload from '@/components/upload.vue';
	export default {
		components: {
			upload
		},
		data() {
			return {
				action: this.$uploadUrl,
				maxSize: 50 * 1024 * 1024, //限制文件大小 50M
				btnLoading: false, //防止重复点击
				isAdd: true,
				detailData: {
					name: "",
					qualityInspectionManagement:{}
				}
			}
		},
		onLoad(options) {
			this.id = options.id
			this.cangId = options.cangId
		},
		onShow() {
			this.getWeighingManagement()
		},
		methods: {
			filterFileType(index, lists) {
				if (lists[index].fileType != 'jpg' && lists[index].fileType != 'png' && lists[index].fileType != 'gif') {
					lists.splice(index, 1);
					// 当前文件不支持
					uni.showModal({
						title: '暂不支持当前图片类型',
						showCancel: false
					});
				} else {
					this.isAdd = false;
				}
			},
			calculate(){
				this.detailData.netWeight=this.detailData.grossWeight-this.detailData.tare
			},
			getImgUrl(res) {
				this.detailData.addressUrl=res
				console.log(res)
				console.log('------------res-----------')
			},
			onError(error) {
				alert(error)
				console.log('------------error-----------')
				console.log(error)
			},
			contractNopicker(e){
				this.detailData.goodsName=this.contractNoList[e[0]].goodsName
				this.detailData.contractNo=this.contractNoList[e[0]].contractNo
			},
			binNumberpicker(e){
				this.detailData.binNumber=this.positionList[e[0]].binNumber
			},
			getWeighingManagement(){
					this.$api.doRequest('get', '/weighingManagement/getWeighingManagement',
					{id: this.id}).then(res => {
						if(res.data.code==200){
						console.log(res)
						this.detailData = res.data.data
						}
					})
					this.$api.doRequest('get', '/warehouseBaseInfo/getWarehouse',
					{id: this.cangId}).then(res => {
						if(res.data.code==200){
						this.positionList = res.data.data.warehousePositionInfoList
						}
					})
					this.$api.doRequest('get', '/warehouseBaseInfo/selectContractNoList',{
						compId: '',
						flag:5
						}).then(res => {
						if(res.data.code==200){
						this.contractNoList = res.data.data
						}
					})
			},
			onProgress(e) {
				console.log(e)
			},
			onRemove(index) {},
			submit(){
				if (!this.detailData.grossWeight) {
					this.$api.msg('毛重不能为空')
					return
				}
				if (isNaN(this.detailData.grossWeight) ||
					(String(this.detailData.grossWeight).indexOf('.') != -1 &&
					String(this.detailData.grossWeight).length -
					(String(this.detailData.grossWeight).indexOf('.') + 1) >
					1) ||
					this.detailData.grossWeight < 1 ||
					this.detailData.grossWeight > 100000
				) {
					this.$api.msg('毛重输入错误！')
					return
				}
				let that = this
				uni.showModal({
					content:"确定提交检斤信息?",
					success(res) {
						if(res.confirm){
							that.$api.doRequest('post', '/weighingManagement/api/editGrossWeight',
							that.detailData).then(res => {
								if(res.data.code==200){
								that.$api.msg('提交成功')
								uni.navigateBack()
								}
							})
						}
						
					}
				})
			}
		}
	}
</script>

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

	.warp {
		margin: 10rpx;
		padding: 20rpx 20rpx 140rpx 20rpx;
	}

	.content,
	.content1,
	.content2
	{
		border-radius: 20rpx;
		background: white;
		padding: 20rpx;
		.title{
			font-size: 28rpx;
			font-weight: 600;
			color: #333333;
		}
		.row {
			display: flex;
			justify-content: space-between;
			padding: 21rpx 0;

			.right,input {
				font-size: 28rpx;
				color: #333333;
			}
		}

		.row-bottom {

			// border: 0;
			.right-bottom {
				width: 300rpx;
				text-align: right;
			}
		}
	}
	.content1{
		margin-top: 20rpx;
	}
	.content2{
		margin-top: 10px;
		display: flex;
		align-items: center;
		.left{
			margin-right: 20px;
		}
	}

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

	}
</style>
