<template>
	<view>
		<view class="title_box rx-bc">
			<view class="name">取样列表 ({{semiProductList.length || 0}})个 </view>
		</view>




		<view class="content_table2" v-if='semiProductList.length > 0'>
			<view class="head row rx-sc">
				<view class="item ww10">序号</view>
				<view class="item ww15">名称</view>
				<view class="item ww15">货位</view>
				<view class="item ww30">产品编码</view>
				<view class="item ww15">数量</view>
				<view class="item ww30">是否合格</view>
				<view class="item ww15">操作</view>

			</view>

			<view class="table">

				<view class="tr row rx-sc" v-for="(it, idx) in semiProductList" :key='idx'>
					<view class="item ww10">{{ idx + 1}} </view>
					<view class="item ww15">{{it.extInfo.vehicleName}}</view>
					<view class="item ww15">{{it.extInfo.areaCode}}</view>

					<view class="item ww30">
						{{it.code}}
					</view>
					<view class="item ww15 content_num">
						1
					</view>

					<view class="item ww30 rx-ac" style="color: #157A2C;">
						
						
						<text  v-if='Object.prototype.hasOwnProperty.call(it.extInfo, "notType") && it.extInfo.notType != 5 '>
							{{ it.extInfo.isQualified == 1 ? '合格':   it.extInfo.isQualified == 2 ? '不合格' : ''}}
						</text>
						<text
							v-if='Object.prototype.hasOwnProperty.call(it.extInfo, "notType") && it.extInfo.notType == 5 '>让步接收</text>
					</view>

					<view class="item ww15 " style="color: #157A2C;" @click="handleQuality(it, idx)">
						质检
					</view>
				</view>

			</view>

		</view>


		<SearchPopup mode="center" v-if='popupShow'>
			<template v-slot:list>
				<view class="search_list">
					<view class="serrch_code">产品编码：<text style="color: #157A2C;">{{qualityObj.code}}</text></view>

					<view class="content_table2">
						<view class="head row rx-sc">
							<view class="item ww20"> 质检名称</view>
							<view class="item ww20"> 工艺参数</view>
							<view class="item ww30" style="font-size: 20rpx;">质检结果参数</view>
							<view class="item ww30">质检结果</view>

						</view>


						<view class="table">
							<view class="tr row rx-sc" v-for="(quaItem, quaItemIdx) in qualityObj.extInfo.qualityParam"
								:key="quaItemIdx">

								<view class="item ww20 ">
									<view>{{quaItem.inspectionName }}</view>
								</view>

								<view class="item ww20 ">
									<view style="display: flex">
										<view v-if="quaItem.textType == 3" style="display: flex; align-items: center">
											{{ quaItem.minValue }} {{ quaItem.unit }}
											&nbsp;&nbsp;-&nbsp;&nbsp;
											{{ quaItem.maxValue }} {{ quaItem.unit }}
										</view>

										<view v-else>
											{{ quaItem.defaultValue }} {{ quaItem.unit }}
										</view>
									</view>
								</view>

								<view class="item ww30 content_num">
						
									<view v-if="isDetails">{{ quaItem.qualityResultValue }}</view>
									<input v-else class="uni-input" v-model="quaItem.qualityResultValue"></input>

								</view>

								<view class="item ww30 content_num">
					
									<view v-if='isDetails'>
										{{ quaItem.qualityResult ?  qualityList[quaItem.qualityResult - 1].name : ''  }}
									</view>

									<zxz-uni-data-select v-else :localdata="qualityList" v-model="quaItem.qualityResult"
										dataValue='value' format='{name}' dataKey="value" filterable
										:clear='false'></zxz-uni-data-select>
								</view>




							</view>

						</view>

					</view>


					<view class="material">
						<view class="content_table">
							<view class="item rx-sc">
								<view class="rx ww50">
									<view class="lable lable150 rx-cc ">质检结果 </view>
									<view class="content content_num ">
										<zxz-uni-data-select :localdata="isQualifiedList"
											v-model="qualityObj.extInfo.isQualified" dataValue='code' format='{name}'
											dataKey="code" filterable :disabled="isDetails" @change="handLoad($event,1)"

											:clear='false'></zxz-uni-data-select>

									</view>
								</view>

								<view class="rx ww50"
									v-if="qualityObj.extInfo.isQualified && qualityObj.extInfo.isQualified == 2">
									<view class="lable lable150 rx-cc ">类型</view>
									<view class="content  content_num">
										<zxz-uni-data-select :localdata="notTypeList"
											v-model="qualityObj.extInfo.notType" dataValue='code' format='{name}'
											dataKey="code" @change="handLoad()" filterable :disabled="isDetails"
											:clear='false'></zxz-uni-data-select>
									</view>
								</view>
							</view>


							<view class="item rx-sc"
								v-if="qualityObj.extInfo.isQualified && qualityObj.extInfo.isQualified != 1  && qualityObj.extInfo.notType != 5">
								<view class="rx ">
									<view class="lable lable150 rx-cc ">原因</view>
									<view class="content content_num">
										<view v-if='isDetails'>{{qualityObj.extInfo.notReason }}</view>
										<input class="uni-input" v-else v-model="qualityObj.extInfo.notReason"></input>
									</view>
								</view>
							</view>


						</view>
					</view>

				</view>
			</template>

			<template v-slot:operate>
				<view class="operate_box rx-bc">
					<u-button size="small" class="u-reset-button" @click="handleClose">
						取消
					</u-button>


					<u-button type="success" size="small" class="u-reset-button" @click="handleOk">
						确定
					</u-button>

				</view>
			</template>

		</SearchPopup>




	</view>
