<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">
					<view @click='show4=true'>{{detailData.inOutTaskNo?detailData.inOutTaskNo:'请选择任务编号'}}</view>
					<u-picker :range="taskNolist" range-key="inOutTaskNo" @confirm='tasknopicker($event)' v-model="show4"
						mode="selector">
					</u-picker>
				</view>
			</view>
			<view v-if="detailData.inOutType=='移库出库'" class="row">
				<view class="left">移库编号</view>
				<view>{{detailData.contractNo?detailData.contractNo:'请选择移库编号'}}</view>
				<!-- <view @click='show=true'>{{detailData.contractNo?detailData.contractNo:'请选择合同编号'}}</view> -->
				<u-picker :range="contractNoList" range-key="contractNo" @confirm='contractNopicker($event)' v-model="show" mode="selector" >
				</u-picker>
			</view>
			<view v-else class="row">
				<view class="left">合同编号</view>
				<view>{{detailData.contractNo?detailData.contractNo:'请选择合同编号'}}</view>
				<!-- <view @click='show=true'>{{detailData.contractNo?detailData.contractNo:'请选择合同编号'}}</view> -->
				<u-picker :range="contractNoList" range-key="contractNo" @confirm='contractNopicker($event)' v-model="show" mode="selector" >
				</u-picker>
			</view>
			<view style=' align-items: flex-start;' class="row">
				<view class="left">提示</view>
				<view class="right">
					{{detailData.tips?detailData.tips:'自动获取，不可编辑'}}
				</view>
			</view>
			<view class="row">
				<view class="left">货名</view>
				<view class="right">{{detailData.goodsName}}</view>
			</view>
			
			<view class="row">
				<view class="left">仓位号</view>
				<view @click='show1=true'>{{detailData.binNumber?detailData.binNumber:'请选择仓位号'}}</view>
				<u-picker :range="positionList" range-key="binNumber" @confirm='binNumberpicker($event)' v-model="show1" mode="selector" >
				</u-picker>
			</view>
			<view class="row" style="text-align: right;">
				<view class="left">囤位号</view>
				<input class="right-bottom" v-model='detailData.storageNumber' placeholder="输入囤位号"></input>
			</view>
			<view class="row row-bottom" @click="issueTypeClick">
				<view class="left">出库类型</view>
				<view class="right">{{issueTypeVal}}></view>
			</view>
			<view class="row ">
				<view class="left">出库日期</view>
				<view class="right">
					<view @click='show5=true'>{{detailData.inOutDate?detailData.inOutDate:'请选择出库日期'}}</view>
					<u-picker  @confirm='inOutDatepicker($event)' :params="params" v-model="show5"
						mode="time">
					</u-picker>
				</view>
			</view>
			<view class="row ">
				<view class="left">运输方式</view>
				<view class="right">
					<view @click='show7=true'>{{detailData.outType?detailData.outType:'请选择运输方式'}}</view>
					<u-picker :range="multiSelector" range-key="name" @confirm='outtypepicker($event)' v-model="show7"
						mode="selector">
					</u-picker>
				</view>
			</view>
			<view v-if='detailData.outType=="汽运"||detailData.outType=="集装箱船"' class="row" style="text-align: right;">
				<view class="left">车牌号</view>
				<input v-model='detailData.carNumber' class="right-bottom" placeholder="输入车牌号"></input>
			</view>
			<view v-if='detailData.outType=="汽运"||detailData.outType=="集装箱船"' class="row" style="text-align: right;">
				<view class="left">箱号-1</view>
				<view class="right">
					<input v-model='detailData.boxNo' placeholder="请输入箱号" name="input" type="digit"></input>
				</view>
			</view>
			<view v-if='detailData.outType=="汽运"||detailData.outType=="集装箱船"' class="row" style="text-align: right;">
				<view class="left">封号-1</view>
				<view class="right">
					<input v-model='detailData.titleNo' placeholder="请输入封号" name="input" type="digit"></input>
				</view>
			</view>
			<view v-if='detailData.outType=="汽运"||detailData.outType=="集装箱船"' class="row" style="text-align: right;">
				<view class="left">箱号-2</view>
				<view class="right">
					<input v-model='detailData.boxNoOther' placeholder="请输入箱号" name="input" type="digit"></input>
				</view>
			</view>
			<view v-if='detailData.outType=="汽运"||detailData.outType=="集装箱船"' class="row" style="text-align: right;">
				<view class="left">封号-2</view>
				<view class="right">
					<input v-model='detailData.titleNoOther' placeholder="请输入封号" name="input" type="digit"></input>
				</view>
			</view>
			<view v-if='detailData.outType=="散船"' class="row" style="text-align: right;">
				<view class="left">船名</view>
				<view class="right">
					<input v-model='detailData.shipName' placeholder="请输入船名" name="input" type="digit"></input>
				</view>
			</view>
			<view v-if='detailData.outType=="散船"' class="row" style="text-align: right;">
				<view class="left">航次</view>
				<view class="right">
					<input v-model='detailData.shipNumber' placeholder="请输入航次" name="input" type="digit"></input>
				</view>
			</view>
			<view v-if='detailData.outType=="火运"' class="row" style="text-align: right;">
				<view class="left">车厢号-1</view>
				<view class="right">
					<input v-model='detailData.wingNumber' placeholder="请输入车厢号" name="input" type="digit"></input>
				</view>
			</view>
			<view v-if='detailData.outType=="火运"' class="row" style="text-align: right;">
				<view class="left">车厢号-2</view>
				<view class="right">
					<input v-model='detailData.wingNumberOther' placeholder="请输入车厢号" name="input" type="digit"></input>
				</view>
			</view>
		</view>
		<div class="content1">
			<view class="title">
				检斤信息
			</view>
			<view class="row row-bottom">
				<view class="left">皮重（公斤）</view>
				<input class="right-bottom" v-model="detailData.tare" placeholder="输入皮重"></input>
			</view>
		</div>
		<!-- <u-select v-model="isShowContractNo" :list="contractNoList" @confirm="confirmContractNo"></u-select> -->
		<u-select v-model="isShowBinNo" :list="binNoList" @confirm="confirmBinNo"></u-select>
		<u-select v-model="isShowIssueType" :list="issueTypeList" @confirm="confirmIssueTypeNo"></u-select>
		
		<view class='footer'>
			<u-button type="primary" class="submit" @click="submit">提交</u-button>
		</view>

	</view>
