<template>
	<view>
	<u-navbar back-text="返回" title="出库拣配确认" :background="background"></u-navbar>
	<u-form ref="testForm">
		<u-form-item :border-bottom="false">
			<p>单号:</p>
			<u-input :focus="focusShipRequest" :border="true" v-model="shipRequestName" 
			placeholder="请输入单号" @confirm="serachMaterialList" /><!-- @blur="pointblur"-->
			<!-- <u-button @click="spilitbox" type="primary" size="default">拆分</u-button> -->
		</u-form-item>
		<u-form-item :border-bottom="false">
			<p>条码:</p>
			<u-input :border="true" v-model="barCode" placeholder="请扫描条码" :focus="focusBarCode"
				@confirm="confirmBarcode" />
		</u-form-item>
	</u-form>
	
<!-- 	<el-table :data="ReserveTableList" border :cell-style="tableRowStyleName"  height="450" style="width: 100%">
		<el-table-column prop="MATERIALPACKINGNAME" label="S/N"  width="200" >
		</el-table-column>
		<el-table-column prop="MATERIALSPECNAME" label="料号" width="200">
		</el-table-column>
		<el-table-column prop="ERPLOCATION" label="库位">
		</el-table-column>
		<el-table-column prop="LOCATIONNAME" label="货架">
		</el-table-column>
		<el-table-column prop="CHARGE" label="批次" >
		</el-table-column>
		<el-table-column prop="MATERIALQUANTITY" label="数量" >
		</el-table-column>
		<el-table-column prop="ISCHECK" label="校验标识" >
		</el-table-column>
	</el-table> -->
	
	<uni-table ref="ConfirmTable"   border stripe type="false">
			<uni-tr>
				<uni-th align="center">S/N</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 ReserveTableList" :key="index" :style="{ backgroundColor: item.ISCHECK != '' ? 'yellowgreen' : 'white' }"><!-- :style="getStyle(index)"--><!--:style="{ backgroundColor: item.color === 0 ? 'white' : 'blue' }" -->
				<uni-td align="center">{{ item.MATERIALPACKINGNAME}}</uni-td>
				<uni-td align="center">{{ item.MATERIALSPECNAME}}</uni-td>
				<uni-td align="center">{{ item.DESCRIPTION}}</uni-td>
				<uni-td align="center">{{ item.ERPLOCATION }}</uni-td>
				<uni-td align="center">{{ item.LOCATIONNAME }}</uni-td>
				<uni-td align="center">{{ item.CHARGE }}</uni-td>
				<uni-td align="center">{{ item.MATERIALQUANTITY }}</uni-td>
				<uni-td align="center">{{ item.ISCHECK }}</uni-td>
			</uni-tr>
		</uni-table>	
	<u-form>
		<u-form-item>
			<u-button @click="ConfirmButton" type="primary" size="mini" style = "background-color: green;">预约确认</u-button>
			<u-button @click="CancelConfirmButton" type="primary" size="mini" style = "background-color: red;">取消确认</u-button>
		</u-form-item>
	</u-form>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				ReserveTableList:[],
				shipRequestName : "",
				barCode : "",
				background: {
					backgroundImage: 'linear-gradient(45deg, rgb(28, 187, 180), rgb(141, 198, 63))'
				},
				focusBarCode: false, //焦点是否被选中
				focusShipRequest: true, //默认焦点在单号
			}

		},

		methods: {
			tableRowStyleName({
				row
			}) {
				if (row.ISCHECK == 'Y') {
					return 'background-color: yellowgreen;';
				}
			},
			
			serachMaterialList () {
				this.$MyRequest('/request/getStockOutReserveDetail', {
					shipRequestName: this.shipRequestName
				}).then(res => {
					if (res.data.success) {
						console.log(res.data)
						this.ReserveTableList = res.data.resultObj //接数据
					}
						this.focusBarCode = true
				}).catch(err => {
					this.$showMessage(err)
				})
			},
			confirmBarcode () {
				let list = this.ReserveTableList;
				for (var i = 0; i < list.length; ++ i) {
					var LbarCode = this.barCode;
					if (this.ReserveTableList[i]['MATERIALPACKINGNAME'] === LbarCode) {
						this.ReserveTableList[i]['ISCHECK'] = "Y"
						this.barCode = ""
					}
				}
			},
			ConfirmButton () {
				let list = this.ReserveTableList;
				if (list <= 0 ) {
					this.$showMessage("不存在需要提交的信息") 
					return;
				}
				for (var i = 0; i < list.length; ++ i) {
					var judge = this.ReserveTableList[i]['ISCHECK']
					if (judge != "Y") {
						this.$showMessage("存在未审核确认的信息") 
						return;
					}
				}
				this.$MyRequest('/request/ConfirmStockOutReserveDetail', {
					shipRequestName: this.shipRequestName
				}).then(res=>{
					     this.$showMessage(res.data.message) //执行出库后返回的消息
					    this.ReserveTableList = null; //清空条码，继续扫
					     this.focusShipRequest = true//获取焦点，好继续扫描
					}).catch(err=>{
						this.ReserveTableList = null;//请空条码
						this.focusShipRequest = true
						this.$showMessage(err)
						})
			},
			CancelConfirmButton () {
				this.$MyRequest('/request/CancelConfirmStockOutReserveDetail', {
					shipRequestName: this.shipRequestName
				}).then(res=>{
					     this.$showMessage(res.data.message) //执行出库后返回的消息
					     this.ReserveTableList = null; //清空条码，继续扫
					     this.focusShipRequest = true//获取焦点，好继续扫描
					}).catch(err=>{
						this.ReserveTableList = null;//请空条码
						this.focusShipRequest = true
						this.$showMessage(err)
						})
			}
			

		}
	}
</script>
<!-- <style>
	@import url("//unpkg.com/element-ui@2.15.13/lib/theme-chalk/index.css");
</style>
 -->