<template>
	<view style="margin: 10rpx;">
		<u-navbar back-text="返回" title="无单据出库" :background="background"></u-navbar>
		<u-form ref="testForm">
			<u-form-item :border-bottom="false">
				<p>扫描条码:</p>
				<u-input :border="true" v-model="MATERIALPACKINGNAME" placeholder="请扫描条码" :focus="focusBarCode"
					@confirm="ScanBarCode" />
			</u-form-item>
			<br />
		</u-form>
		<br />
		<uni-table ref="BoxList" border stripe type="false">
			<uni-tr>
				<uni-th align="center">标签</uni-th>
				<uni-th align="center">批次</uni-th>
				<uni-th align="center">品名</uni-th>
				<uni-th align="center">料号</uni-th>
				<uni-th align="center">规格</uni-th>
				<uni-th align="center">阶段</uni-th>
				<uni-th align="center">数量</uni-th>
				<uni-th align="center">组织</uni-th>
				<uni-th align="center">仓库</uni-th>
				<uni-th align="center">货位</uni-th>
			</uni-tr>
			<uni-tr v-for="(item, index) in BoxListInfo" :key="index">
				<uni-td align="center">{{ item.MATERIALPACKINGNAME}}</uni-td>
				<uni-td align="center">{{ item.CHARGE}}</uni-td>
				<uni-td align="center">{{ item.DESC_CN}}</uni-td>
				<uni-td align="center">{{ item.MATERIALSPECNAME }}</uni-td>
				<uni-td align="center">{{ item.SPECNAME }}</uni-td>
				<uni-td align="center">{{ item.PHASE }}</uni-td>
				<uni-td align="center">{{ item.MATERIALQUANTITY }}</uni-td>
				<uni-td align="center">{{ item.ERPFACTORY }}</uni-td>
				<uni-td align="center">{{ item.ERPLOCATION }}</uni-td>
				<uni-td align="center">{{ item.LOCATIONNAME }}</uni-td>
			</uni-tr>
		</uni-table>
		<uni-datetime-picker style="align-items: center;" type="date" :clear-icon="false" v-model="commitDate" @maskClick="maskClick" />
		<u-button @click="OtherStockOut" type="primary" :loading="loading">确定</u-button>


	</view>
</template>

<script>
	export default {
		data() {
			return {
				LocationName: '', //库位信息
				LOCATIONNAME: '',
				ERPFACTORY: '', //组织
				ERPLOCATION: '', //库位
				tabH: 800, //表格的宽度
				MATERIALSPECNAME: '',
				MATERIALPACKINGNAME: '', //条码
				CHARGE: '', //批次
				DESC_CN: '', //品名
				SPECNAME: '', //规格
				RECEIVEACTNO: '', //入库单号
				UNIT: '', //单位
				PHASE: '', //阶段
				QTY: '', //数量
				background: {
					backgroundImage: 'linear-gradient(45deg, rgb(28, 187, 180), rgb(141, 198, 63))'
				}, //返回按钮的样式
				colors: ['#007aff', '#4cd964', '#dd524d'],
				styleType: 'button',
				current: 0,
				BoxListInfo: [], //后端传回来的绑定表格的数据
				colorIndex: 0,
				activeColor: '#007aff',
				styleType: 'text',
				loading: false,
				scanData: [], //已扫描箱
				barCode: "", //条码
				DURABLENAMECode: "", //卷芯
				focusBarCode: false, //焦点是否被选中
				focusShipRequest: true, //默认焦点在单号
				siteName: "",
				userId: "",
			}
		},

		mounted() {
			this.tabH = this.$GetRemainingHeight(4, 0); //定义表格的高度
			let that = this
			uni.getStorage({
				key: "sitename",
				success(res) {
					that.siteName = res.data
				}
			})
			uni.getStorage({
				key: "userid",
				success(res) {
					that.userId = res.data
				}
			})
		},

		methods: {
			//获取焦点的公共方法
			getfocus(nextfocus) {
				this.initfocus()
				this[nextfocus]
				this.$nextTick(() => { //vue是数据全部修改后才进行的视图更新，哪nextTick函数就是为了拿到最新的数据，还不懂的可以去百度
					this[nextfocus] = true
				})
			},

			 ScanBarCode() {
				await this.$MyRequest('/NoInvoice/getQTCList', {
					MATERIALPACKINGNAME: this.MATERIALPACKINGNAME
				}).then(res => {
					if (res.data.success) {
						this.BoxListInfo.push(res.data.resultObj[0]);
					} else {
						this.$showMessage(res.data.message)
					}
					this.MATERIALPACKINGNAME = '';
					this.focusBarCode = true
					this.focusShipRequest = false
				}).catch(err => {
					this.MATERIALPACKINGNAME = '';
					this.$showMessage(err)
				});
			},

			/**
			 * 入库审核
			 */
			OtherStockOut() {
				this.loading = true;
				this.$MyRequest('/NoInvoice/QTCCommit', {
					boxList: this.BoxListInfo,
					user: this.userId
				}).then(res => {
					if (res.data.success) {
						this.loading = false;
						this.BoxListInfo = [];
						this.barCode = '';
						this.resetValue();
						this.$showMessage(res.data.message)
					} else {
						this.loading = false;
						this.$showMessage(res.data.message)
					}
					this.focusBarCode = true
					this.focusShipRequest = false
				}).catch(err => {
					this.loading = false;
					this.$showMessage(err)
				});
			},
			
			resetValue() {
				this.BoxListInfo = [];
			}
		}
	}
</script>

<style lang="scss">
	switch {
		color: #FFCC33;
	}

	/* 基础样式 */
	.picker {
		display: flex;
		flex-direction: column;
		align-items: flex-start;
		width: 100%;
		/* 根据需要调整宽度 */
	}

	.row {
		display: flex;
		justify-content: space-between;
		margin-bottom: 10px;
		/* 行与行之间的间距 */
	}

	.col {
		flex: 1;
		/* 使得每列占据相等的空间 */
		display: flex;
		flex-direction: column;
		align-items: flex-start;
	}

	label {
		// font-weight: bold;
		/* 标签加粗 */
		margin-bottom: 5px;
		/* 标签和值之间的间距 */
	}

	.value {
		/* 值的样式，可以根据需要调整 */
	}
</style>
