<template>
	<view class="" style="background-color: #fff;">
		<uni-collapse ref="collapse1" >
			<uni-collapse-item :open="true">
				<template v-slot:title>
					<uni-swipe-action ref="swipeAction">
						<uni-swipe-action-item @click="removeData($event,dataContent)" :right-options="removeOptions">
							<item-qty :dataContent="dataContent" 
								:isShowBalanceQty="false"
								:isShowBalance="true"></item-qty>
						</uni-swipe-action-item>
					</uni-swipe-action>
				</template>

				<view class="" v-for="(item,index) in dataContent.subList">
					<uni-swipe-action ref="swipeAction">
						<uni-swipe-action-item @click="swipeClick($event,item,index)"
							:right-options="item.scaned?scanOptions:detailOptions">	
							<comMovebalance :dataContent="item" :isShowStdPack="false" :isShowPack="true"
								:fromInventoryStatus="item.inventoryStatus" :toInventoryStatus="item.toInventoryStatus"
								:isShowLocation="true" :allowEditStatus='allowEditStatus'></comMovebalance>
						</uni-swipe-action-item>
					</uni-swipe-action>
					<view class='split_line'></view>
				</view>
			</uni-collapse-item>
		</uni-collapse>
		<balanceQtyEdit ref="balanceQtyEdit" @confirm="confirm" :isShowStatus="isShowStatus"
			:allowEditStatus="allowEditStatus"
			:allowEditQty="allowEditQty"
			>
		</balanceQtyEdit>
		<job-detail-popup ref="winHint" :dataContent="showItem"></job-detail-popup>
		<comMessage ref="comMessage"></comMessage>
	</view>
</template>

<script>
	import itemQty from '@/mycomponents/item/itemQty.vue'
	import recommend from '@/mycomponents/recommend/recommend.vue'
	import jobDetailPopup from '@/mycomponents/job/jobDetailPopup.vue'
	import balance from '@/mycomponents/balance/balance.vue'
	import balanceMove from '@/mycomponents/balance/balanceMove.vue'
	import comMovebalance from '@/pages/inventoryMove/coms/comMovebalance.vue'
	import balanceQtyEdit from '@/mycomponents/qty/balanceQtyEdit.vue'

	import {
		getDetailOption,
		getDetailEditRemoveOption,
		getRemoveOption
	} from '@/common/array.js';
	export default {
		components: {
			itemQty,
			recommend,
			jobDetailPopup,
			balance,
			balanceQtyEdit,
			balanceMove,
			comMovebalance,
		},
		props: {
			dataContent: {
				type: Object,
				default: {}
			},
			settingParam: {
				type: Object,
				default: {}
			},
			fromInventoryStatus: {
				type: String,
				default: ""
			},
			toInventoryStatus: {
				type: String,
				default: ""
			},
			isShowStatus: {
				type: Boolean,
				default: true
			},
			allowEditStatus: {
				type: Boolean,
				default: false
			},
			allowEditQty: {
				type: Boolean,
				default: false
			},

		},
		watch: {
			dataContent: {
				handler(newName, oldName) {
					if (this.dataContent.subList.length > 0) {
						this.$nextTick(res => {
							setTimeout(() => {
								if (this.$refs.collapse1) {
									this.$refs.collapse1.resize();
								}
							}, 500)
						})
					}
				},
				
				
				immediate: true,
				deep: true
			}
		},

		data() {
			return {
				option: [],
				title: "推荐详情",
				showItem: {},
				editItem: {},
				detailOptions: [],
				scanOptions: [],
				removeOptions: [],
				dataList: []
			}
		},

		mounted() {
			this.detailOptions = getDetailOption();
			this.scanOptions = getDetailEditRemoveOption();
			this.removeOptions = getRemoveOption();
		},

		methods: {
			removeData(e, dataContent) {
				if (e.content.text == "移除") {
					this.$refs.comMessage.showQuestionMessage("确定移除扫描信息?",
						res => {
							if (res) {
								this.$emit('removeData', dataContent)
							}
						});
				}
			},
			swipeClick(e, item, index) {
				if (e.content.text == "详情") {
					this.detail(item)
				} else if (e.content.text == "编辑") {
					this.edit(item)
				} else if (e.content.text == "移除") {
					this.remove(item, index)
				}
			},

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

			detail(item) {
				this.showItem = item;
				this.dataList = [

					{
						title: "箱码",
						content: item.packingNumber
					},
					{
						title: "批次",
						content: item.batch
					},
					{
						title: "库位",
						content: item.locationCode
					},
					{
						title: "数量",
						content: item.qty
					},
					{
						title: "单位",
						content: item.uom
					}
				]
				this.$refs.winHint.openScanPopup(this.showItem)
			},
			remove(item, index) {
				this.$refs.comMessage.showQuestionMessage("确定移除扫描信息?",
					res => {
						if (res) {
							this.dataContent.subList.splice(index, 1)
							this.$emit('removePack', item)
						}
					});
			},
			confirm(qty) {
				this.editItem.handleQty = qty;
				this.$emit('updateData')
			}
		}
	}
</script>

<style>
</style>
