<template>
	<view>
		<!-- <requiredLocation title="需求库位" :locationCode="dataContent.toLocationCode"
			:isShowEdit="dataContent.allowModifyLocation==1"></requiredLocation> -->
			<uni-collapse ref="collapse">
				<uni-collapse-item :open="true" :show-animation="true">
					<template v-slot:title>
						<!-- 物品 -->
						<item-qty :dataContent="dataContent" :handleQty="dataContent.handleQty" :isShowBalanceQty="false" :isSpecial='true'></item-qty>
					</template>
					<view
						    v-for="(item,index) in dataContent.subList">
						<view >
							<view class="" :class="item.scaned?'scan_view':''">
								<recommendRepleinsh :isShowPackingNumberProps="true"  :isShowPack="false" :detail="item" :isShowLocation="false" :isShowFromLocation="true"  :isShowToLocation="item.isRecommTaskItem?true:false" :boardNumber='item.boardNumber' :settingParam='settingParam' ref="recommendRepleinshRef" :isShowStatus='false' @updateData='updateData'></recommendRepleinsh>
							</view>
						</view>
					</view>
					</uni-collapse-item>
			</uni-collapse>
	</view>
	<balance-qty-edit ref="balanceQtyEdit" @confirm="confirm" :isShowStatus="true"></balance-qty-edit>
	<detail-info-popup ref="detailInfoPopup"></detail-info-popup>
	<comMessage ref="message"></comMessage>
</template>

<script>
	import itemQty from '@/mycomponents/item/itemQty.vue'
	import recommendRepleinsh from '@/mycomponents/recommend/recommendRepleinsh.vue'
	import recommendBalance from '@/mycomponents/balance/recommendBalance.vue'
	import handleBalance from '@/mycomponents/balance/handleBalance.vue'
	import recommendQtyEdit from '@/mycomponents/qty/recommendQtyEdit.vue'
	import jobDetailPopup from '@/mycomponents/job/jobDetailPopup.vue'
	import requiredLocation from '@/mycomponents/location/requiredLocation.vue'
	import balanceQtyEdit from '@/mycomponents/qty/balanceQtyEdit.vue'
	import location from '@/mycomponents/balance/location.vue'
	import detailInfoPopup from '@/pages/productionReceipt/coms/detailInfoPopup.vue'

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

	export default {
		emits: ['updateData'],
		components: {
			itemQty,
			recommendRepleinsh,
			recommendBalance,
			handleBalance,
			recommendQtyEdit,
			requiredLocation,
			balanceQtyEdit,
			location,
			detailInfoPopup
		},
		props: {
			dataContent: {
				type: Object,
				default: {}
			},
			settingParam: {
				type: Object,
				default: {}
			},
		},
		watch: {

		},

		data() {
			return {
				option: [],
				showItem: {},
				editItem: {},
				batchItem: {},
				detailOptions: [],
				scanOptions: [],
				removeOptions:[],
				editAndRemoveOptions:[]
			}
		},

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

		methods: {
			resizeCollapse() {
				this.$refs.collapse.resize()
				// this.$refs.collapse.childrens.forEach(i => {
				// 	i.init();
				// })
			},

			swipeClick(e, batch, record, index) {
				if (e.content.text == "编辑") {
					this.edit(batch, record)
				} else if (e.content.text == "移除") {
					this.remove(batch, record, index)
				}
			},

			edit(batch, record) {
				let that = this;
				that.editItem = record;
				that.batchItem = batch;
				record.balance.balanceQty = record.balance.qty;
				that.$refs.balanceQtyEdit.openEditPopup(record.balance, record.qty);
			},

			detail(item) {
				this.showItem = item;
				this.$refs.receiptHint.openScanPopup()
			},
			remove(batch, record, index) {
				this.$refs.message.showQuestionMessage("确定移除扫描信息?",
					res => {
						if (res) {
							batch.Records.splice(index, 1);
							this.resizeCollapse();
							this.$emit('updateData', record)
						}
					});
			},
			updateData(e, item, index,detail){
				this.$emit('updateData',e, item, index,detail)
			},
			confirm(val) {
				this.editItem.qty = val;
				this.$emit('updateData', this.editItem)
				// let qty = 0;
				// this.batchItem.Records.forEach(r => {
				// 	qty += Number(r.qty);
				// })
				// this.batchItem.handleQty = qty;
			}
		}
	}
</script>

<style>
</style>
