<template>
	<view class="" style="background-color: #fff;">
		<uni-collapse ref="collapse"  style="height: 500px;">
			<uni-collapse-item :open="true">
				<template v-slot:title>
					<itemCompareQty :dataContent="dataContent" :handleQty="dataContent.handleQty"
						:isShowPackUnit="false"></itemCompareQty>
				</template>
				<package-list :dataContent="dataContent.subList" :isEdit="settingParam.allowModifyQty=='TRUE'"  :settingParam="settingParam"   @collapseChange="collapseChange"></package-list>
			</uni-collapse-item>
		</uni-collapse>

		<recommend-qty-edit ref=" receiptEdit" :dataContent="editItem" :settingParam="settingParam" @confirm="confirm">
		</recommend-qty-edit>
		<win-scan-location ref="scanLocationCode" title="目标库位" @getLocation='getLocation'
			:locationTypeList="locationTypeList"></win-scan-location>
		<receipt-detail-info-popup ref="jobDetailPopup" :dataContent="showItem"></receipt-detail-info-popup>
		<comMessage ref="message"></comMessage>
	</view>
</template>

<script>
	import itemCompareQty from '@/mycomponents/item/itemCompareQty.vue'
	import recommend from '@/mycomponents/recommend/recommend.vue'
	import recommendQtyEdit from '@/mycomponents/qty/recommendQtyEdit.vue'
	import jobDetailPopup from '@/mycomponents/detail/jobDetailPopup.vue'
	import receiptDetailInfoPopup from '@/pages/purchaseReceipt/coms/receiptDetailInfoPopup.vue'
	import winScanLocation from "@/mycomponents/scan/winScanLocation.vue"
	import pack from '@/mycomponents/balance/pack.vue'
	import detailList from '@/mycomponents/detail/detailList.vue'
	import packageList from '@/mycomponents/package/packageList.vue'

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

	export default {
		components: {
			itemCompareQty,
			recommend,
			recommendQtyEdit,
			jobDetailPopup,
			receiptDetailInfoPopup,
			winScanLocation,
			detailList,
			packageList
		},
		props: {
			dataContent: {
				type: Object,
				default: null
			},
			settingParam: {
				type: Object,
				default: null
			},
			locationTypeList: {
				type: Object,
				default: null
			},


		},
		watch: {

		},

		data() {
			return {
				showItem: {},
				editItem: {
					record: {

					}
				},
				locatonItem: {},
				detailOptions: [],
				scanOptions: []
			}
		},

		mounted() {
			if (this.detailOptions.length == 0) {
				this.detailOptions = getDetailOption();
			}
			if (this.scanOptions.length == 0) {
				this.scanOptions = getPurchaseReceiptOption(this.settingParam.allowModifyQty, this.settingParam
					.allowModifyLocation)
			}
			

		},

		updated() {
			console.log('updated')
		},

		methods: {	
			collapseChange(){
				setTimeout(() => {
					this.resizeCollapse();
				}, 500)
			},
			
			resizeCollapse() {
				this.$nextTick(r => {
					this.$refs.collapse.resize()
				});
				this.$forceUpdate();
			},


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

			swipeClick(e, item) {
				if (e.content.text == "详情") {
					this.detail(item)
				} else if (e.content.text == "编辑") {
					this.edit(item)
				} else if (e.content.text == "库位") {
					this.showLocation(item)
				} else if (e.content.text == "移除") {
					this.remove(item)
				}
			},
			edit(item) {
				this.editItem = item;
				this.$refs.receiptEdit.openTaskEditPopup(item.qty, item.handleQty, item.labelQty);
			},
			showLocation(item) {
				this.locatonItem = item;
				this.$refs.scanLocationCode.openScanPopup();
			},
			//扫描源库位
			getLocation(location, code) {
				this.locatonItem.toLocationCode = code;
				this.$emit('updateData')
			},

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

<style>
</style>