<template>
	<view class="warp">
		<view class="content1">
			<u-form :model="purchaseOrder" ref="uForm" class="uForm">
				<u-form-item label="任务类型" prop="receivingAddress" label-width="140">
					<u-input v-model="OutList.inOutType" input-align="right" placeholder="" disabled />
				</u-form-item>
				<!-- <view v-if="type=='移库'" class="title part2">移库出库</view>
				<view v-if="type=='退库'" class="title part2">退库</view> -->
				<view v-if="OutList.judge == 1">
					<!-- 出库 -->
					<view class="title part2">{{OutList.inOutType}}</view>
					<view class='row'>
						<view class="left">编号</view>
						<view class="right">{{OutList.inOutType}} {{OutList.inOutTaskNo}}</view>
					</view>
					<view class='row'>
						<view class="left">仓库</view>
						<view class="right">{{OutList.sendWarehouse}}</view>
					</view>
					<view class='row'>
						<view class="left">出库类型</view>
						<view class="right">{{OutList.inOutType}}</view>
					</view>
				<!-- <view class='row'>
						<view class="left">出库类型</view>
						<view class="right">{{OutList.inOutType}}</view>
					</view> -->
					<view class='row' v-if="OutList.inOutType == '移库出库'">
						<view class="left">移库任务编号</view>
						<view class="right">{{OutList.moveTaskNo}}</view>
					</view>
					<view class='row' v-if="OutList.inOutType != '移库出库'">
						<view class="left">合同编号</view>
						<view class="right">{{OutList.contractNo}}</view>
					</view>
					<view class='row'>
						<view class="left">货名</view>
						<view class="right">{{OutList.goodsName}}</view>
					</view>
					<view class='row'>
						<view class="left">重量(吨)</view>
						<view class="right">{{OutList.weight}}</view>
					</view>
					<view class='row'>
						<view class="left">预计出库日期</view>
						<view class="right">{{OutList.predictDate}}</view>
					</view>
					<!-- 	<view class='row'>
					<view class="left">预计入库日期</view>
					<view class="right">{{OutList.inOutDate}}</view>
				</view> -->
					<view class='row'>
						<view class="left">出库经办人</view>
						<view class="right">{{OutList.publisher}}</view>
					</view>
					<view class="title part2">可编辑项</view>
					<u-form-item label="品级" prop="grade" label-width="150">
						<u-input v-model="OutList.grade" input-align="right" placeholder="" @click='show=true'
							disabled />
						<u-picker :range="pjList" range-key="type" @confirm='pjPicker($event)' v-model="show"
							mode="selector">
						</u-picker>
					</u-form-item>
					<u-form-item label="容重(克/升)>=" prop="bulkDensity" label-width="190">
						<u-input v-model="OutList.bulkDensity" input-align="right" placeholder="" />
					</u-form-item>
					<u-form-item label="水分(%)<=" prop="waterContent" label-width="160">
						<u-input v-model="OutList.waterContent" input-align="right" placeholder="" />
					</u-form-item>
					<u-form-item label="单价(元/吨)" prop="unitPrice" label-width="160">
						<u-input v-model="OutList.unitPrice" input-align="right" placeholder="" />
					</u-form-item>
					<u-form-item v-if="type!='移库'&&type!='退库'" label="业务描述" prop="businessDescribe" label-width="160"
						label-position="top">
						<u-input v-model="OutList.businessDescribe" input-align="left" placeholder="" type="textarea"
							class="textarea" />
					</u-form-item>
					<u-form-item v-if="type!='退库'" label="仓位号(选填)" prop="binNumber" label-width="170">
						<u-input v-model="OutList.binNumber" input-align="right" placeholder="未指定" />
					</u-form-item>
				</view>
				<view v-if="EnterList.judge == 2">
					<!-- 入库 -->
					<view class="title part2">{{EnterList.inOutType}}</view>
					<view class='row'>
						<view class="left">编号</view>
						<view class="right">{{EnterList.inOutType}} {{EnterList.inOutTaskNo}}</view>
					</view>
					<view class='row'>
						<view class="left">仓库</view>
						<view class="right">{{EnterList.warehouseName}}</view>
					</view>
					<view class='row'>
						<view class="left">入库类型</view>
						<view class="right">{{EnterList.inOutType}}</view>
					</view>
					<view class='row' v-if="EnterList.inOutType == '移库入库'">
						<view class="left">移库任务编号</view>
						<view class="right">{{EnterList.moveTaskNo}}</view>
					</view>
					<view class='row' v-if="EnterList.inOutType != '移库入库'">
						<view class="left">合同编号</view>
						<view class="right">{{EnterList.contractNo}}</view>
					</view>
					<view class='row'>
						<view class="left">货名</view>
						<view class="right">{{EnterList.goodsName}}</view>
					</view>
					<view class='row'>
						<view class="left">重量(吨)</view>
						<view class="right">{{EnterList.weight}}</view>
					</view>
					<view class='row'>
						<view class="left">预计入库日期</view>
						<view class="right">{{EnterList.predictDate}}</view>
					</view>
					<view class='row'>
						<view class="left">出库经办人</view>
						<view class="right">{{EnterList.publisher}}</view>
					</view>
					<view class="title part2">可编辑项</view>
					<u-form-item label="品级" prop="grade" label-width="150">
						<u-input v-model="EnterList.grade" input-align="right" placeholder="" @click='show=true'
							disabled />
						<u-picker :range="pjList" range-key="type" @confirm='pjPicker1($event)' v-model="show"
							mode="selector">
						</u-picker>
					</u-form-item>
					<u-form-item label="容重(克/升)>=" prop="bulkDensity" label-width="190">
						<u-input v-model="EnterList.bulkDensity" input-align="right" placeholder="" />
					</u-form-item>
					<u-form-item label="水分(%)<=" prop="waterContent" label-width="160">
						<u-input v-model="EnterList.waterContent" input-align="right" placeholder="" />
					</u-form-item>
					<u-form-item label="单价(元/吨)" prop="unitPrice" label-width="160">
						<u-input v-model="EnterList.unitPrice" input-align="right" placeholder="" />
					</u-form-item>
					<u-form-item v-if="type!='移库'&&type!='退库'" label="业务描述" prop="businessDescribe" label-width="160"
						label-position="top">
						<u-input v-model="EnterList.businessDescribe" input-align="left" placeholder="" type="textarea"
							class="textarea" />
					</u-form-item>
					<u-form-item v-if="type!='退库'" label="仓位号(选填)" prop="binNumber" label-width="170">
						<u-input v-model="EnterList.binNumber" input-align="right" placeholder="未指定" />
					</u-form-item>
				</view>
				<!-- <view v-if="type=='移库'">
					<view class="title part2">移库入库</view>
					<u-form-item label="编号" prop="receivingAddress" label-width="140">
						<u-input v-model="purchaseOrder.receivingAddress" input-align="right" placeholder="" disabled/>
					</u-form-item>
					<u-form-item label="仓库" prop="receivingAddress" label-width="140">
						<u-input v-model="purchaseOrder.receivingAddress" input-align="right" placeholder="" disabled/>
					</u-form-item>
					<u-form-item label="入库类型" prop="receivingAddress" label-width="140">
						<u-input v-model="purchaseOrder.receivingAddress" input-align="right" placeholder="" disabled/>
					</u-form-item>
					<u-form-item label="移库任务编号" prop="receivingAddress" label-width="180">
						<u-input v-model="purchaseOrder.receivingAddress" input-align="right" placeholder="" disabled/>
					</u-form-item>
					<u-form-item label="货名" prop="receivingAddress" label-width="140">
						<u-input v-model="purchaseOrder.receivingAddress" input-align="right" placeholder="" disabled/>
					</u-form-item>
					<u-form-item label="重量(吨)" prop="receivingAddress" label-width="140">
						<u-input v-model="purchaseOrder.receivingAddress" input-align="right" placeholder="" disabled/>
					</u-form-item>
					<u-form-item label="预计入库时间" prop="receivingAddress" label-width="180">
						<u-input v-model="purchaseOrder.receivingAddress" input-align="right" placeholder="" disabled/>
					</u-form-item>
					<u-form-item label="入库经办人" prop="receivingAddress" label-width="150">
						<u-input v-model="purchaseOrder.receivingAddress" input-align="right" placeholder="" disabled/>
					</u-form-item>
					<u-form-item label="品级" prop="receivingAddress" label-width="150">
						<u-input v-model="purchaseOrder.receivingAddress" input-align="right" placeholder="" @click='show=true' disabled/>
						<u-picker :range="pjList" range-key="type" @confirm='pjPicker($event)' v-model="show" mode="selector">
						</u-picker>
					</u-form-item>
					<u-form-item label="容重(克/升)>=" prop="receivingAddress" label-width="190">
						<u-input v-model="purchaseOrder.receivingAddress" input-align="right" placeholder=""/>
					</u-form-item>
					<u-form-item label="水分(%)<=" prop="receivingAddress" label-width="160">
						<u-input v-model="purchaseOrder.receivingAddress" input-align="right" placeholder=""/>
					</u-form-item>
					<u-form-item label="单价(元/吨)" prop="receivingAddress" label-width="160">
						<u-input v-model="purchaseOrder.receivingAddress" input-align="right" placeholder=""/>
					</u-form-item>
					<view class="title part2">可编辑项</view>
					<u-form-item label="业务描述" prop="receivingAddress" label-width="160" label-position="top">
						<u-input v-model="purchaseOrder.receivingAddress" input-align="left" placeholder="" type="textarea" class="textarea"/>
					</u-form-item>
					<u-form-item label="仓位号(选填)" prop="receivingAddress" label-width="170">
						<u-input v-model="purchaseOrder.receivingAddress" input-align="right" placeholder="未指定"/>
					</u-form-item>
				</view>
				<view v-if="type=='退库'">
					<view class="title part2">出</view>
					<u-form-item label="编号" prop="receivingAddress" label-width="140">
						<u-input v-model="purchaseOrder.receivingAddress" input-align="right" placeholder="" disabled/>
					</u-form-item>
					<u-form-item label="仓库" prop="receivingAddress" label-width="140">
						<u-input v-model="purchaseOrder.receivingAddress" input-align="right" placeholder="" disabled/>
					</u-form-item>
					<u-form-item label="出库类型" prop="receivingAddress" label-width="140">
						<u-input v-model="purchaseOrder.receivingAddress" input-align="right" placeholder="" disabled/>
					</u-form-item>
					<u-form-item label="合同编号" prop="receivingAddress" label-width="180">
						<u-input v-model="purchaseOrder.receivingAddress" input-align="right" placeholder="" disabled/>
					</u-form-item>
					<u-form-item label="货名" prop="receivingAddress" label-width="140">
						<u-input v-model="purchaseOrder.receivingAddress" input-align="right" placeholder="" disabled/>
					</u-form-item>
					<u-form-item label="重量(吨)" prop="receivingAddress" label-width="140">
						<u-input v-model="purchaseOrder.receivingAddress" input-align="right" placeholder="" disabled/>
					</u-form-item>
					<u-form-item label="预计出库时间" prop="receivingAddress" label-width="180">
						<u-input v-model="purchaseOrder.receivingAddress" input-align="right" placeholder="" disabled/>
					</u-form-item>
					<u-form-item label="出库经办人" prop="receivingAddress" label-width="150">
						<u-input v-model="purchaseOrder.receivingAddress" input-align="right" placeholder="" disabled/>
					</u-form-item>
					<u-form-item label="品级" prop="receivingAddress" label-width="150">
						<u-input v-model="purchaseOrder.receivingAddress" input-align="right" placeholder="" @click='show=true' disabled/>
						<u-picker :range="pjList" range-key="type" @confirm='pjPicker($event)' v-model="show" mode="selector">
						</u-picker>
					</u-form-item>
					<u-form-item label="容重(克/升)>=" prop="receivingAddress" label-width="190">
						<u-input v-model="purchaseOrder.receivingAddress" input-align="right" placeholder=""/>
					</u-form-item>
					<u-form-item label="水分(%)<=" prop="receivingAddress" label-width="160">
						<u-input v-model="purchaseOrder.receivingAddress" input-align="right" placeholder=""/>
					</u-form-item>
					<u-form-item label="单价(元/吨)" prop="receivingAddress" label-width="160">
						<u-input v-model="purchaseOrder.receivingAddress" input-align="right" placeholder=""/>
					</u-form-item>
					<view class="title part2">可编辑项</view>
					<u-form-item label="业务描述" prop="receivingAddress" label-width="160" label-position="top">
						<u-input v-model="purchaseOrder.receivingAddress" input-align="left" placeholder="" type="textarea" class="textarea"/>
					</u-form-item>
					<u-form-item label="仓位号(选填)" prop="receivingAddress" label-width="170">
						<u-input v-model="purchaseOrder.receivingAddress" input-align="right" placeholder="未指定"/>
					</u-form-item>
				</view> -->
			</u-form>
		</view>
		<u-toast ref="uToast" />
		<!-- <u-modal v-model="show" content="确定通过出入库任务？" showCancelButton></u-modal> -->
		<view class="bottom-btn">
			<u-button type="primary" class="submit" hover-class="none" @click="rejectSubmit()">驳回</u-button>
			<u-button type="primary" class="submit" hover-class="none" @click="passSubmit()">通过</u-button>
		</view>
	</view>