</template>

<script>
	import {
		getWarehouseList,
	} from '@/api/pda/workOrder.js'

	import SearchPopup from '../../components/searchPopup.vue'
	export default {

		components: {
			SearchPopup
		},
		props: {
			semiProductList: {
				type: Array,
				default: () => []
			},

			isDetails: {
				type: Boolean,
				default: false
			}


		},
		data() {
			return {

				popupShow: false,

				qualityIdx: null,
				qualityObj: {},


				qualityList: [{
						name: '合格',
						value: 1
					},
					{
						name: '不合格',
						value: 2
					},
					{
						name: '让步接受',
						value: 3
					},

				],


				isQualifiedList: [{
						code: '1',
						name: '合格'
					},
					{
						code: '2',
						name: '不合格'
					}
				],


				notTypeList: [{
						code: "1",
						name: '返工'
					},
					{
						code: "2",
						name: '返修'
					},
					{
						code: "3",
						name: '报废'
					},
					{
						code: '4',
						name: '降级使用'
					},
					{
						code: "5",
						name: '让步接收'
					}
				]


			}
		},

		created() {

		},

		methods: {


			handleQuality(it, idx) {
				this.qualityObj = it
				this.qualityIdx = idx
				this.popupShow = true
				console.log(this.qualityObj)
			},

			handleClose() {
				this.qualityIdx = null
				this.popupShow = false
			},

			handleOk() {
				this.semiProductList[this.qualityIdx].isQualified = this.qualityObj.extInfo.isQualified
				this.handleClose()
			},

			handLoad(event,i) {
				console.log(event,i);
				if(i==1){
					if(event.code === "1"){
						this.handleOk();
					}
				}

				this.$forceUpdate()
			},


		}



	}
</script>