</template>

<script>
	import helper from '@/common/helper.js'; 
	export default {
		data() {
			return {
				// isShowContractNo: false,
				isShowBinNo: false,
				isShowIssueType: false,
				issueTypeVal: "销售出库",
				detailData: {},
				id:'',
				cangId:'',
				show1:false,
				show:false,
				show4:false,
				show5:false,
				show7:false,
				contractNoList: [],
				positionList:[],
				binNoList: [],
				taskNolist:[],
				params:{year: true,
					month: true,
					day: true,},
				multiSelector: [{
				            name: '汽运',
				            value: '0',
				          },
				          {
				            name: '火运',
				            value: '1',
				          },
				          {
				            name: '集装箱船',
				            value: '2',
				          },
				          {
				            name: '散船',
				            value: '3',
				          },
				],
				issueTypeList: [{
						value: '1',
						label: '销售出库'
					},
					{
						value: '2',
						label: '移库出库'
					},
					{
						value: '3',
						label: '暂存出库'
					},
					{
						value: '4',
						label: '贸易服务出库'
					},
				]
			}
		},
		onShow() {},
		onLoad(options) {
			this.cangId = options.cangId
			console.log(options)
			this.detailData.warehouseName = options.warehouseName
			this.getWeighingManagement()
		},
		methods: {
			outtypepicker(e){
				this.detailData.outType=this.multiSelector[e[0]].name
			},
			inOutDatepicker(e){
				this.detailData.inOutDate=e.year+'-'+e.month+'-'+e.day
				console.log(e)
			},
			tasknopicker(e){
				console.log(e)
				this.detailData.inOutTaskNo=this.taskNolist[e[0]].inOutTaskNo
				var data = this.taskNolist[e[0]]
				if (this.taskNolist[e[0]].contractNo) {
					this.detailData.contractNo = this.taskNolist[e[0]].contractNo
				}else {
					this.detailData.contractNo = this.taskNolist[e[0]].moveTaskNo
				}
				for (let i = 0; i < this.contractNoList.length; i++) {
					
					if(this.detailData.contractNo==this.contractNoList[i].contractNo){
						this.detailData.goodsName = this.contractNoList[i].goodsName
						this.detailData.goodsNameKey = this.contractNoList[i].goodsNameKey
						this.detailData.grade = this.contractNoList[i].grade
						this.detailData.inOutType = this.contractNoList[i].inOutType
						if(this.detailData.inOutType=='销售出库'){
							this.warehouseTradeCount = '000' + this.warehouseTradeCount
							this.detailData.qualityNo='XSCK'+this.getdate()+this.commonWarehouseNo+this.warehouseTradeCount.substring(this.warehouseTradeCount.length - 4)
							if (!this.contractNoList[i].unitContractPrice) {
								this.detailData.tips = '买方' + this.contractNoList[i].seller
							} else {
								this.detailData.tips ='买方' +this.contractNoList[i].seller +'（ ' + this.contractNoList[i].unitContractPrice +'元/吨）'
							}
							
							this.detailData.inOutTypeKey = 1
						}else if(this.detailData.inOutType=='移库出库'){
							this.warehouseTradeCount = '000' + this.warehouseTradeCount
							this.detailData.qualityNo='YKCK'+this.getdate()+this.commonWarehouseNo+this.warehouseTradeCount.substring(this.warehouseTradeCount.length - 4)
							if (this.contractNoList[i].unitContractPrice) {
								this.detailData.tips ='入货库' +data.sendWarehouse +' （' +this.contractNoList[i].unitContractPrice +'元/吨）'
							} else {
								this.detailData.tips = '入货库' + data.sendWarehouse
							}
							this.detailData.inOutTypeKey = 3
						}else if (this.contractNoList[i].inOutType == '暂存入库') {
							this.detailData.inOutTypeKey = 4
						} else if (this.contractNoList[i].inOutType == '贸易服务出库') {
							this.detailData.inOutTypeKey = 5
						} else if (this.contractNoList[i].inOutType == '采购出库') {
							this.detailData.inOutTypeKey = 6
						}
						 this.cost = this.contractNoList[i].contractPrice
						if (this.cost) {
							this.isGetCost = true
							this.detailData.cost =this.cost - this.detailData.deductionAmount
						} else {
							this.isGetCost = false
							this.detailData.cost = this.detailData.cost
						}
						if (this.contractNoList[i].inOutType == '移库入库') {
							this.isSelectType = false
						} else {
							this.isSelectType = true
						}
						if (this.contractNoList[i].priceType == '随行就市') {
							this.disabled1 = !this.disabled1
						}
						if (this.contractNoList[i].deliverType == '1') {
							this.carstatus = true
						} else {
							this.carstatus = false
						}
						if (this.contractNoList[i].tranCarInfoList) {
							this.tranCarInfoList = this.contractNoList[i].tranCarInfoList
						              // this.carstatus = true
						}else{
							this.options2 =[]
						}
						this.fleetNameList=this.contractNoList[i].tranCarInfoList1
					}
					
				}
				console.log(this.gridList)
			},
			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(){
				console.log(this.cangId)
					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', '/inOutWarehouseTask/selectInOutWarehouseNo', {
						flag: 1,
						warehouseName:this.detailData.warehouseName
					}).then(res => {
						console.log(res)
						this.taskNolist=res.data.data
					})
					this.multiSelector1=[]
					this.$api.doRequest('get', '/inOutWarehouseTask/getContractNo', {
						warehouseName:this.detailData.warehouseName
					}).then(res => {
						// console.log(res)
						if(res.data.data.contractManagementInfoList){
							for (let i = 0; i < res.data.data.contractManagementInfoList.length; i++) {
								res.data.data.contractMangementInfoList[i].name='自运 （'+
								res.data.data.contractMangementInfoList[i].contractNo+' '+res.data.data.contractMangementInfoList[i].seller+'）'
								this.multiSelector1.push(res.data.data.contractManagementInfoList[i])
							}
						}
						// this.taskNolist=res.data.data
					})
					this.$api.doRequest('get', '/warehouseBaseInfo/selectContractNoList',{
						compId: '',
						flag:5
						}).then(res => {
						if(res.data.code==200){
						this.contractNoList = res.data.data
						}
					})
			},
			contractNoClick() {
				uni.navigateTo({
					url:"selectContractNo?compId="+this.detailData.compId
				})
			},
			issueTypeClick() {
				this.isShowIssueType = true
			},
			confirmContractNo(e) {},
			confirmBinNo(e) {},
			confirmIssueTypeNo(e) {
				console.log(e)
				this.detailData.inOutType=e[0].label
				this.issueTypeVal = e[0].label
			},
			submit(){
				if (!this.detailData.contractNo) {
					this.$api.msg('合同编号不能为空')
					return
				}
				if (!this.detailData.binNumber) {
					this.$api.msg('仓位号不能为空')
					return
				}
				if (!this.detailData.storageNumber) {
					this.$api.msg('囤位号不能为空')
					return
				}
				if (
					this.detailData.storageNumber.length < 1 ||
					this.detailData.storageNumber.length > 10
				) {
					this.$api.msg('囤位号不超过10个字符！')
					return
				}
				if (!this.detailData.carNumber) {
					this.$api.msg('车牌号不能为空')
					return
				}
				if (this.detailData.carNumber.length != 7) {
					this.$api.msg('车牌号输入错误')
					return
				}
				if (!this.detailData.inOutType) {
					this.$api.msg('出库类型不能为空')
					return
				}
				var that = this
				uni.showModal({
					content:"确定提交检斤信息?",
					success(res) {
						if(res.confirm){
							that.$api.doRequest('post', '/weighingManagement/api/editTareOut',
							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: 20rpx;
	}

	.content,
	.content1 {
		border-radius: 20rpx;
		background: white;
		padding: 20rpx;

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

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

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

		.row-bottom {
			border: 0;

			.right-bottom {
				width: 300rpx;
				text-align: right;
			}
		}
	}

	.content1 {
		margin-top: 20rpx;
	}
	.footer{
		position: fixed;
		bottom:0;
		width:100%;
		padding:10px;
		background:#fff;
		.submit {
			width: 90%;
			background: #22C572;
			border-radius: 50rpx;
		}
	}
	
	.row input{
		font-size:14px;
	}
</style>