</template>

<script>
	import {
		mapState
	} from 'vuex';
	export default {
		data() {
			return {
				id: "",
				OutList: {},
				EnterList: {},
				type: '移库',
				show: false,
				purchaseOrder: {
					freightUnitPrice: "123",
					receivingAddress: '出库',
					grade: "1"
				},

				pjList: [{
						type: '一等品'
					},
					{
						type: '二等品'
					},
					{
						type: '三等品'
					},
					{
						type: '等外'
					}
				],
				rules: {
					freightUnitPrice: [{
							validator: (rule, value, callback) => {
								return !this.$u.test.isEmpty(value)
							},
							message: '运费不能为空',
							trigger: ['change', 'blur']
						},
						{
							validator: (rule, value, callback) => {
								return this.$u.test.amount(value)
							},
							message: '数值类型，最多保留两位小数',
							trigger: ['change', 'blur'],
						}
					]
				}
			}
		},
		onReady() {
			this.$refs.uForm.setRules(this.rules);
		},
		onLoad(options) {
			this.id = options.id
			this.getList()
		},
		computed: {
			...mapState(['hasLogin', 'userInfo']),
		},
		methods: {
			getList() {
				this.$api.doRequest('get', '/inOutWarehouseTask/getTask', {
					id: this.id
				}).then(res => {
					if (res.data.code == 200) {
						this.$api.doRequest('get', '/inOutWarehouseTask/getInOutWarehouseTask', {
							relevanceId: res.data.data.relevanceId
						}).then(res => {
							if (res.data.code == 200) {
								for (let i = 0; i < res.data.data.length; i++) {
									if (res.data.data[i].inOutType == "移库出库" || res.data.data[i]
										.inOutType == "贸易服务出库" || res.data.data[i].inOutType == "销售出库" ||
										res.data.data[i].inOutType == "暂存出库") {
										this.OutList = res.data.data[i]
										this.OutList.judge = 1
									}
									if (res.data.data[i].inOutType == "移库入库" || res.data.data[i]
										.inOutType == "暂存入库" || res.data.data[i].inOutType == "退库" || res
										.data.data[i].inOutType == "采购入库" || res.data.data[i].inOutType ==
										"贸易服务入库") {
										this.EnterList = res.data.data[i]
										this.EnterList.judge = 2
									}
								}
							}
						})
					}
				})
			},
			pjPicker(e) {
				this.OutList.grade = this.pjList[e[0]].type
				this.OutList.gradeKey = e[0] + 1
			},
			pjPicker1(e) {
				this.EnterList.grade = this.pjList[e[0]].type
				this.EnterList.gradeKey = e[0] + 1
			},
			passSubmit() {
				this.OutList.inOutFlag = 1
				this.EnterList.inOutFlag = 2
				if (this.OutList.taskTypeKey == 1) {
					this.requestadd(this.OutList)
				} else if (this.EnterList.taskTypeKey == 2) {
					this.requestadd(this.EnterList)
				} else if (
					this.OutList.taskTypeKey == 3 ||
					this.OutList.taskTypeKey == 4
				) {
					this.requestadd(this.OutList, 'repetition')
					if (!this.deletetask) {
						this.requestadd(this.EnterList, 'repetition')
					}
				}
			},
			rejectSubmit() {
				if (this.EnterList.taskTypeKey == 1) {
					this.requestaudit(this.EnterList)
				} else if (this.EnterList.taskTypeKey == 2) {
					this.requestaudit(this.EnterList)
				} else if (
					this.EnterList.taskTypeKey == 3 ||
					this.EnterList.taskTypeKey == 4
				) {
					this.requestaudit(this.EnterList, 'repetition')
					if (!this.deletetask) {
						this.requestaudit(this.EnterList, 'repetition')
					}
				}
			},
			requestadd(list, status) {
				list.compId = sessionStorage.getItem('ws-pf_compId')
				list.publisher = this.userInfo.userName
				this.$api.doRequest('post', '/inOutWarehouseTask/api/checkOrUpdateInOutTask', list).then(res => {
					if (res.data.code == 200) {
						this.$api.doRequest('post', '/inOutWarehouseTask/api/checkOrUpdateInOutTask', {
							taskId: list.taskId,
							approved: true,
							auditMind: '34',
							needReapply: false
						}).then(res => {
							if (res.data.code == 200) {
								this.$api.msg('审核成功！')
							}
						})
					}
				})
			},
			requestaudit(list, status) {
				list.compId = '2710b21efc1e4393930c5dc800010dc4'
				list.publisher = this.userInfo.userName
				this.$api.doRequest('post', '/inOutWarehouseTask/api/checkOrUpdateInOutTask', list).then(res => {
					if (res.data.code == 200) {
						this.$api.doRequest('post', '/inOutWarehouseTask/api/checkOrUpdateInOutTask', {
							taskId: list.taskId,
							approved: false,
							auditMind: "驳回原因",
							needReapply: true
						}).then(res => {
							if (res.data.code == 200) {
								this.$api.msg('驳回成功！')
							}
						})
					}
				})
			},
		}
	}
</script>

<style scoped lang="scss">
	.content1,
	.content2 {
		background-color: #FFFFFF;
		margin: 10rpx;
		padding-bottom: 10rpx;
		border-radius: 20rpx;

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

	.uForm {
		padding: 0 40rpx;
	}

	.u-form-item {
		padding: 0;
	}

	.bottom-btn {
		width: 100%;
		position: fixed;
		bottom: 40rpx;
		display: flex;
		z-index: 2;
	}

	.submit {
		width: 40%;
		background: #22C572;
		border-radius: 10rpx;
	}

	.part2 {
		margin-top: 20rpx;
	}

	.textarea {
		border: 1px solid #ccc;
	}

	.row {
		display: flex;
		justify-content: space-between;
		border-bottom: 1px solid #EEEEEE;
		padding: 21rpx 0;

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