<template>
	<view>
		<u-navbar back-text="返回" title="立库空托盘出库" :background="background"></u-navbar>
		<uni-segmented-control :current="current" :values="items" :style-type="styleType" :active-color="activeColor" />
		<!-- <view v-if="current === 0">
			<uni-z-table :style="{'height': tabH+'px'}" :tableData="matData" :columns="matColumns" :showBottomSum="true"
				:rowNumbers="true" :pagination="true" @click="handleRowClick">
				<template #custom-cell="{row, column}">
					<view  class="flex-item" v-if="column.field === 'MATERIALSPECNAME'">
						<checkbox :value="row.isSelected" ></checkbox>
						{{ row.MATERIALSPECNAME }}
					</view>
					<view v-else>
						{{ row[column.field] }}
					</view>
			 </template>
			</uni-z-table>
		</view> -->
		<view>
			<zb-table style="height: 700upx;" ref="zbTable" :columns="matColumns" :data="matData"
				:cell-style="cellStyleFn" highlight=true @rowClick="HandleChange"></zb-table>
		</view>
		<u-button @click=" DeclinePallet" type="primary">确定</u-button>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				totalAll: 0,
				ChangeRow: [],
				tabH: 800, //表格的宽度
				ischecked: true, //默认出库
				background: {
					backgroundImage: 'linear-gradient(45deg, rgb(28, 187, 180), rgb(141, 198, 63))'
				}, //返回按钮的样式
				//style:{color: '#2979FF'},
				colors: ['#007aff', '#4cd964', '#dd524d'],
				styleType: 'button',
				items: ['入库清单'], //分栏器的选项卡 应发，实发，待发，物料描述，行号
				current: 0,
				matData: [], //后端传回来的绑定表格的数据
				matData2: [],
				colorIndex: 0,
				activeColor: '#007aff',
				loading: false,
				matColumns: [{
						label: '托盘号',
						name: "DURABLENAME",
					},
					{
						label: '数量',
						name: "ASSIGNEDPACKINGQUANTITY",
					},
					{
						label: '是否选中',
						name: "CHECKBOX",
					}
				],
			}
		},

		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
				}
			})
		},
		created() {
			// 在这里调用你的方法，当组件被创建时执行  
			this.FreeQuanty();
		},
		methods: {
			rowclick(row) {
				console.log(row);
			},
			// 设置是否选中的颜色状态
			cellStyleFn({
				row,
				column,
				rowIndex,
				columnIndex
			}) {
				return {
					backgroundColor: row.CHECKBOX != 'False' ? 'yellowgreen' : 'white'
				}
			},
			handleRowClick(e) {
				console.log("1")
			},
			FreeQuanty() {
				this.$MyRequest('/api/ApiQuery', {
					queryId: "GetDURABLENAMEandQuantity",
					version: "00002",
					params: {}
				}).then(res => {
					if (res.data.code == "0") {
						for (let i = 0; i < res.data.data.length; i++) {
							this.matData = res.data.data
						}
					}
				}).catch(err => {
					this.$showMessage(err)
				})
			},
			DeclinePallet() {
				let colum1 = [];
				
				for (let i = 0; i < this.matData.length; i++) {
					if (this.matData[i].CHECKBOX == 'True') {
						colum1.push(this.matData[i].DURABLENAME);
					}
				}
				console.log(colum1);
				let palletString = colum1.join(";");
				this.$MyRequest('/bpel/event', {
					header: {
						MESSAGENAME: 'TransportCommandRequest',
						LANGUAGE: 'Chinese',
						SITENAME: 'SDK',
						Flag: 'TP' //托盘标志
					},
					body: {
						TRAYNAME: palletString, //托盘号
						Quantity: '',
						SITENAME: 'SDK',
						TRANSPORTCOMMANDTYPE: 'OUT',
						FLAG: 'TP', //托盘标志
						pallet: ''
					}
				}).then(res => {
					if (res.data.code == "0") {
						this.$showMessage("指令下发成功")
					}
				}).catch(err => {
					this.$showMessage(err)
				})

			},
			//点击拆分按钮
			spilitbox() {
				uni.navigateTo({
					url: './SplitBoxPage' //跳转到拆分页面
				})
			},
			//设置开关的选中状态
			changeischecked() {
				this.ischecked = !this.ischecked
				//console.log("选中状态", this.ischecked)
			},
			//选中table的当前选中行时，对数据进行一系列的操作
			selectTableRow(e) {
				var matId = e.row["MATERIALSPECNAME"];
				this.getmaterialkw(matId);
				this.shipRequestDetailName = e.row["SHIPREQUESTDETAILNAME"]
			},
			//获取选中当前行的库位信息     
			getmaterialkw(material) {
				this.$MyRequest('/request/getlocation', {
					materialSpecName: material
				}).then(res => {
					if (res.data.success)
						this.materialKwData = res.data.resultObj //接收数据
					else this.$showMessage(res.data.message)
				}).catch(err => {
					this.$showMessage(err)
				})
			},
			HandleChange(e) {

				for (let i = 0; i < this.matData.length; i++) {
					if (this.matData[i].DURABLENAME === e.DURABLENAME) {
						this.matData[i].CHECKBOX = this.matData[i].CHECKBOX == 'False' ? 'True' : 'False'
						break; // 退出循环  
					}
				}
			}
		}
	}
</script>

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