<template>
	<view class="" style="background-color: #fff;">
		<uni-collapse ref="collapse1" @change="">
			<uni-collapse-item :open="true">
				<template v-slot:title>
					<item-qty :dataContent="dataContent" :handleQty="dataContent.handleQty"></item-qty>
				</template>
				<view class='split_line'></view>
				<view class="" v-for="(item,index) in dataContent.subList">
					<uni-swipe-action ref="swipeAction">
						<uni-swipe-action-item :right-options="item.scaned?scanOptions:detailOptions"
							@click="swipeClick($event,item)">
							<recommend :detail="item"  :isShowFromLocation="true" :isShowToLocation="true"></recommend>
						</uni-swipe-action-item>
					</uni-swipe-action>
				</view>
				<!-- <view class='split_line'></view> -->
			</uni-collapse-item>
		</uni-collapse>
		<balance-qty-edit ref="qtyEdit" :settingParam="settingParam" @confirm="confirm" :allowEditStatus="true"></balance-qty-edit>
		<win-scan-location ref="scanLocationCode" title="目标库位" @getLocation='getLocation'
			></win-scan-location>
		<detail-info-popup ref="detailInfoPopup"></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 balanceQtyEdit from '@/mycomponents/qty/balanceQtyEdit.vue'
	import detailInfoPopup from '@/pages/inventoryMove/coms/detailInfoPopup.vue'
	import winScanLocation from "@/mycomponents/scan/winScanLocation.vue"
	
	import {
		getDetailOption,
		getPurchaseReceiptOption
	} from '@/common/array.js';


	export default {
		components: {
			itemQty,
			recommend,
			balanceQtyEdit,
			detailInfoPopup,
			winScanLocation
		},
		data() {
			return {
				option: [],
				title: "推荐详情",
				showItem: {},
				editItem: {
					
				},
				detailOptions: [],
				scanOptions: []
			}
		},
		props: {
			dataContent: {
				type: Object,
				default: {}
			},
			settingParam: {
				type: Object,
				default: {}
			},
		},
		watch: {
			// dataContent: {
			// 	handler(newName, oldName) {},
			// 	immediate: true,
			// 	deep: true
			// }
		},
		mounted() {
			if (this.detailOptions.length == 0) {
				this.detailOptions = getDetailOption();
			}
			if (this.scanOptions.length == 0) {
				this.scanOptions = getPurchaseReceiptOption(this.settingParam.allowModifyQty, this.settingParam
					.allowModifyLocation)
			}
		},
		methods: {
			openDetailCardPopup() {
				this.$refs.winHint.openScanPopup()
			},
			swipeClick(e, item) {
				if (e.content.text == "详情") {
					this.detail(item)
				} else if (e.content.text == "编辑") {
					this.edit(item)
				} else if (e.content.text == "库位") {
					this.showLocation(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.$emit('openDetail', item);
			},

			remove(item) {
				this.$refs.message.showQuestionMessage("确定移除扫描信息?",
					res => {
						if (res) {
							item.scaned = false
							item.balance = {}
							item.handleQty = 0;
							this.$forceUpdate()
							this.$emit('remove', item)
						}
					});
			},
			confirm(qty) {
				this.editItem.handleQty = qty;
				this.$emit('updateData')
			},
			showLocation(item) {
				this.locatonItem = item;
				this.$refs.scanLocationCode.openScanPopup();
			},
			//扫描源库位
			getLocation(location, code) {
				this.locatonItem.toLocationCode =code;
				this.$emit('updateData')
			},
		}
	}
</script>

<style>
</style>
