<template>
	<view class="page-wraper">
		<view class="page-wraper" v-if="dataList.length>0">
			<view class="page-main">
				<scroll-view scroll-y="true" class="page-main-scroll">
					<view class="detail-list">
						<comCountRecordCard  :dataContent="dataContent" :recordList="dataList"  @removeData="removeData"
							:isShowStatus="true" @updateData="updateData" @removePack='removePack' :allowEditQty="true"
							:allowEditStatus="true">
						</comCountRecordCard>
					</view>
				</scroll-view>
			</view>

		</view>

		<comMessage ref="comMessage"></comMessage>
	</view>
</template>

<script>
	import comCountRecordCard from '@/pages/count/coms/comCountRecordCard.vue'

	import {
		inventoryMoveRecordSubmit,
		getBasicLocationByCode,
		getBasicItemByCode
	} from '@/api/request2.js';

	import {
		getDirectoryItemArray,
		getItemTypeName,
		getInventoryStatusName,
		getInventoryStatusDesc
	} from '@/common/directory.js';

	import {
		getPrecisionStrategyList
	} from '@/common/balance.js';

	import {
		getPackingNumberAndBatchByList,
		deepCopyData,
	} from '@/common/basic.js';

	import {
		getBusinessType,
		createItemInfo,
		createDetailInfo,
		calcHandleQty,
		createItemInfoForLabel,
		createDetailInfoForLabel
	} from '@/common/record.js';

	import {
		calc
	} from '@/common/calc.js';

	export default {
		components: {
			comCountRecordCard,
		},
		props: {},
		onLoad(options) {
			if (options.data) {
				this.dataList = JSON.parse(decodeURIComponent(options.data));
				this.fromLocationCode = this.dataList[0].fromLocationCode
				this.dataContent.itemName = this.dataList[0].itemName;
				this.dataContent.itemDesc1=this.dataList[0].itemDesc1;
				this.dataContent.itemCode = this.dataList[0].itemCode;
				this.dataContent.uom =this.dataList[0].uom;
				this.dataContent.batch=this.dataList[0].batch;
				this.dataContent.inventoryStatus=this.dataList[0].inventoryStatus;
				var handleQty = 0;
				this.dataList.forEach(item => {
					handleQty = calc.add(Number(handleQty), Number(item.handleQty))
				})
				this.dataContent.qty=handleQty;

			}
		},

		//拦截返回按钮事件
		onBackPress(e) {
			//已经接收但是没提交任务
			if (e.from === 'backbutton') {
				var dataContent={
					locationCode : this.fromLocationCode,
					itemName :this.dataContent.itemName,
					itemDesc1:this.dataContent.itemDesc1,
					itemCode : this.dataContent.itemCode,
					uom :this.dataContent.uom,
					batch:this.dataContent.batch,
					inventoryStatus:this.dataContent.inventoryStatus,
					recordList:this.dataList
				}
				uni.$emit('refreshData',   dataContent);
				uni.navigateBack();
				return true;
			}
		},

		data() {
			return {
				fromLocationCode: "",
				toInventoryStatus: "",
				businessType: {}, //业务类型
				dataContent: {},
				businessTypeCode: "Count",
				dataList: [],
				managementType: {}
			}
		},

		mounted() {

		},


		methods: {


			showErrorMessage(message) {
				if (this.$refs.scanPopup) {
					this.$refs.scanPopup.packLoseFocus()
				}
				this.$refs.comMessage.showErrorMessage(message, res => {
					if (res) {
						if (this.$refs.scanPopup) {
							this.$refs.scanPopup.packGetFocus()
						}
					}
				});
			},
			updateData() {
				calcHandleQty(this.dataList);
				for (var i = 0; i < this.dataList.length; i++) {
					let item = this.dataList[i];
					if (item.qty == 0) {
						this.dataList.splice(i, 1)
					}
				}
			},

			removePack() {
				// for (var i = 0; i < this.dataList.length; i++) {
				// 	var item = this.dataList[i];
				// 	if (item.subList.length == 0) {
				// 		this.dataList.splice(i, 1)
				// 	}
				// }
				// this.updateData();
			},


			removeData(item) {
				for (let i = 0; i < this.dataList.length; i++) {
					if (this.dataList[i].itemCode == item.itemCode) {
						this.dataList.splice(i, 1)
					}
				}
			},
			clearData() {
				this.fromLocationCode = '';
				this.subList = [];
				this.dataList = [];
				this.dataContent = {}
				this.toWarehouseCode = ""
			},

		}
	}
</script>

<style>
</style>