<template>
	<view>
		<!-- <requiredLocation title="需求库位" :locationCode="dataContent.toLocationCode"
			:isShowEdit="dataContent.allowModifyLocation==1"></requiredLocation> -->

		<view v-for="(item,index) in dataContent.subList">
		<uni-swipe-action ref="swipeAction" :class="item.scaned? 'scan_view':''">
			<uni-swipe-action-item
				:right-options="(item.scaned&&isEdit)?editAndRemoveOptions : item.scaned? removeOptions:options"
				@click="swipeClick($event,item,index)" style='padding:0px 0px  5px 0px;align-items: center;'>
					<item-qty :dataContent="item" :handleQty="item.handleQty" :isShowBalanceQty="false"></item-qty>
					<location :locationCode="item.fromLocationCode">
					</location>
				<handleBalanceBatch :detail="item" :isShowLocation="false"
					 :isShowBatch="true" :isShowPack='false'>
				</handleBalanceBatch>
				</uni-swipe-action-item>
			</uni-swipe-action>
		</view>
	</view>
	<qtyEdit ref="balanceQtyEdit" @confirm="confirm" :isShowStatus="true"></qtyEdit>
	<detail-info-popup ref="detailInfoPopup"></detail-info-popup>
	<comMessage ref="message"></comMessage>
</template>

<script>
	import itemQty from '@/mycomponents/item/itemQty.vue'
	import recommend from '@/mycomponents/recommend/recommend.vue'
	import recommendBalance from '@/mycomponents/balance/recommendBalance.vue'
	import handleBalance from '@/mycomponents/balance/handleBalance.vue'
	import handleBalanceBatch from '@/mycomponents/balance/handleBalanceBatch.vue'
	import recommendQtyEdit from '@/mycomponents/qty/recommendQtyEdit.vue'
	import jobDetailPopup from '@/mycomponents/job/jobDetailPopup.vue'
	import requiredLocation from '@/mycomponents/location/requiredLocation.vue'
	import balanceQtyEdit from '@/mycomponents/qty/balanceQtyEdit.vue'
	import qtyEdit from '@/mycomponents/qty/qtyEdit.vue'
	import location from '@/mycomponents/balance/location.vue'
	import detailInfoPopup from '@/pages/productionReceipt/coms/detailInfoPopup.vue'

import {
		getDetailOption,
		getPurchaseReceiptOption,
		getRemoveOption,
		getEditRemoveOption
	} from '@/common/array.js';

	export default {
		emits: ['updateData'],
		components: {
			itemQty,
			recommend,
			recommendBalance,
			handleBalance,
			recommendQtyEdit,
			requiredLocation,
			qtyEdit,
			location,
			detailInfoPopup,
			handleBalanceBatch
		},
		props: {
			dataContent: {
				type: Object,
				default: null
			},
			settingParam: {
				type: Object,
				default: null
			},
			isEdit: {
				type: Boolean,
				default: true
			},
		},
		watch: {

		},

		data() {
			return {
				option: [],
				showItem: {},
				editItem: {},
				batchItem: {},
				detailOptions: [],
				scanOptions: [],
				removeOptions: []
			}
		},

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

		methods: {
			resizeCollapse() {
				this.$nextTick(r => {
					this.$refs.collapse.forEach(r => {
						r.childrens.forEach(i => {
							i.init();
						})
						r.resize();
					})
				});
			},

			swipeClick(e, item, index) {
				if (e.content.text == "编辑") {
					this.edit(item)
				} else if (e.content.text == "移除") {
					this.remove(item, index)
				}
			},

			edit(item) {
				let that = this;
				that.editItem = item;
				that.$refs.balanceQtyEdit.openEditPopup(item);
			},

			detail(item) {
				this.showItem = item;
				this.$refs.receiptHint.openScanPopup()
			},
			remove(item, index) {
				this.$refs.message.showQuestionMessage("确定移除扫描信息?",
					res => {
						if (res) {
							item.handleQty = 0;
							item.scaned = false ;
						}
					});
			},
			confirm(val) {
				this.editItem.handleQty = val;
				this.$emit('updateData', this.editItem)
				// let qty = 0;
				// this.batchItem.Records.forEach(r => {
				// 	qty += Number(r.qty);
				// })
				// this.batchItem.handleQty = qty;
			}
		}
	}
</script>

<style>
</style>
