<template>
	<view>
		<view class="title_box rx-bc">
			<view class="name">取样</view>


		</view>


		<view class="material ">

			<view class="content_table">
				<view class="item">
					<view class="lable rx-cc">工序名称</view>
					<view class="content">
						{{item.diagramLast.taskTypeName}}
					</view>
				</view>





				<view class="item rx-sc">
					<view class="rx ww55 ">
						<view class="lable  rx-cc">数量</view>
						<view class="content rx-sc">
							<view>{{item.formedNum}}</view>
							<view class="unit">{{item.unit}}</view>
						</view>
					</view>

					<view class="rx ww45">
						<view class="lable rx-cc ww80">重量</view>
						<view class="content content_num">
							<view>{{item.formedWeight}}</view>
							<view class="unit">{{item.weightUnit}}</view>

						</view>
					</view>

				</view>

				<view class="item">
					<view class="lable rx-cc">取样数量</view>
					<view class="content content_num  rx-sc">
						<input class="uni-input" v-model="item.sampleNum" type='digit'
							@blur='item.sampleNum > item.formedNum ?  item.sampleNum = item.formedNum : item.sampleNum'></input>
						<view class="unit">{{item.unit}}</view>
						<view class="penalize" @click="penalize">处置
						
						</view>

					</view>
				</view>

		






			</view>

			<view class="content_table2" v-if="item.sampleList.length > 0">
				<view class="head row rx-sc">
					<view class="item ww15">类型</view>
					<view class="item ww20">数量</view>
					<view class="item ww55">处置</view>
					<view class="item ww15">操作</view>
				</view>

				<view class="table">

					<view class="tr row rx-sc" v-for="(item, index) in item.sampleList" :key='index'>


						<view class="item ww15 content_num">
							{{ item.selectType == 1 ? '回用' : item.selectType == 2 ? '入库' : ''  }}
						</view>

						<view class="item ww20 content_num">
							<input class="uni-input" v-model="item.num"></input>
						</view>

						<view class="item ww55  content_num">
							<zxz-uni-data-select :localdata="warehouseList" v-if='item.selectType != 1'
								v-model="item.warehouseId" dataValue='id' dataKey="name" filterable
								format='{name}'></zxz-uni-data-select>
						</view>
						<view class="item ww15">
							<view class="left rx-ss" @click="getDelete(index)">
								<uni-icons custom-prefix="iconfont" type="icon-shanchu" size="20"
									color="#fa3534"></uni-icons>
							</view>
						</view>

					</view>






				</view>


			</view>


		</view>

		<u-popup :show="show" mode='center' v-if='show' :closeOnClickOverlay='false'>
			<view class="popup_box">
				<uni-data-select v-model="selectType" :localdata="rangeList"></uni-data-select>

				<view class="operate_box rx-sc">
					<u-button size="small" class="u-reset-button" @click="cancel">取消</u-button>
					<u-button size="small" class="u-reset-button" type="success" @click="save">确定</u-button>
				</view>
			</view>


		</u-popup>


	</view>
</template>

<script>
	import {

		getWarehouseList,

	} from '@/api/pda/workOrder.js'

	export default {
		props: {
			item: {
				type: Object,
				default: () => {}
			},


		},
		data() {
			return {
				warehouseList: [],

				show: false,
				selectType: null,
				rangeList: [{
						value: 1,
						text: "回用"
					},
					{
						value: 2,
						text: "入库"
					}
				]
			}
		},
		created() {
			this.getWarehouseListFn()
		},
		methods: {
			getWarehouseListFn() {
				getWarehouseList().then(res => {
					this.warehouseList = res
				})
			},
			cancel() {
				this.selectType = null
				this.show = false

			},

			penalize() {

				if (Number(this.item.sampleNum <= 0) ) {
					uni.showToast({
						icon: 'none',
						title: '取样数量要大于0'
					})
					return false
				}

				this.show = true


			},

			save() {
				this.show = false
				if (this.selectType) {
					this.item.sampleList.push({
						selectType: this.selectType,
						num: null,
						warehouseId: null
					})
				} else {
					uni.showToast({
						icon: 'none',
						title: '请先选项处置方法'
					})
				}

			},

			getDelete(idx) {
				this.item.sampleList.splice(idx, 1)
			},

		}
	}
</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 {
			padding: 0 18rpx;
			height: 60rpx;
			background: $theme-color;
			font-size: 26rpx;
			font-style: normal;
			font-weight: 400;
			font-size: 24rpx;
			color: #fff;
			border-radius: 4rpx;

			.scan {
				width: 34rpx;
				height: 34rpx;
				margin-right: 12rpx;

			}

		}

	}


	.material {
		margin-top: 10rpx;



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

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


				.lable {
					width: 156rpx;
					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;
				}

				.ww80 {
					width: 80rpx;
				}

				.content {
					width: 518rpx;
					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: 200rpx;
						line-height: 60rpx;
						background: $theme-color;
						font-size: 24rpx;
						text-align: center;
						color: #fff;
					}

				}


				.pd4 {
					padding: 4rpx 8rpx;
				}



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

			.ww55 {
				width: 55%;
			}

			.ww45 {
				width: 45%;
			}
		}


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


			.row {
				width: 100%;


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

				}

				.left {
					width: 40rpx;
				}

				.ww30 {
					width: 30%;
				}

				.ww20 {
					width: 20%;
				}

				.ww35 {
					width: 35%;
				}

				.ww55 {
					width: 55%;
				}

				.ww15 {
					width: 15%;
				}
			}

			.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: 78rpx;
					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;
		box-sizing: border-box;

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


	}

	.popup_box {
		width: 78vw;
		padding: 32rpx;


	}



	.operate_box {
		margin-top: 32rpx;
		padding: 10rpx 100rpx;

		/deep/ .u-button {
			width: 160rpx;
		}
	}
</style>