<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>
				<u-line />
				<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)">
							<!-- <view class="uni-row">
								<view class="location_view uni-inline-item">
									<text class="card_location">库位</text>
									<text style="margin-left: 10px">{{item.FromLocationCode}}</text>
									<text class="card_location"> </text>
									<text>{{item.toLocationCode}}</text>
								</view>
							</view> -->
							<view class="uni-row ">
								<view class="location_view uni-inline-item">
									<text class="card_location">来源库位</text>
									<text style="margin-left: 10px">{{item.FromLocationCode}}</text>
								</view>
								<view class="location_view uni-inline-item">
									<text class="card_location">目标库位</text>
									<text style="margin-right: 10px">{{item.toLocationCode}}</text>
								</view>
							</view>
							<recommend :detail="item" :record="item.record" :isShowLocation="false"></recommend>

							<u-line />
						</uni-swipe-action-item>
					</uni-swipe-action>
				</view>
			</uni-collapse-item>
		</uni-collapse>
		<balance-qty-edit ref="qtyEdit" :dataContent="editItem" :settingParam="settingParam" @confirm="confirm">
		</balance-qty-edit>
		<detail-info-popup ref="detailInfoPopup"></detail-info-popup>
		<com-message ref="message"></com-message>
	</view>
</template>

<script>
	import location from '@/mycomponents/balance/location.vue'
	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 comMessage from '@/mycomponents/common/comMessage.vue'

	import {
		getDetailOption,
		getDetailRemoveOption,
		getDetailEditRemoveOption
	} from '@/common/array.js';


	export default {
		components: {
			location,
			itemQty,
			recommend,
			balanceQtyEdit,
			detailInfoPopup,
			comMessage
		},
		data() {
			return {
				option: [],
				title: "推荐详情",
				showItem: {},
				editItem: {
					record: {

					}
				},
				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 = getDetailEditRemoveOption();
				// if (this.dataContent.allowModifyQty == 1) {
				// 	this.scanOptions = getDetailEditRemoveOption();
				// } else {
				// 	this.scanOptions = getDetailRemoveOption();
				// }
			}
		},
		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.remove(item)
				}
			},

			edit(item) {
				this.editItem = item;
				this.$refs.qtyEdit.openEditPopup(item.balance, item.record.qty);
			},

			detail(item) {
				this.showItem = item;
				// this.$refs.receiptHint.openScanPopup()
				this.$refs.detailInfoPopup.openPopup(item)
			},

			remove(item) {
				this.$refs.message.showQuestionMessage("确定移除扫描信息?",
					res => {
						if (res) {
							item.scaned = false
							item.record = {}
							item.balance = {}
							item.inventoryStatus = item.RecommendInventoryStatus;
							// item.record.qty = 0;
							this.$forceUpdate()
							this.$emit('remove', item)
						}
					});
			},
			confirm(qty) {
				this.editItem.record.qty = qty;
				this.$emit('updateData', this.editItem)
			}
		}
	}
</script>

<style>
</style>
