<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)">
							<recommend :detail="item" ></recommend>
						<view :class="item.scaned?'scan_view':'' ">
							<view class="" style="font-size: 30rpx;">
								不合格数量 : {{item.FailedQty}}
							</view>
							<view class="" style="font-size: 30rpx;margin-top: 10rpx;">
								不合格原因 : {{item.FailedReason}}
							</view>
						</view>
							<u-line />
						</uni-swipe-action-item>
					</uni-swipe-action>
				</view>
			</uni-collapse-item>
		</uni-collapse>
		<inspectQtyEdit ref="qtyEdit" :dataContent="editItem" :settingParam="settingParam" @confirm="confirm">
		</inspectQtyEdit>
		<job-detail-popup ref="receiptHint" :dataContent="showItem"></job-detail-popup>
		<comMessage ref="message"></comMessage>
	</view>
</template>

<script>
	import Batch from "@/mycomponents/Batch/Batch.vue"
	import itemQty from '@/mycomponents/item/itemQty.vue'
	import recommend from '@/mycomponents/recommend/recommend.vue'
	import inspectQtyEdit from '@/mycomponents/qty/inspectQtyEdit.vue'

	import jobDetailPopup from '@/mycomponents/job/jobDetailPopup.vue'
	import comMessage from '@/mycomponents/common/comMessage.vue'

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


	export default {
		components: {
			Batch,
			itemQty,
			recommend,
			inspectQtyEdit,
			jobDetailPopup,
			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.settingParam.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.record, item.record.qty);
			},

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

			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,faileQty,reasonInfo) {
				this.editItem.record.qty = qty;
				this.editItem.record.FailedQty = faileQty;
				this.editItem.FailedQty = faileQty;
				
				this.editItem.FailedReason = reasonInfo.text;
				this.editItem.record.FailedReason = reasonInfo.text;
				this.$emit('updateData', this.editItem)
			}
		}
	}
</script>

<style>
</style>