<style lang="scss" scoped>
	.title_box {
		margin-top: 28rpx;

		.name {
			font-size: 28rpx;
			font-style: normal;
			font-weight: 400;
			color: $theme-color;
			padding-left: 20rpx;

			position: relative;

			&:before {
				position: absolute;
				content: '';
				left: 0rpx;
				top: 0rpx;
				bottom: 0rpx;
				width: 4rpx;
				height: 28rpx;
				background: $theme-color;
				margin: auto;
			}


		}

	}


	.btn_box {
		height: 60rpx;
		width: 140rpx;
		background: $theme-color;
		font-size: 26rpx;
		font-style: normal;
		font-weight: 400;
		font-size: 24rpx;
		color: #fff;
		border-radius: 4rpx;
		margin-left: 40rpx;


	}



	.material {
		margin-top: 16rpx;



		.content_table {
			width: 100%;
			border: 2rpx solid $border-color;

			.item {
				display: flex;
				border-bottom: 2rpx solid $border-color;


				.lable {
					width: 132rpx;
					text-align: center;
					background-color: #F7F9FA;
					font-size: 26rpx;
					border-right: 2rpx solid $border-color;
					flex-shrink: 0;
				}

				.lable150 {
					width: 156rpx !important;
					font-size: 24rpx;
				}

				.lable190 {
					width: 190rpx !important;
					font-size: 24rpx;
				}

				.ww80 {
					width: 80rpx;
				}

				.content {
					width: 500rpx;
					min-height: 64rpx;
					font-size: 28rpx;
					line-height: 28rpx;
					font-style: normal;
					font-weight: 400;
					padding: 18rpx 8rpx;
					box-sizing: border-box;
					word-wrap: break-word;
					flex-grow: 1 !important;


					.unit {
						padding: 0 4rpx;
						font-size: 24rpx;
						color: #404446;
					}

					.penalize {
						width: 160rpx;
						line-height: 60rpx;
						background: $theme-color;
						font-size: 24rpx;
						text-align: center;
						color: #fff;
					}

				}



				.content_H {
					min-height: 92rpx;
				}

				.pd4 {
					padding: 4rpx 8rpx;
				}



				&:last-child {
					border-bottom: none;
				}
			}

			.ww55 {
				width: 55%;
			}

			.ww50 {
				width: 50%;
			}

			.ww45 {
				width: 45%;
			}
		}
	}




	.content_table2 {
		width: 100%;
		margin-top: 18rpx;

		.row {
			width: 100%;


			.item {
				color: #404446;
				font-size: 28rpx;
				padding-left: 12rpx;

			}

			.color157 {
				color: $theme-color;
			}


			.ww30 {
				width: 30%;

			}

			.ww20 {
				width: 20%;

			}

			.ww15 {
				width: 15%;

			}

			.ww40 {
				width: 40%;

			}

			.ww10 {
				width: 10%;
			}
		}

		.head {
			height: 64rpx;
			background: #F7F9FA;
			border-top: 2rpx solid #E3E5E5;
			border-left: 2rpx solid #E3E5E5;

			.item {
				height: 64rpx;
				line-height: 64rpx;
				border-right: 2rpx solid #E3E5E5;
				box-sizing: border-box;
			}
		}



		.tr {
			border-top: 2rpx solid #E3E5E5;
			border-left: 2rpx solid #E3E5E5;


			.item {
				font-size: 24rpx;
				min-height: 76rpx;
				display: flex;
				align-items: center;
				border-right: 2rpx solid #E3E5E5;
				box-sizing: border-box;
				white-space: normal;
				word-break: break-all;

			}

			&:last-child {
				border-bottom: 2rpx solid #E3E5E5;

			}
		}
	}


	.content_num {
		display: flex;
		align-items: center;
		padding: 0 4rpx;

		/deep/ .uni-input-input {
			border: 2rpx solid #F0F8F2;
			background: #F0F8F2;
			color: $theme-color;
		}

	}



	.search_list {
		min-height: 100rpx;
		width: 96vw;
		padding: 0 8rpx;

		/deep/ .u-form-item__body {
			padding: 6rpx 0rpx !important;
		}

		.serrch_code {
			padding: 8rpx 4rpx;
			color: #000;
			font-size: 26rpx;
		}

	}
</style>