<template>
	<view class="" style="background-color: #fff;">
					<itemCompareQty :dataContent="dataContent" :handleQty="dataContent.handleQty"></itemCompareQty>
		<view class="" v-for="(item,index) in dataContent.subList" :key="index" >
			<uni-swipe-action ref="swipeAction" v-if="index==0" :class="item.scaned?'scan_view':''">
			<uni-swipe-action-item
				:right-options="(item.scaned&&isEdit)?editAndRemoveOptions : item.scaned? removeOptions:options"
				@click="swipeClick($event,item,'parent')">
					<!-- <div style="display: flex;">
						<div style="flex: 1;">
							<batch v-if="item.batch" :batch="item.batch"></batch>
							<to-location title="目标库位" :locationCode="item.toLocationCode">
							</to-location>
						</div>
						<text style="font-size: 30rpx;color: #2979ff; " @click="copy(item)" v-if="isDevlement()">复制</text>
						</div> -->
						<recommendBatch :detail="item" :isShowFromLocation="false"
							:isShowToLocation="settingParam.allowModifyLocation=='TRUE'"></recommendBatch>
				</uni-swipe-action-item>
			</uni-swipe-action>
			<view v-if="item.fgList!=undefined && item.fgList.length>0" class="card_view " style="margin-left: 20px;"
				v-for="(fg, index) in item.fgList" :key="index">
				<com-fg-card :detail='fg' class="scan_view"></com-fg-card>
			</view>
		</view>


		<recommend-qty-edit ref="receiptEdit" :dataContent="editItem" :settingParam="settingParam" @confirm="confirm" :isNumTips='false'>
		</recommend-qty-edit>
		<win-scan-location ref="scanLocationCode" title="目标库位" @getLocation='getLocation'
			:locationAreaTypeList="locationAreaTypeList"></win-scan-location>
		<productDetailInfoPopup ref="jobDetailPopup" :dataContent="showItem"></productDetailInfoPopup>
		<comMessage ref="message"></comMessage>
	</view>
</template>

<script>
	import itemCompareQty from '@/mycomponents/item/itemCompareQty.vue'
	import recommendBatch from '@/mycomponents/recommend/recommendBatch.vue'
	import recommendQtyEdit from '@/mycomponents/qty/recommendQtyEdit.vue'
	import jobDetailPopup from '@/mycomponents/detail/jobDetailPopup.vue'
	import productDetailInfoPopup from '@/pages/productReceipt/coms/productDetailInfoPopup.vue'
	import winScanLocation from "@/mycomponents/scan/winScanLocation.vue"
	import comFgCard from "@/pages/productReceipt/coms/comFgCard.vue"

	import pack from '@/mycomponents/balance/pack.vue'
	import location from '@/mycomponents/balance/location.vue'
	import toLocation from '@/mycomponents/balance/toLocation.vue'
	import batch from '@/mycomponents/balance/batch.vue'
	import config from '@/static/config.js'
	import {
		getRemoveOption,
		getEditRemoveOption
	} from '@/common/array.js';

	export default {
		components: {
			itemCompareQty,
			recommendBatch,
			recommendQtyEdit,
			jobDetailPopup,
			productDetailInfoPopup,
			winScanLocation,
			comFgCard,
			pack,
			location,
			toLocation,
			batch
		},
		props: {
			dataContent: {
				type: Object,
				default: null
			},
			settingParam: {
				type: Object,
				default: null
			},
			locationAreaTypeList: {
				type: Array,
				default: null
			},
isEdit: {
				type: Boolean,
				default: true
			},

		},
		watch: {
			dataContent: {
				handler(newName, oldName) {
					if (this.dataContent.subList.length > 0) {
						if (this.$refs.collapse1 != undefined && this.$refs.collapse1 != null) {
							this.$nextTick(res => {
								this.$refs.collapse1.resize()
							})
						}
					}
				},
				immediate: true,
				deep: true
			}
		},

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

					}
				},
				locatonItem: {},
				detailOptions: [],
				scanOptions: [],
				options: [],
				removeOptions: [],
				editAndRemoveOptions: []
			}
		},

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

		methods: {
			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
							item.fgList = []
							this.$forceUpdate()
							this.$emit('remove', item)
						}
					});
			},
			confirm(qty) {
				this.editItem.handleQty = qty;
				this.$emit('updateData')
			},
			isDevlement() {
				return config.isDevelopment;
			},
			copy(detail) {
				console.log(detail)
				// HPQ;V1.0;ICE115F11161AG;PP20230427000026;B20230427002;Q100
				var content = "HPQ;V1.0;I" + detail.itemCode + ";P" + detail.packingNumber + ";B" + detail
					.batch + ";Q" + detail.qty
				// #ifdef H5
				this.$copyText(content).then(
					res => {
						uni.showToast({
							title: '复制采购标签成功',
							icon: 'none'
						})
					}
				)
				// #endif
				// #ifndef H5
				uni.setClipboardData({
					data: content,
					success: () => {
						uni.showToast({
							title: '复制采购标签成功'
						})
					}
				})
				// #endif
			},
		}
	}
</script>

<style>
</style>