<template>
	<view class="" style="background-color: #fff;">

					<item-qty :dataContent="dataContent" :handleQty="dataContent.handleQty"></item-qty>
		
				<view class='split_line'></view>
				<view class="" v-for="(item,index) in dataContent.subList">
					<uni-swipe-action ref="swipeAction">
						<uni-swipe-action-item @click="swipeClick($event,item)"
							:right-options="item.scaned?scanOptions:detailOptions">
							{{item.scaned}}
							<recommendBatch :detail="item"  ></recommendBatch>
						</uni-swipe-action-item>
					</uni-swipe-action>
					<view class='split_line'></view>
				</view>
		

		<balance-qty-edit ref="qtyEdit" :settingParam="settingParam" @confirm="confirm"></balance-qty-edit>
		<scrap-detail-info-popup ref="jobDetailPopup" :dataContent="showItem"></scrap-detail-info-popup>
		<comMessage ref="message"></comMessage>
	</view>
</template>

<script>
	import itemQty from '@/mycomponents/item/itemQty.vue'
	import recommend from '@/mycomponents/recommend/recommend.vue'
	import recommendBatch from '@/mycomponents/recommend/recommendBatch.vue'
	import jobDetailPopup from '@/mycomponents/detail/jobDetailPopup.vue'
	import scrapDetailInfoPopup from '@/pages/scrap/coms/scrapDetailInfoPopup.vue'
	import balanceQtyEdit from '@/mycomponents/qty/balanceQtyEdit.vue'
	import location from '@/mycomponents/balance/location.vue'
	import toLocation from '@/mycomponents/balance/toLocation.vue'
	import batch from '@/mycomponents/balance/batch.vue'
	import itemCompareQty from '@/mycomponents/item/itemCompareQty.vue'
	import config from '@/static/config.js'
	
	import {
		getRemoveOption,
		getEditRemoveOption,
		getDetailEditRemoveOption,
	} from '@/common/array.js';

	export default {
		components: {
			itemQty,
			recommendBatch,
			jobDetailPopup,
			scrapDetailInfoPopup,
			balanceQtyEdit,
			location,
			toLocation,
			itemCompareQty,
			batch,
		},
		props: {
			dataContent: {
				type: Object,
				default: {}
			},
			settingParam: {
				type: Object,
				default: {}
			},
			isEdit: {
				type: Boolean,
				default: true
			},
		},
		watch: {

		},

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

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

		mounted() {
			this.scanOptions = getDetailEditRemoveOption();
			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.remove(item)
				}
			},
			edit(item) {
				this.editItem = item;
				this.$refs.qtyEdit.openEditPopup(item.balance, item.handleQty);
			},

			detail(item) {
				this.showItem = item;
				console.log("提交参数", JSON.stringify(item));
				this.$refs.jobDetailPopup.openPopup(item)
			},
			remove(item) {
				this.$refs.message.showQuestionMessage("确定移除扫描信息?",
					res => {
						if (res) {
							item.scaned = false
							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>
