<template>
	<view :class="detail.scaned?'scan_view':''" style="background-color: #ffffff; border-bottom: 1upx solid #EEEEEE;">

		<!-- uni-inline-item 暂时拿掉-->
		<uni-collapse ref="collapse1">
			<uni-collapse-item :open="true" :show-animation="true">
				<template v-slot:title>
					<view class="uni-flex uni-row space-between" style="align-items: center">
						<view style="word-break: break-all;">
							<!-- 	<container v-if="isShowContainer&&detail.containerNumber!=null" :container="detail.containerNumber">
							</container> -->
							<pack v-if="isShowPack && detail.packingNumber" :isShowPackingNumberProps="isShowPackingNumberProps"
								:packingCode="detail.packingNumber"></pack>
							<batch v-if="isShowBatch && detail.batch!=null" :batch="detail.batch"></batch>
							<location v-if="isShowFromLocation" :title="formLocationTitle" :locationCode="detail.fromLocationCode">
							</location>
							<!-- 	<to-location></to-location> -->
							<to-location v-if="isShowToLocation" title="目标库位" :locationCode="detail.toLocationCode">
							</to-location>
						</view>

					</view>
				</template>
				<uni-swipe-action ref="swipeAction" style="margin-top: 10px;" v-for="(item,index) in detail.packList"
					:key='index'>
					<uni-swipe-action-item
						:right-options="(item.scaned&&settingParam.allowModifyQty == 'TRUE')?editAndRemoveOptions : item.scaned? removeOptions:[]"
						@click="itemCoceClick($event,item,index,detail)">
						<view class="uni-flex uni-row space-between" style="align-items: center"
							:class="item.scaned?'scan_view':''">
							<view class="" style="flex:1">
								<board-number v-if="item.boardNumber" :packingCode="item.boardNumber"></board-number>
								<batch v-if="isShowBatch && item.batch!=null" :batch="item.batch"></batch>
							</view>

							<view style="word-break: break-all;" class="uni-flex uni-row center">
								<!-- ||detail.handleQty==0 可能会有扫描到0的情况-->
								<recommend-qty v-if="item.handleQty==null || item.handleQty==undefined" :dataContent="item"
									:isShowStdPack="false" :isShowStatus="isShowStatus"></recommend-qty>
								<compare-qty v-else :dataContent="item" :recommendQty="Number(item.qty)"
									:handleQty="Number(item.handleQty)" :isShowStdPack="false" :isShowStatus="isShowStatus"
									:isShowRecommendQty='false' :isShowPackUnit='false'>
								</compare-qty>
							</view>

						</view>
					</uni-swipe-action-item>
				</uni-swipe-action>
			</uni-collapse-item>
		</uni-collapse>
		<comMessage ref="message"></comMessage>
		<recommend-qty-edit ref="receiptEdit" :dataContent="editItem" :settingParam="settingParam" @confirm="confirm" :showBalanceQty='true'>
		</recommend-qty-edit>
	</view>
</template>

<script>
	import container from '@/mycomponents/container/container.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 recommendQty from '@/mycomponents/qty/recommendQty.vue'
	import compareQty from '@/mycomponents/qty/compareQty.vue'
	import config from '@/static/config.js'
	import boardNumber from '@/mycomponents/balance/boardNumber.vue'
	import recommendQtyEdit from '@/mycomponents/qty/recommendQtyEdit.vue'
	import {
		getEditRemoveOption,
		getRemoveOption,
	} from '@/common/array.js';
	export default {
		emits: ['updateData','deleteData'],
		components: {
			container,
			pack,
			location,
			toLocation,
			batch,
			recommendQty,
			compareQty,
			boardNumber,
			recommendQtyEdit
		},

		data() {
			return {
				removeOptions: [],
				editAndRemoveOptions: [],
				editItem:{}
			}
		},
		mounted() {
			this.removeOptions = getRemoveOption()
			this.editAndRemoveOptions = getEditRemoveOption()
		},
		props: {
			detail: {
				type: Object,
				default: {}
			},
			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: '库位'
			},
			formLocationTitle: {
				type: String,
				default: '来源库位'
			},
			isShowPackingNumberProps: {
				type: Boolean,
				default: false
			},
			settingParam: {
				type: Object,
				default: {}
			},


		},
		watch: {
			// 模拟扫描功能
			detail: {
				handler(newVal, oldVal) {
					if (newVal.scaned) {
						newVal.copyContent = "HPQ;V1.0;I" + newVal.itemCode + ";P" + newVal.packingNumber + ";B" + newVal.batch +
							";Q" + newVal.qty
					} else {
						newVal.copyContent = ''
					}
					console.log('newVal.copyContent', newVal.copyContent)
				},
				immediate: true,
				deep: true
			}
		},
		methods: {
			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;
			},
			resizeCollapse() {
				this.$refs.collapse1.resize()
				// this.$refs.collapse1.childrens.forEach(i => {
				// 	i.init();
				// })
			},
			itemCoceClick(e, item, index, detail) {
				if (e.content.text == "编辑") {
					this.edit(item)
				} else if (e.content.text == "移除") {
					// this.dataContent.subList.splice(index, 1);
					this.$refs.message.showQuestionMessage("确定移除扫描信息?",
						res => {
							if (res) {
								detail.packList.splice(index, 1)
								item.scaned = false
								item.handleQty = 0
								this.$nextTick(() => {
									this.resizeCollapse()
								})
								this.$emit('deleteData',e, item, index,detail)
							}
						});
				}
			},
			edit(item) {
				this.editItem = item;
				this.$refs.receiptEdit.openTaskEditPopup(item.qty, item.handleQty, item.labelQty);
			},
			confirm(val) {
				this.editItem.handleQty =  Number(val);
				this.$emit('updateData', this.editItem)
			}
		}
	}
</script>

<style>
</style>