<template>
	<view>
		<view class="form-area">
			<view class="upper-ipt">
				<!-- <uni-easyinput style="margin-bottom: 15rpx;" v-model="carCode" placeholder="请输入车牌号"></uni-easyinput> -->
				<uni-easyinput suffixIcon="search" v-model="codeVal" placeholder="请输入编码" @iconClick="searchCode"></uni-easyinput>
			</view>
			<view 
				class="info-area"
				v-for="(item, index) in infoList"
				:key="index"
				v-show="infoList.length != 0"
			>
				<view>
					<h4>机具分类</h4>
					<span>{{ item.itemType }}</span>
				</view>
				<view>
					<h4>设备名称</h4>
					<span>{{ item.deviceType }}</span>
				</view>
				<view>
					<h4>设备规格</h4>
					<span>{{ item.specificationType }}</span>
				</view>
				<view>
					<h4>设备状态</h4>
					<span>{{ item.maStatusName }}</span>
				</view>
				<view>
					<h4>机具编码</h4>
					<span>{{ item.maCode }}</span>
				</view>
				<view>
					<h4>出库数量</h4>
					<span>1</span>
				</view>
			</view>
			<view 
				class="sub-btn"
				v-show="infoList.length != 0"
				@click="outStore"
			>
				出库
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				carCode: '',
				codeVal: '',
				typeId: '',
				num: '',
				parentId: '',
				infoList: '',
				manageType: '',
				taskId: '',
				subList: {}
			}
		},
		methods: {
			searchCode () {
				let that = this
				that.infoList = []
				console.log(that.codeVal);
				// 根据maId获取设备详情
				that.$api.fetchMaterialOutStore.fetchInfoByCode({
					maCode: that.codeVal
				}).then(res => {
					console.log(res);
					if (res.data.rows.length == 0) {
						uni.showToast({
							icon: 'none',
							title: '请输入正确格式的编码！'
						})
					} else {
						that.infoList = res.data.rows
					}
				}).catch(err => {
					console.log(err);
				})
			},
			outStore () {
				let that = this
				console.log(that.infoList, this.typeId);
				if (this.infoList[0].typeId != this.typeId) {
					uni.showToast({
						icon: 'none',
						title: '机具类型不匹配！'
					})
				} else {
					that.subList = {
						parentId: that.parentId,
						typeId: that.typeId,
						manageType: that.manageType,
						taskId: that.taskId,
						maId: that.infoList[0].maId,
						outNum: 1,
						// carCode: that.carCode,
						companyId: uni.getStorageSync('userInfo').sysUser.companyId
					}
					console.log(that.subList);
				// 提交编码出库申请
					that.$api.fetchMaterialOutStore.subOutStore(that.subList).then(res => {
						console.log(res);
						if (res.data.code == 200) {
							uni.showToast({
								icon: 'none',
								title: res.data.msg,
								success: () => {
									uni.navigateBack()
								}
							})
						} else {
							uni.showToast({
								icon: 'none',
								title: res.data.msg
							})
						}
					}).catch(err => {
						console.log(err);
					})
				}
			}
		},
		onLoad(params) {
			console.log(params);
			this.typeId = params.typeId
			this.num = params.num
			this.parentId = params.parentId
			this.manageType = params.manageType
			this.taskId = params.taskId
			// this.codeVal = params.code
		}
	}
</script>

<style lang="scss">
	.form-area{
		width: 90%;
		margin: 40rpx auto;
		.upper-ipt{
			width: 100%;
			display: flex;
			flex-direction: column;
			align-items: center;
			margin-bottom: 30rpx;
		}
		.info-area{
			width: 100%;
			display: flex;
			flex-direction: column;
			border-bottom: 1px solid #d7d7d7;
			view{
				margin-bottom: 25rpx;
				display: flex;
				align-items: center;
				h4{
					width: 35%;
					font-weight: normal;
					font-size: 14px;
					color: #989898;
				}
				span{
					font-size: 14px;
				}
			}
		}
		.info-area:last-child{
				border-bottom: none;
			}
		.sub-btn{
			width: 80%;
			margin: 30rpx auto;
			box-sizing: border-box;
			padding: 15rpx 0;
			background-color: #0189FC;
			color: #fff;
			display: flex;
			justify-content: center;
			align-items: center;
			border-radius: 40rpx;
		}
	}
</style>
