<template>
	<view>
		<!-- 需求库位 -->
		<requiredLocation title="需求库位" :locationCode="dataContent.toLocationCode"
			:isShowEdit="dataContent.allowModifyLocation==1"></requiredLocation>
		<u-line />
		<view v-for="(item,index) in dataContent.Items">
			<uni-collapse ref="collapse">
				<uni-collapse-item :open="true">
					<template v-slot:title>
						<!-- 物品 -->
						<item-qty :dataContent="item" :handleQty="item.handleQty"></item-qty>
					</template>
					<u-line />
					<view v-for="(loacation,index) in item.Locations">
						<view>
							<view class="uni-flex uni-row space-between">
								<!-- 推荐库位 -->
								<location :locationCode="loacation.fromLocationCode">
								</location>
							</view>
							<view v-for="(batch,index) in loacation.Batchs">
								<uni-collapse ref="subCollapse">
									<uni-collapse-item :open="true">
										<template v-slot:title>
											<view class="uni-flex uni-row space-between">
												<view>
													<batch :batch="batch.batch" style='margin-left: 20px;'>
													</batch>
												</view>
												<view>
													<recommend-qty
														v-if="batch.Records==null || batch.Records==undefined "
														:dataContent="batch" :isShowStatus='false'
														:isShowStdPack="false">
													</recommend-qty>
													<compare-qty v-else :dataContent="batch" :recommendQty="batch.qty"
														:handleQty="batch.handleQty" :isShowStatus='false'
														:isShowStdPack="false">
													</compare-qty>
												</view>
											</view>
										</template>

										<view v-if='batch.Records!=null || batch.Records!=undefined '
											v-for="(record,index) in batch.Records">
											<uni-swipe-action ref="swipeAction">
												<uni-swipe-action-item @click="swipeClick($event,batch)"
													:right-options="scanOptions">
													<!-- :right-options="loacation.scaned?scanOptions:detailOptions" -->
													<view class="uni-flex uni-row space-between">
														<view>
															<pack :packingCode="record.packingNumber"
																style='margin-left: 40px;'>
															</pack>
														</view>
														<view>
															<qty :dataContent="record" :isShowStdPack="false">
															</qty>
														</view>
													</view>

													<!-- <com-issue-recommend :detail="loacation"></com-issue-recommend> -->
												</uni-swipe-action-item>
											</uni-swipe-action>
										</view>
									</uni-collapse-item>
								</uni-collapse>
							</view>
						</view>
					</view>
				</uni-collapse-item>
			</uni-collapse>
		</view>
	</view>


	<recommendQtyEdit ref="receiptEdit" :dataContent="editItem" :settingParam="settingParam"
		:handleQty="editItem.record.qty" @confirm="confirm">
	</recommendQtyEdit>
	<job-detail-popup ref="receiptHint" :dataContent="showItem"></job-detail-popup>
	<comMessage ref="message"></comMessage>
</template>

<script>
	import itemQty from '@/mycomponents/item/itemQty.vue'
	import recommend from '@/mycomponents/recommend/recommend.vue'
	import recommendQtyEdit from '@/mycomponents/qty/recommendQtyEdit.vue'
	import jobDetailPopup from '@/mycomponents/job/jobDetailPopup.vue'
	import requiredLocation from '@/mycomponents/location/requiredLocation.vue'
	import comIssueRecommend from '@/pages/issue/coms/comIssueRecommend.vue'

	import pack from '@/mycomponents/balance/pack.vue'
	import location from '@/mycomponents/balance/location.vue'
	import batch from '@/mycomponents/balance/batch.vue'
	import recommendQty from '@/mycomponents/qty/recommendQty.vue'
	import compareQty from '@/mycomponents/qty/compareQty.vue'
	import balanceQty from '@/mycomponents/qty/balanceQty.vue'
	import qty from '@/mycomponents/qty/qty.vue'

	import {
		getDetailOption,
		getEditRemoveOption
	} from '@/common/array.js';

	export default {
		components: {
			itemQty,
			recommend,
			recommendQtyEdit,
			jobDetailPopup,
			requiredLocation,
			comIssueRecommend,
			pack,
			location,
			batch,
			recommendQty,
			compareQty,
			balanceQty,
			qty
		},
		props: {
			dataContent: {
				type: Object,
				default: {}
			},
			settingParam: {
				type: Object,
				default: {}
			},
		},
		watch: {

		},

		data() {
			return {
				option: [],
				title: "推荐详情",
				showItem: {},
				editItem: {
					record: {

					}
				},
				detailOptions: [],
				scanOptions: []
			}
		},

		mounted() {
			this.detailOptions = getDetailOption();
			this.scanOptions = getEditRemoveOption();
		},

		methods: {
			resizeCollapse() {
				this.$nextTick(r => {
					this.$refs.subCollapse.forEach(r => {
						r.resize();
					})
				});

				this.$nextTick(r => {
					this.$refs.collapse.forEach(r => {
						r.childrens.forEach(i => {
							i.init();
						})
						r.resize();
					})
				});

			},

			swipeClick(e, item) {
				if (e.content.text == "详情") {
					this.detail(item)
				} else if (e.content.text == "编辑") {
					this.edit(item)
				} else if (e.content.text == "移除") {
					this.remove(item)
				}
			},
			edit(item) {
				this.editItem = item;
				this.$refs.receiptEdit.openEditPopup();
			},

			detail(item) {
				this.showItem = item;
				this.$refs.receiptHint.openScanPopup()
			},
			remove(item) {
				this.$refs.message.showQuestionMessage("确定移除扫描信息?",
					res => {
						if (res) {
							item.isScaned = false
							item.record = {}
							// item.record.qty = 0;
							this.$forceUpdate()
							this.$emit('remove', item)
						}
					});
			},
			confirm(qty) {
				this.editItem.record.qty = qty;
				this.$emit('updateData')
			}
		}
	}
</script>

<style>
</style>
