<template>
	<page-meta root-font-size="18px"></page-meta>
	<view class="">
		<view class="top_card">
			<view class="top_wrap" v-if="datacontent">
				<view class="top_card">
		
					<view class="device-detail">
						<view class="list-style nopad">
							<view class="ljh_box nopad">
								<view class="tit_ljh uni-flex">
									<text class="font_xl text_black text_bold">申请单号 : {{datacontent.number}}</text>
								</view>
		
							</view>
						</view>
					</view>
		
				</view>
			</view>
		</view>

		<scroll-view scroll-y class="scroll-detail" style="margin-top: 10rpx;padding-bottom:100px">
			<view class="detail-list " v-for="(item, index) in details" :key="index">
				<view class="detail-content">
					<view class="" style="">
						<view class="uni-flex uni-row u-col-center">
							<view class="" style="margin-top: 20rpx; margin-left: 10rpx; font-weight: bold;">
								({{index+1}}).
							</view>
							<comItemCode :itemData="item"></comItemCode>
						</view>

						<uni-table border stripe style="">
							<uni-tr>
								<uni-td align="center">单件码</uni-td>
								<uni-td>{{item.singleCodeRequest}}</uni-td>
							</uni-tr>
							<uni-tr>
								<uni-td align="center">单位</uni-td>
								<uni-td>{{item.uom}}</uni-td>
							</uni-tr>
							<uni-tr>
								<uni-td align="center">标包数</uni-td>
								<uni-td>{{item.stdPackQty}}</uni-td>
							</uni-tr>

							<uni-tr>
								<uni-td align="center">数量</uni-td>
								<uni-td>
									<view class="uni-flex uni-row">
										<view class="uni-flex uni-row space-between" style="width: 100%;">
											<view class="">
												{{item.qty}}
											</view>

											<view class="">
											</view>

										</view>
									</view>
								</uni-td>
							</uni-tr>
						</uni-table>
					</view>
				</view>
			</view>

		</scroll-view>

		<div class="new_bot_box" v-if="datacontent.requestStatus==5">
			<view class="new_btn_bot bot_pos uni-flex">
				<button class="new_save_btn " style="width: 100%;" @click="cancle()">取消</button>
			</view>
		</div>
		<comMessage ref="comMessage" @afterCloseCommitMessage='closeCommitMessage()'></comMessage>
	</view>
</template>

<script>
	import {
		getThirdLocationRequestDetail,
		thirdLocationRequestCancle
	} from '@/api/index.js';
	import {
		showConfirmMsg,
		goHome,
		navigateBack
	} from '@/common/basic.js';
	import comItemCode from '@/mycomponents/comItem/comItemCode.vue'
	import comMessage from '@/mycomponents/common/comMessage.vue'
	import comJobScanDetail from '@/mycomponents/comjob/comJobScanDetail.vue'

	export default {
		components: {
			comMessage,
			comJobScanDetail,
			comItemCode
		},
		data() {
			return {
				id: "",
				datacontent: {},
				details: [],
				jobStatus: "",
			}
		},
		onLoad(param) {
			this.id = param.id;
			this.getDetail();
		},
		//返回首页
		onNavigationBarButtonTap(e) {
			if (e.index === 0) {
				goHome();
			} else if (e.index === 1) {
				window.location.reload();
			}
		},
		mounted() {
			uni.setNavigationBarColor({
				frontColor: '#ffffff',
				backgroundColor: "#5A7CF3 !important"
			})
		},
		methods: {

			//加载零件信息
			getDetail() {
				uni.showLoading({
					title: "加载中",
					mask: false
				})
				let that = this;
				getThirdLocationRequestDetail(that.id)
					.then(item => {
						uni.hideLoading()
						console.log('item', item);
						that.datacontent = item;
						that.jobStatus = item.jobStatus
						that.details = item.details;
					})
					.catch(err => {
						uni.hideLoading()
						this.showMessage('未查找到详细信息')
					});
			},


			getScanCount() {
				this.scanCount = this.datacontent.details.filter(r => r.scaned).length;
			},

			closeScanPopup() {
				if (this.allCount == this.scanCount) {
					this.$refs.scanPopup.closeScanPopup();
				}
			},

			cancle() {
				showConfirmMsg("是否确认取消?", callback => {
					if (callback) {
						uni.showLoading({
							title: "加载中",
							mask: true
						})
						thirdLocationRequestCancle(this.datacontent.id).then(res => {
							uni.hideLoading()
							uni.showToast({
								title:"取消成功"
							})
							navigateBack(1)
						}).catch(error => {
							uni.hideLoading()
							this.showMessage("取消失败" + error)
						})
					}
				})

			},

			async finsh() {
				uni.showLoading({
					title: "提交中",
					mask: true
				})
				try {
					var jobList = await getkittingRequestJobByRequest(this.datacontent.number)
					var handleResult = await kittingRequestHandle(this.datacontent.id)

					var isHaveNewJobList = [];
					jobList.forEach(res => {
						isHaveNewJobList.push(res.kittingRequestNumber);
					})
					var isHaveNewJob = await iskittingHasNewJob(isHaveNewJobList)
					uni.hideLoading()
					this.showMessage(isHaveNewJob)
				} catch (error) {
					uni.hideLoading()
					this.showMessage(error)
				}
			},

			showCommitSuccessMessage() {
				this.$refs.comMessage.showCommitSuccess();
			},

			closeCommitMessage() {
				navigateBack(1); //点关闭直接返回列表
				uni.hideLoading();
			},


			showMessage(message) {
				this.$refs.comMessage.showMessage(message);
			},

		}
	}
</script>

<style scoped lang="scss">
</style>