<template>
	<view>
		<view class="uni-form-item uni-column">
			<view class="uni-flex uni-row">
				<view class="title" style="width: 190rpx;">交验单号:</view>
				<input class="uni-input" style="font-size: 40rpx;font-weight: bold;color: black;" disabled="true" v-model="deliverNo"/>
			</view>
			<view class="uni-flex uni-row" style="margin-top: 3px;margin-bottom: 3px;">
				<view class="title" style="width: 190rpx;">规格型号\图号:</view>
				<input class="uni-input" style="margin-right: 5px;" :focus="foucusIndex === 0" v-model="materialSpecCode" placeholder="请输入规格型号\图号" @confirm="confirmFun"/>
			</view>
			<!-- 2024 孙亚龙新增的注释。 由于不确定是哪个业务要加状态过滤查询条件，所以暂时注释掉代码 -->
			<view class="uni-flex uni-row" style="margin-top: 5px;margin-bottom: 8px;">
				<view class="title">质检状态:</view>
				<view style="padding-top: 10rpx;padding-bottom: 10rpx;">
					<uni-data-checkbox v-model="CheckStatus" :localdata="CheckStatusData"></uni-data-checkbox>
				</view>
			</view>
			<view class="uni-flex uni-row">
				<button type="primary" style="-webkit-flex: 1;flex: 1;margin-left: 5px;" @click="queryFun">查    询</button>
				<button type="primary" style="-webkit-flex: 1;flex: 1;margin-left: 5px;margin-right: 5px;" @click="resetCondition">重    置</button>
			</view>
		</view>
		<uni-section title="待质检的交验单明细：" type="line" style="margin-bottom: 3px;padding: 3px;">
			<view class="my-tips-view" v-if="isShowTips">没有查询到交验单明细数据......</view>
			<uni-pagination :total="total" :current="current" :pageSize="pageSize" @change="pageChange" title="标题文字" v-if="!isShowTips" style="margin: 4px;"/>
			<view v-if="!isShowTips" style="text-align: center;">
				<text class="example-info">数据总量：{{ total }}条，每页数据：{{ pageSize }}</text>
			</view>
			<view v-for="(newsitem,key) in sapDeliverDtlList" :key="key">
				<view class="myDeliverDetail"  @click="myDeliverDetailClick(newsitem)">
					<view style="flex-direction: row;flex-direction: row;height: 25px;display: flex;padding: 2px;border-radius: 5px 5px;">
						<text style="align-self: center;">物料编号：</text>
						<text style="align-self: center;font-size: 30rpx;font-weight: bold;">{{newsitem.materialCode}}</text>
						<text :class="newsitem.keyFlag ? 'keyFlagRed' : 'keyFlagGray'" style="align-self: center;margin-left: 20px;">{{newsitem.keyFlag ? '★' : '■'}}</text>
					</view>
					<view class="line-h"></view>
					<view style="flex-direction: row;flex-direction: row;display: flex;-webkit-justify-content: space-between;justify-content: space-between;">
						<view>
							<view style="flex-direction: row;flex-direction: row;display: flex;padding: 2px;">
								<text style="align-self: center;color: #555;font-size: 25rpx;">物料名称：</text>
								<text style="align-self: center;font-size: 25rpx;word-wrap: break-word;width: 200px;">{{newsitem.materialName}}</text>
							</view>
							<view style="flex-direction: row;flex-direction: row;display: flex;padding: 2px;">
								<text style="align-self: center;color: #555;font-size: 25rpx;">规格型号/图号：</text>
								<text style="align-self: center;font-size: 30rpx;font-weight: bold;word-wrap: break-word;width: 200px;">{{newsitem.materialSpec}}</text>
							</view>
							<view style="flex-direction: row;flex-direction: row;display: flex;padding: 2px;">
								<text style="align-self: center;color: #555;font-size: 25rpx;">交验单数量：</text>
								<text style="align-self: center;font-size: 35rpx;font-weight: bold;color: blue;">{{newsitem.sumQty}}</text>
							</view>
							<view style="flex-direction: row;flex-direction: row;display: flex;padding: 2px;">
								<text style="align-self: center;color: #555;font-size: 25rpx;">已质检数量：</text>
								<text style="align-self: center;font-size: 35rpx;font-weight: bold;color: blue;">{{newsitem.sumCheckQty}}</text>
							</view>
						</view>
						<view v-if="newsitem.sumCheckQty < newsitem.sumQty" style="border-radius: 35px;width: 35px; background-color: lime;height: 35px;align-self: center;margin-right: 5px;"></view>
						<view v-else style="border-radius: 35px;width: 35px; background-color: lightgray;height: 35px;align-self: center;margin-right: 5px;"></view>
					</view>
				</view>
			</view>
		</uni-section>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				deliverNo: '',
				foucusIndex: 0,
				materialSpecCode: '',
				isShowTips: true,
				sapDeliverDtlList:[],
				current: 1,
				total: 0,
				pageSize: 10,
				//2024 孙亚龙新增的注释。 由于不确定是哪个业务要加状态过滤查询条件，所以暂时注释掉代码
				CheckStatus: -1,
				CheckStatusData: [{
						value: -1,
						text: '全部'
					},{
						value: 0,
						text: '已质检'
					},{
						value: 1,
						text: '未质检'
					}
				]
			}
		},
        onLoad(option) {
			this.deliverNo = option.deliverNo;
			this.queryFun()
			uni.$on('CallSapDeliverDtlQueryFunc', this.CallSapDeliverDtlQueryFunc)
        },
		onUnload() {
			uni.$off('CallSapDeliverDtlQueryFunc', this.CallSapDeliverDtlQueryFunc)
		},
		methods: {
			async queryFun() {
				uni.showLoading({
					title: "正在查询...",
					mask: true,
				})
				this.sapDeliverDtlList = []
				let parm = {
					url : '/business/SapDeliverRecord/GetSapDeliverRecordSumList',
					data: {
						DeliverNo: this.deliverNo,
						MaterialSpec: this.materialSpecCode,
						CheckStatus: this.CheckStatus, // 质检结果快速出库默认(CheckStatus = -1)查询全部质检状态的数据。
						PageNum: this.current,
						PageSize: this.pageSize
					},
					method: 'GET',
					isHaveToken : true
				}
				let retData = await getApp().RequestData(parm)
				if(retData.isSuccess) {
					if(retData.data.code == 200) {
						let len = retData.data.data.result.length
						this.total = retData.data.data.totalNum
						if(len > 0) {
							this.isShowTips = false
						}
						else {
							this.isShowTips = true
						}
						this.sapDeliverDtlList = retData.data.data.result
					}
					else {
						this.isShowTips = true
					}
				}
				else {
					this.isShowTips = true
				}
				uni.hideLoading()
			},
			resetCondition() {
				this.materialSpecCode = ""
				this.sapDeliverDtlList = []
				this.CheckStatus = -1
				this.isShowTips = true
				this.foucusIndex = 1
				setTimeout(() => {
					this.foucusIndex = 0;
				}, 150)
			},
			confirmFun() {
				this.queryFun()
			},
			myDeliverDetailClick(model) {
				model.deliverNo = this.deliverNo;
				if(model.sumCheckQty >= model.sumQty) {
					uni.showToast({
						title: '已全部质检',
						icon: 'error',
						mask: true,
						duration: 1500
					})
				} else {
					uni.navigateTo({
						url: '/pages/Inspect/FastOutStoreInspectOperate',
						success() {
							uni.$emit('sendDeliverDtlData',model)
						}
					});
				}
			},
			pageChange(e) {
				this.current = e.current
				this.queryFun()
			},
			CallSapDeliverDtlQueryFunc() {
				this.materialSpecCode = ""
				this.queryFun()
				this.foucusIndex = 1
				setTimeout(() => {
					this.foucusIndex = 0;
				}, 150)
			}
		}
	}
</script>

<style lang="scss">
	.my-tips-view {
		/* margin-top: 50px; */
		text-align: center;
		color: #999999;
		font-size: 20px;
		font-weight: normal;
	}
	.myDeliverDetail {
		border: 1px solid #cccccc;
		border-radius: 5px;
		margin-top: 1px;
	}
	.myDeliverDetail:active {
		background-color: aliceblue;
	}
	.line-h {
	    height: 1rpx;
	    background-color: #cccccc;
	}
	.keyFlagRed {
		color: red;
	}
	.keyFlagGray {
		color: lightgray;
	}
</style>
