<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" :open="true">
					<template v-slot:title>
						<uni-swipe-action>
							<uni-swipe-action-item
								:right-options="(item.scaned&&isEdit)?editAndRemoveOptions : item.scaned? removeOptions:options"
								@click="swipeClick($event,item,'parent',index)">
								<package-card :dataContent="item" :isShowLocation="false"
									:isShowFromLocation="isShowFromLocation"
									:isShowStatus="isShowStatus"></package-card>
							</uni-swipe-action-item>
						</uni-swipe-action>

					</template>
					<view v-for="(pack,index) in item.packList" :key="pack.id"
						style=" width: 100%; background-color: antiquewhite;">
						<uni-swipe-action>
							<uni-swipe-action-item
								:right-options="(pack.scaned)?editAndRemoveOptions : pack.scaned? removeOptions:options"
								@click="swipeClick($event,pack,'child',index,item)">
								<package-card :dataContent="pack" :isShowLocation="false" :isShowFromLocation="false" :isShowPackingNumberProps='isShowPackingNumberProps'
									:isShowToLocation="false"
									:isShowStatus="isShowPackListStatus"
									 :isShowRecommendQty='false'
									:isShowBatch="false"></package-card>
							</uni-swipe-action-item>
						</uni-swipe-action>

					</view>
				</uni-collapse-item>
			</uni-collapse>
		</view>
		<recommend-qty-edit ref="receiptEdit" :dataContent="editItem" :settingParam="settingParam" @confirm="confirm" :isNumPackTips='isNumPackTips'>
		</recommend-qty-edit>
		<comMessage ref="comMessage"></comMessage>
	</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", "updateData"],
		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
			},
			
			isShowPackListStatus: {
				type: Boolean,
				default: true
			},

			locationTitle: {
				type: String,
				default: '库位'
			},
			settingParam: {
				type: Object,
				default: null
			},
			isEdit: {
				type: Boolean,
				default: false
			},
			// 采购订单单独显示的包装号
			isShowPackingNumberProps:{
				type:Boolean,
				default:false
			},
			isNumPackTips: {
				type: Boolean,
				default: false
			},

		},
		watch: {

		},
		methods: {
			swipeClick(e, item, type,index,ele) {
				if (e.content.text == "编辑") {
					this.edit(item)
				} else if (e.content.text == "移除") {
					if (type == 'parent') {
						this.removeParent(item,type);
					} else {
						this.remove(item,type,index,ele)
					}
				}
			},
			removeParent(item,type) {
				this.$refs.comMessage.showQuestionMessage("确定移除扫描信息?",
					res => {
						if (res) {
							item.scaned = false
							item.handleQty = null;
							item.packList.forEach(subItem => {
								subItem.scaned = false
								subItem.handleQty = null;
							})

							this.$emit('updateData',type,item)
							this.$forceUpdate()
						}
					});
			},



			remove(item,type,index,ele) {
				this.$refs.comMessage.showQuestionMessage("确定移除扫描信息?",
					res => {
						if (res) {
							item.scaned = false
							item.handleQty = null;
							this.collapseChange()
							this.$emit('updateData',type,item,index,ele)
							this.$forceUpdate()
						}
					});
			},

			edit(item) {
				this.editItem = item;
				console.log(777,item)
				this.$refs.receiptEdit.openTaskEditPopup(item.qty, item.handleQty, item.labelQty, item.packQty);
			},
			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>