<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" v-for="(item,index) in List" :key="index">
					<workOrderBom :item='item' v-if='item' @handleScan='handleWordScan'></workOrderBom>

					<sampleBom :item='item.quality' v-if='item.quality' :isDetails='false'></sampleBom>

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

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

	</view>

	</view>
</template>

<script>
	import {
		workorderList,

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

	import workOrderBom from '../../feeding/components/workOrderBom.vue'
	import sampleBom from '../components/sampleBom.vue'
	import {
		batchSave
	} from '@/api/pda/feeding.js'
	export default {
		components: {
			workOrderBom,
			sampleBom
		},
		data() {
			return {
				title: null,
				id: null,
				taskId: null,
				List: [],
				count: 0
			}
		},

		onLoad(options) {
			this.title = options.taskName ? options.taskName : '质检'
			this.id = options.workOrderId
			this.taskId = options.taskId
			this.getList()
		},
		methods: {
			getList() {
				workorderList({
					ids: [this.id],
					taskId: this.taskId
				}).then(res => {
					this.List = res.map(m => {
						m.workOrderId = m.id
						m.quality['sampleList'] = []
						m.feedType = 2
						delete m.id
						return {
							...m
						}
					})
				})
			},

			scrolltolower() {},

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

			save() {

				console.log(this.List)


				this.count = 0;
				this.List[0].quality.sampleList.forEach(e => {
					if (Number(e.num) > 0 && Number(e.num) != NaN) {
						this.count += Number(e.num);
					}

				})

				if (this.List[0].quality.sampleNum != this.count) {
					uni.showToast({
						icon: 'none',
						title: '处置数量和取样数量对应不上'
					})

					return false
				}



				batchSave(this.List).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;
		}
	}


	.operate_box {
		padding: 10rpx 160rpx;

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