<template>
	<view class="" style="background-color: #fff;">
		<uni-collapse ref="collapse1" @change="">
			<uni-collapse-item :open="true">
				<template v-slot:title>
					<uni-swipe-action ref="swipeAction">
						<uni-swipe-action-item @click="removeItem($event,dataContent)" :right-options="removeOptions">
							<item-qty :dataContent="dataContent" :handleQty="dataContent.handleQty"
								:isShowBalance="true" :isShowBalanceQty="isShowBalanceQty"></item-qty>
						</uni-swipe-action-item>
					</uni-swipe-action>
				</template>
				<!-- <u-line /> -->
				<view class="" v-for="(detail,index) in dataContent.subList">
					<uni-swipe-action ref="swipeAction">
						<uni-swipe-action-item @click="swipeClick($event,detail,index)"
							:right-options="detail.scaned?scanOptions:detailOptions">
							<balance :dataContent="detail" :isShowStdPack="false" :isShowStatus="true"
								:isShowPack="true" :isShowFromLocation="isShowFromLocation" :isShowToLocation="isShowToLocation">
							</balance>
						</uni-swipe-action-item>
					</uni-swipe-action>
					<!-- <u-line /> -->
				</view>
			</uni-collapse-item>
		</uni-collapse>
		<balance-qty-edit ref="balanceQtyEdit" @confirm="confirm"></balance-qty-edit>
		<record-detail-popup ref="recordDetailPopup"></record-detail-popup>
	<!-- 	<balance-detail-popup ref="balanceDetailPopup"></balance-detail-popup> -->
		<comMessage ref="comMessage"></comMessage>
	</view>
</template>

<script>
	import itemQty from '@/mycomponents/item/itemQty.vue'
	// import jobDetailPopup from '@/mycomponents/job/jobDetailPopup.vue'
	import balance from '@/mycomponents/balance/balance.vue'
	import recommend from '@/mycomponents/recommend/recommend.vue'
	import balanceQtyEdit from '@/mycomponents/qty/balanceQtyEdit.vue'
	import balanceDetailPopup from '@/mycomponents/balance/balanceDetailPopup.vue'
	import purchaseLabel from '@/mycomponents/balance/purchaseLabel.vue'
	import location from '@/mycomponents/balance/location.vue'
	import recordDetailPopup from '@/mycomponents/detail/recordDetailPopup.vue'

	import {
		getDetailOption,
		getDetailEditRemoveOption,
		getClearOption
	} from '@/common/array.js';
	export default {
		components: {
			itemQty,
			recommend,
			balance,
			balanceQtyEdit,
			balanceDetailPopup,
			purchaseLabel,
			location,
			recordDetailPopup
			// winListHint
		},
		props: {
			dataContent: {
				type: Object,
				default: {}
			},
			settingParam: {
				type: Object,
				default: {}
			},

			isShowStatus: {
				type: Boolean,
				default: false
			},

			isShowFromLocation: {
				type: Boolean,
				default: true
			},

			isShowToLocation: {
				type: Boolean,
				default: true
			},

			isShowBalanceQty: {
				type: Boolean,
				default: false
			},
		},
		watch: {
			dataContent: {
				handler(newName, oldName) {
					if (this.dataContent.subList.length > 0) {
						if (this.$refs.collapse1 != undefined && this.$refs.collapse1 != null) {
							this.$nextTick(res => {
								this.$refs.collapse1.resize()
							})
						}
					}
				},
				immediate: true,
				deep: true
			}
		},

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

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

		methods: {
			removeItem(e, dataContent) {
				if (e.content.text == "清空") {
					this.$refs.comMessage.showQuestionMessage("确定清空物料及箱码信息?",
						res => {
							if (res) {
								this.$emit('removeItem')
								// this.$emit('removeItem', this.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(this.editItem, this.editItem.handleQty);
			},

			detail(item) {
				this.showItem = item;
				this.$refs.recordDetailPopup.openPopup(item);
			},

			remove(item, index) {
				this.$refs.comMessage.showQuestionMessage("确定移除扫描信息?",
					res => {
						if (res) {
							this.dataContent.subList.splice(index, 1)
							this.$emit('removePack')
						}
					});
			},

			confirm(qty) {
				// this.editItem.qty = qty;
				this.editItem.handleQty = qty;
				this.$emit('updateData')
			}
		}
	}
</script>

<style>
</style>
