<template>
	<view class="content-box">
		<uni-nav-bar fixed="true" statusBar="true" left-icon="back" :title="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' @handleScan='handleWordScan'></workOrderBom>




					<qualityTurnoverBom v-if='objData.turnover && objData.turnover.length != 0' :list='objData.turnover' :wordItem='objData'
						:newTurnover='objData.newTurnover' @handleScan='handleScan' @refreshList='getList'>
					</qualityTurnoverBom>




					<view class="operate_box rx-sc">
						<u-button size="small" class="u-reset-button" type="success"
							@click="handAdd(objData.workOrderId)">手动添加</u-button>
						<u-button size="small" class="u-reset-button" type="success"
							@click="scanIt(objData.workOrderId)">扫一扫</u-button>
					</view>

				</view>
			</u-list>

		</view>




	</view>
</template>

<script>
	import workOrderBom from '../../feeding/components/workOrderBom.vue'
	import qualityTurnoverBom from '../components/qualityTurnoverBom.vue'

	import {
		getVehicle,
	} from '@/api/pda/workOrder.js'





	export default {
		components: {
			workOrderBom,
			qualityTurnoverBom
		},
		data() {
			return {
				title: '',
				workOrderId: null,
				objData: {},
				taskId: null


			}
		},

		onShow() {
			uni.$off("setSelectList");
			uni.$on("setSelectList", (selectList, id) => {
				let turnover = []
				selectList.forEach(f => {
					if (f.rootCategoryLevelId == 7) { // 周转车
					
					f.extInfo.positionList.length && f.extInfo.positionList.forEach(o => {
						o['check'] = false
						o['isend'] = false
					})
					
						turnover = turnover.concat(f)
					}
				})
				this.$set(this.objData, 'turnover', turnover)
				this.$forceUpdate()



			});
		},

		onLoad(options) {
			this.title = options.taskName ? options.taskName + '-更换周转车' : '更换周转车'
			this.workOrderId = options.workOrderId;
			this.taskId = options.taskId
			this.taskName = options.taskName

			this.getList()

		},


		methods: {
			scrolltolower() {},



			getList() {
				getVehicle({
					workOrderId: this.workOrderId,
					taskId: this.taskId
				}).then(res => {


					if (!res.hasOwnProperty('turnover')) {
						res['turnover'] = []
					}
					this.objData = res
					console.log(this.objData)

				})
			},






			handleWordScan(id, type) {
				uni.showToast({
					icon: 'none',
					title: '不支持更换工单'
				})


			},


			handleScan(id, type) {

				let _this = this
				uni.scanCode({
					success: function(res) {
						_this.scanData(res.result, type, id)
					}
				})


			},


			handAdd(id) {
				const storageKey = Date.now() + "";
				uni.setStorageSync(storageKey, this.objData);
				uni.navigateTo({
					url: `/pages/pda/workOrder/search/index?id=${id}&storageKey=${storageKey}&isType=job&taskId=${this.taskId}`
				})
			},







		},

	}
</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;
		}



	}


	.operate_box {
		padding: 10rpx 160rpx;

		/deep/ .u-button {
			width: 160rpx;
		}
	}
</style>