<template>
	<view class="materRe">
		<uni-forms>
			<uni-collapse>
				<uni-forms-item :labelWidth="90" label="领料单号">
					<uni-easyinput :value="options.drawTaskCode" disabled />
				</uni-forms-item>
				<button type="primary" @click="allocateStockBtn">一键分配库存</button>

				<uni-collapse-item :open="true" title="明细信息">
					<uni-card v-for="(item,index) in getTaskData.wmsDrawTaskDetailList" :key="index">
						<uni-row>
							<uni-col :span="12" style="white-space: nowrap;overflow: hidden;text-overflow: ellipsis; ">
								物料编码:{{item.materialCode}}
								</uni-forms-item>
							</uni-col>
							<uni-col :span="12" style="white-space: nowrap;overflow: hidden;text-overflow: ellipsis; ">

								数量:{{item.number}}

							</uni-col>
						</uni-row>
						<uni-row>
							<uni-col :span="12" style="white-space: nowrap;overflow: hidden;text-overflow: ellipsis; ">

								物料名称:{{item.materialName}}

							</uni-col>
							<uni-col :span="12" style="white-space: nowrap;overflow: hidden;text-overflow: ellipsis; ">

								单位:{{item.unitId}}

							</uni-col>
						</uni-row>
						<uni-row>
							<uni-col :span="12" style="white-space: nowrap;overflow: hidden;text-overflow: ellipsis; ">

								物料规格:{{item.specification}}

							</uni-col>
							<uni-col :span="12" style="white-space: nowrap;overflow: hidden;text-overflow: ellipsis; ">

								可用数量:{{item.availableNumber}}

							</uni-col>
						</uni-row>
						<uni-row>
							<uni-col :span="24" style="white-space: nowrap;overflow: hidden;text-overflow: ellipsis; ">

								物料批号:{{item.materialBatchNo}}

							</uni-col>
						</uni-row>
						<uni-row>
							<uni-col :span="24">

								<button type="primary"
									:disabled="item.pickedNumber > 0 ? true : false || item.outedNumber > 0 ? true : false"
									@click="InventoryBtn(item,index)">选择物料库存</button>

							</uni-col>
						</uni-row>
					</uni-card>
				</uni-collapse-item>
			</uni-collapse>
			<button @click="goBack" type="primary" style="position: fixed;bottom: 0;width: 100vw;">确定</button>
		</uni-forms>

	</view>
</template>

<script>
	import {
		getTask
	} from "@/api/wms/pdcMaterial"
	import {
		allocateStock, //分配库存
	} from "@/api/wms/materRequisitiontask";


	export default {
		onLoad(options) {
			this.options = JSON.parse(options.data)
			console.log(this.options, "optj");
			getTask(JSON.parse(options.data).id).then(res => {
				console.log(res, "res");
				this.getTaskData = res.data;
				this.getTaskData.wmsDrawTaskDetailList.forEach(item => {
					item.secondNumber =
						item.secondNumber == null ? item.number : item.secondNumber;
				});

			})
	

		},
		// onShow() {
		// 	console.log(this.getTaskData.wmsDrawTaskDetailList, "this.getTaskData.wmsDrawTaskDetailList");
		// 	if (this.getTaskData.wmsDrawTaskDetailList) {
		// 		this.getTaskData.wmsDrawTaskDetailList.forEach(item => {
		// 			convertBySecondUnitOrNum({
		// 				materialCode: item.materialCode,
		// 				unitId: item.unitId,
		// 				secondUnitId: item.secondUnitId,
		// 				secondNumber: item.secondNumber,
		// 			}).then(res => {
		// 				console.log("单位1", res);
		// 			})
		// 		})
		// 	}


		// },
		mounted() {

		},
		data() {
			return {
				options: {},
				getTaskData: {},
			}
		},
		methods: {

			InventoryBtn(item, index) {
				console.log(item, index);
				this.$tab.navigateTo("/pages/wms/pdcMaterial/materRequisitiontask/InventoryDetails?data=" +
					encodeURIComponent(JSON.stringify(item)) + '&wmsDrawTaskDetailList=' + encodeURIComponent(JSON
						.stringify(this.getTaskData.wmsDrawTaskDetailList)) + '&index=' + encodeURIComponent(JSON
						.stringify(index))+"&getListArr="+encodeURIComponent(JSON
						.stringify(this.options)));
			},
			allocateStockBtn() {
				console.log(this.options, "this");
				allocateStock([this.options.id]).then(res => {
					console.log(res)
				})
			},
			goBack() {
				this.$tab.navigateBack({
					delta: 1 // 返回的页面数量，1 表示返回上一级页面
				});
			}
		},

	}
</script>

<style lang="scss">
	.materRe {
		background-color: #FFFFFF;
	}
</style>