<template>
	<view class="content-box">
		<uni-nav-bar fixed="true" statusBar="true" left-icon="back" title="入库" background-color="#F7F9FA" color="#000"
			@clickLeft="back">

		</uni-nav-bar>

		<view class="list_box">
			<u-list @scrolltolower="scrolltolower">
				<view class="card_box">
					<workOrderBom :item='objData' v-if='objData' @handleScan='handleScan'></workOrderBom>

					<view class="select_box">
						<zxz-uni-data-select :localdata="warehouseList" placeholder="请选择入库仓库" v-model="warehouseId"
							dataValue='id' dataKey="name" filterable format='{name}'></zxz-uni-data-select>
					</view>

					<view class="list_box" v-for="(item, index) in List" :key="index" v-if="clientEnvironmentId != 3">
						<view class="time">打包时间： {{ item.createTime }}</view>
						<packingBom :objData="item.extInfo" :measuringUnit='item.measuringUnit'></packingBom>
					</view>


					<view class="list_box" v-for="(it, index) in tgList" :key="index" v-if="clientEnvironmentId == 3">
						<view class="time">打包时间： {{ it.createTime }}</view>
						<packingTgBom :list='it.extInfo.pickOutInList' :isWarehousing='true'></packingTgBom>
					</view>



				</view>
			</u-list>
		</view>



		<view class="bottom-wrapper">
			<view class="btn_box" @click="save">一键报工</view>
		</view>

	</view>
</template>

<script>
import {
	getByIdReport,
	jobSave

} from '@/api/pda/jobBooking.js'

import {
	getWarehouseList,
	listPDAToWarehouse,
	listPDAToWarehouseTG
} from '@/api/pda/workOrder.js'

import packingBom from './components/packingBom.vue'
import workOrderBom from '../feeding/components/workOrderBom.vue'
import packingTgBom from '../jobBooking/components/packingTgBom.vue'
export default {
	components: {
		workOrderBom,
		packingBom,
		packingTgBom
	},
	data() {
		return {
			id: null,
			taskId: null,

			objData: {},
			warehouseList: [],
			warehouseId: null,

			List: [],

			tgList: [],


			clientEnvironmentId: uni.getStorageSync("userInfo") && uni.getStorageSync("userInfo")
				.clientEnvironmentId, // *1 主环境-601环境   2 soll-索尔环境    3 tg-碳谷环境

			inWarehouseType: null,

		}
	},

	onLoad(options) {

		this.id = options.workOrderId
		this.taskId = options.taskId
		this.workReportId = options.workReportId
		this.getList()

		this.getWarehouseListFn()

		if (this.clientEnvironmentId == 3) {
			this.getTgWarehouse()
		} else {
			this.getWarehouse()
		}

	},

	methods: {
		getList() {
			getByIdReport(this.id, this.taskId).then(res => {
				this.objData = res
				if (res.workOrderType == 1) {
					this.inWarehouseType = 1
				} else if (res.workOrderType == 2) {
					this.inWarehouseType = 8 //  "1入库类型1生产入库2半成品入库"
				}


				this.objData.workReportInfo = {
					formingNum: null,
					formingWeight: null,
					formedNum: null,
					formedWeight: null,
					taskId: this.taskId

				}

			})
		},

		getWarehouseListFn() {
			getWarehouseList().then(res => {
				this.warehouseList = res
			})
		},

		getWarehouse() {
			let param = {
				workOrderId: this.id,
				taskId: this.taskId,
				workReportId: this.workReportId

			}
			listPDAToWarehouse(param).then(res => {
				this.List = res
			})
		},


		getTgWarehouse() {
			let param = {
				workOrderId: this.id,
				taskId: this.taskId,
				workReportId: this.workReportId

			}
			listPDAToWarehouseTG(param).then(res => {
				this.tgList = res
			})
		},


		handleScan() {

		},
		scrolltolower() { },

		save() {
			if (!this.warehouseId) {
				uni.showToast({
					icon: 'none',
					title: '请先选择入库仓库'
				})
				return false
			}



			let storageInfo = {
				warehouseId: this.warehouseId,
				inWarehouseType: this.inWarehouseType,
				toWarehouseList: this.clientEnvironmentId == 3 ? this.tgList : this.List,
			}
			this.objData['storageInfo'] = storageInfo


			jobSave(this.objData).then(res => {
				uni.navigateBack()
			})

		},
	}
}
</script>
<style lang="scss" scoped>
.content-box {
	height: 100vh;
	overflow: hidden;
	display: flex;
	flex-direction: column;

}

.list_box {
	flex: 1;
	overflow: hidden;
	padding: 4rpx 0;

	.u-list {
		height: 100% !important;
	}

	.card_box {
		padding: 16rpx 24rpx;
	}



}

.bottom-wrapper {
	.btn_box {
		width: 750rpx;
		height: 88rpx;
		line-height: 88rpx;
		background: $theme-color;
		text-align: center;
		font-size: 36rpx;
		font-style: normal;
		font-weight: 400;
		color: #fff;
	}
}




.select_box {
	margin-top: 20rpx;
}

.list_box {
	margin-top: 40rpx;

	.time {
		font-size: 28rpx;
	}
}
</style>