<template>
	<view>
		
		<!-- <requiredLocation title="需求库位" :locationCode="dataContent.toLocationCode"
			:isShowEdit="dataContent.allowModifyLocation==1"></requiredLocation> -->
		<view>
			<uni-collapse ref="collapse">
				<uni-collapse-item :open="true"  :class="dataContent.scaned?'scan_view':''">
					<template v-slot:title>
						<view class="split_line"></view>
						<!-- 物品 -->
						<item-qty :dataContent="dataContent" :handleQty="dataContent.handleQty" :isShowBalanceQty='false'></item-qty>
					</template>
					<uni-swipe-action ref="swipeAction" style="margin-top: 10px;"
						    v-for="(item,index) in dataContent.subList">
						<uni-swipe-action-item
							:right-options="(item.scaned&&isEdit)?editAndRemoveOptions : item.scaned? removeOptions:detailOptions"   @click="itemCoceClick($event,item,index)">
							<view class="" :class="item.scaned?'scan_view':''">
								<recommend :detail="item" :isShowLocation="false" :isShowFromLocation="true"  :isShowToLocation="settingParam.allowModifyLocation=='TRUE'"></recommend>
							</view>
						</uni-swipe-action-item>
					</uni-swipe-action>
				</uni-collapse-item>
			</uni-collapse>
		</view>
	</view>
	<!-- <balance-qty-edit ref="balanceQtyEdit" @confirm="confirm" :isShowStatus="true"></balance-qty-edit> -->
	<recommend-qty-edit ref="receiptEdit" :dataContent="editItem" :settingParam="settingParam" @confirm="confirm">
	</recommend-qty-edit>
	<detail-info-popup ref="detailInfoPopup"></detail-info-popup>
	<comMessage ref="message"></comMessage>
</template>

<script>
	import itemQty from '@/mycomponents/item/itemQty.vue'
	import recommend from '@/mycomponents/recommend/recommend.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 comIssueRequestInfo from '@/pages/issue/coms/comIssueRequestInfo.vue'
	import batch from '@/mycomponents/balance/batch.vue'
	import qtyEdit from '@/mycomponents/qty/qtyEdit.vue'
	import {
		getDetailOption,
		getEditRemoveOption,
		getRemoveOption
	} from '@/common/array.js';

	export default {
		emits: ['updateData', "removeItemCode"],
		components: {
			itemQty,
			recommend,
			recommendBalance,
			handleBalance,
			recommendQtyEdit,
			requiredLocation,
			balanceQtyEdit,
			location,
			detailInfoPopup,
			comIssueRequestInfo,
			batch,
		},
		props: {
			dataContent: {
				type: Array,
				default: []
			},
			settingParam: {
				type: Object,
				default: {}
			},
			isEdit: {
				type: Boolean,
				default: true
			},
		},
		watch: {

		},

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

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

		methods: {
			resizeCollapse() {
				this.$nextTick(r => {
						this.$refs.collapse.resize()
						this.$refs.collapse.childrens.forEach(i => {
							i.init();
						})
					
				});
			},
			swipeClick(e, batch,
			 record,recordIndex,
			 batchIndex,
			Batchs,
			 locatonIndex,
			Locations) {
				if (e.content.text == "编辑") {
					this.edit(batch, record)
				} else if (e.content.text == "移除") {
					this.remove(batch, record, recordIndex,batchIndex,Batchs,locatonIndex,Locations)
				}
			},

			itemCoceClick(e, item, index) {
				if (e.content.text == "编辑") {
					this.edit(item)
				} else if (e.content.text == "移除") {
					// this.dataContent.subList.splice(index, 1);
					item.scaned = false
					item.handleQty=0
				this.$emit('updateData')
				}
			},

			edit(item) {
				this.editItem = item;
				this.$refs.receiptEdit.openTaskEditPopup(item.qty, item.handleQty, item.labelQty);
			},

			detail(item) {
				this.showItem = item;
				this.$refs.receiptHint.openScanPopup()
			},
			remove(batch, record, recordIndex,batchIndex,Batchs,locatonIndex,Locations) {
				this.$refs.message.showQuestionMessage("确定移除扫描信息?",
					res => {
						if (res) {
							batch.Records.splice(recordIndex, 1);
							if(batch.Records.length==0&&Batchs[batchIndex].isNewAdd){
								Batchs.splice(batchIndex,1)
							}
							if(batch.Records.length==0&&Locations[locatonIndex].isNewAdd){
								Locations.splice(locatonIndex,1)
							}
							this.resizeCollapse();
							this.$emit('updateData', record)
						}
					});
			},
			confirm(val) {
				this.editItem.handleQty =  Number(val);
				this.$emit('updateData', this.editItem)
			}
		}
	}
</script>

<style>
</style>