<template>
	<view class="">

		<view class="" v-for="(item,index) in dataContent" :key="item.id">
			<uni-collapse ref="collapse2" @change="collapseChange">
				<uni-collapse-item :disabled="false">
					<template v-slot:title>
						<package-card :dataContent="item" :isShowLocation="false" :isShowFromLocation ="isShowFromLocation"
							></package-card>
					</template>
					<view v-for="(pack,index) in item.packList" :key="pack.id" style=" width: 100%; background-color: antiquewhite;">
						<uni-swipe-action-item :right-options="(pack.scaned&&isEdit)?editAndRemoveOptions:removeOptions"
							@click="swipeClick($event,pack)">
							<package-card :dataContent="pack" :isShowLocation="false" :isShowFromLocation="false"
								:isShowToLocation="false" :isShowBatch="false"></package-card>
						</uni-swipe-action-item>

					</view>
				</uni-collapse-item>
			</uni-collapse>
		</view>
		<recommend-qty-edit ref="receiptEdit" :dataContent="editItem" :settingParam="settingParam" @confirm="confirm">
		</recommend-qty-edit>
	</view>
</template>


<script>
	import config from '@/static/config.js'
	import packageCard from '@/mycomponents/package/packageCard.vue'
	import recommendQtyEdit from '@/mycomponents/qty/recommendQtyEdit.vue'

	import {
		getRemoveOption,
		getEditRemoveOption
	} from '@/common/array.js';
	export default {
		emits: ["collapseChange"],
		components: {
			packageCard,
			recommendQtyEdit
		},

		data() {
			return {
				editItem: {},
				options: [],
				removeOptions: [],
				editAndRemoveOptions:[]
			}
		},
		mounted() {
			this.removeOptions = getRemoveOption();
			this.editAndRemoveOptions =getEditRemoveOption()
		},
		props: {
			dataContent: {
				type: Object,
				default: null
			},
			isShowContainer: {
				type: Boolean,
				default: true
			},
			isShowPack: {
				type: Boolean,
				default: true
			},
			isShowBatch: {
				type: Boolean,
				default: true
			},
			isShowFromLocation: {
				type: Boolean,
				default: true
			},
			isShowToLocation: {
				type: Boolean,
				default: false
			},
			isShowStatus: {
				type: Boolean,
				default: true
			},

			locationTitle: {
				type: String,
				default: '库位'
			},
			settingParam: {
				type: Object,
				default: null
			},
			isEdit:{
				type: Boolean,
				default: false
			}

		},
		watch: {

		},
		methods: {
			swipeClick(e, item) {
				if (e.content.text == "编辑") {
					this.edit(item)
				}
			},
			edit(item) {
				this.editItem = item;
				this.$refs.receiptEdit.openTaskEditPopup(item.qty, item.handleQty, item.labelQty);
			},
			collapseChange() {
				this.$emit("collapseChange");
				this.resizeCollapse();
			},
			resizeCollapse() {
				this.$nextTick(r => {
					this.$refs.collapse2.forEach(r => {
						r.childrens.forEach(i => {
							i.init();
						})
						r.resize();
					})

				});
				this.$forceUpdate();
			},

			copy() {
				// HPQ;V1.0;ICE115F11161AG;PP20230427000026;B20230427002;Q100
				var content = "HPQ;V1.0;I" + this.detail.itemCode + ";P" + this.detail.packingNumber + ";B" + this.detail
					.batch + ";Q" + this.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
			},
			copyPro() {
				// HPQ;V1.0;ICE115F11161AG;PP20230427000026;B20230427002;Q100
				var content = "HMQ;V1.0;I" + this.detail.itemCode + ";P" + this.detail.packingNumber + ";B" + this.detail
					.batch + ";Q" + this.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
			},
			isDevlement() {
				return config.isDevelopment;
			},
			confirm(qty){
				this.editItem.handleQty =qty;
				this.$emit("updateData")
			}
			
		}
	}
</script>

<style>
	.open {
		/* background-color: green !important; */
		padding-top: 0px !important;
	}
</style>