<template>
	<view class="" style="background-color: #fff;">
		<!-- <view class="cell_box uni-flex uni-row">
			<view class="cell_info">
				<view class="text_lightblue">车间</view>
				<view>{{workShopCode}}</view>
			</view>
			<view class="cell_info">
				<view class="text_lightblue">生产线</view>
				<view>{{dataContent.productionLineCode}}</view>
			</view>
			<view class="cell_info">
				<view class="text_lightblue">工位</view>
				<view>{{ dataContent.workStationCode }}</view>
			</view>
			<view class="cell_info">
				<view class="text_lightblue">原材料库</view>
				<view>{{ dataContent.toLocationCode}}</view>
			</view>
		</view> -->
		<uni-collapse ref="collapse1" @change="">
			<uni-collapse-item :open="true">
				<template v-slot:title>
					<item-compare-qty :dataContent="dataContent" :handleQty="Number(dataContent.handleQty)">
					</item-compare-qty>
				</template>
				<u-line />
				<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">
							<recommend :detail="item" :isShowToLocation="false">
							</recommend>
						</uni-swipe-action-item>
					</uni-swipe-action>
				</view>
				<u-line />
			</uni-collapse-item>
		</uni-collapse>
		<balance-qty-edit ref="qtyEdit" :settingParam="settingParam" @confirm="confirm"></balance-qty-edit>
		<win-scan-location ref="scanLocationCode" title="目标库位" @getLocation='getLocation'
			:locationTypeList="locationTypeList"></win-scan-location>
		<com-message ref="message"></com-message>
	</view>
</template>

<script>
	import itemCompareQty from '@/mycomponents/item/itemCompareQty.vue'
	import recommend from '@/mycomponents/recommend/recommend.vue'
	import balanceQtyEdit from '@/mycomponents/qty/balanceQtyEdit.vue'
	import comMessage from '@/mycomponents/common/comMessage.vue'
	import winScanLocation from "@/mycomponents/scan/winScanLocation.vue"
	import {
		getDetailOption,
		getPurchaseReceiptOption
	} from '@/common/array.js';

	export default {
		emits: ['openDetail',"updateData"],
		components: {
			itemCompareQty,
			recommend,
			balanceQtyEdit,
			comMessage,
			winScanLocation
		},
		props: {
			dataContent: {
				type: Object,
				default: {}
			},
			settingParam: {
				type: Object,
				default: {}
			},
			isShowPack: {
				type: Boolean,
				default: true
			},
			isShowBatch: {
				type: Boolean,
				default: true
			},
			isShowLocation: {
				type: Boolean,
				default: true
			},
			locationTypeList: {
				type: Array,
				default: []
			},
		},
		watch: {

		},

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

		mounted() {
			if (this.detailOptions.length == 0) {
				this.detailOptions = getDetailOption();
			}
			if (this.scanOptions.length == 0) {
				this.scanOptions = getPurchaseReceiptOption(this.settingParam.allowModifyQty, this.settingParam
					.allowModifyLocation)
			}
		},

		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.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);
				// this.showItem = item;
				// this.$refs.jobDetailPopup.openPopup(item)
			},
			remove(item) {
				this.$refs.message.showQuestionMessage("确定移除扫描信息?",
					res => {
						if (res) {
							item.scaned = false
							item.balance = {}
							item.handleQty = null;
							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>
