<template>
	<view>
		<view class="info-area" v-for="(item, index) in infoList" :key="index" v-show="infoList.length != 0">
			<view>
				<h4>类型名称</h4>
				<span>{{ item.typeName }}</span>
			</view>
			<view>
				<h4>规格型号</h4>
				<span>{{ item.typeCode }}</span>
			</view>
			<view>
				<h4>设备编码</h4>
				<span>{{ item.maCode }}</span>
			</view>
			<view>
				<h4>设备状态</h4>
				<span>{{ item.sdStatus }}</span>
			</view>
			<view style="flex-direction: column;">
				<!-- 				<h4 style="margin-bottom: 30rpx;">待修状态</h4> -->
				<uni-data-checkbox v-model="fixVal" :localdata="fixRange"></uni-data-checkbox>
			</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>
</template>

<script>
	export default {
		data() {
			return {
				typeId: '',
				num: '',
				parentId: '',
				infoList: '',
				fixVal: '',
				fixRange: [{
						text: '合格',
						value: '1'
					},
					{
						text: '待修',
						value: '2'
					},
					{
						text: '待报废',
						value: '3'
					}
				],
				initData: {}
			}
		},
		methods: {
			outStore() {
				let that = this
				console.log(that.infoList);
				if (!this.fixVal) {
					uni.showToast({
						icon: 'none',
						title: "请选择一种接收状态",
					})
					return
				}

				const arrList = [{
					"parentId": this.initData.parentId,
					"typeId": this.initData.typeId,
					"backNum": "1",
					"backStatus": this.fixVal,
					"manageType": this.initData.manageType,
					"createBy": this.initData.createBy,
					"maId": that.infoList[0].maId
				}]


				const params = {
					taskId: this.initData.taskId,
					arr: arrList
				}
				// 提交编码出库申请
				that.$api.backMaterialReceive.backMaterialSetCodeBack(params, null).then(res => {
					console.log(res);
					if (res.data.code == 200) {
						uni.showToast({
							icon: 'none',
							title: res.data.msg,
							success: () => {
								setTimeout(() => {
									uni.navigateBack()
								},200)
							}
						})
					} else {
						uni.showToast({
							icon: 'none',
							title: res.data.msg
						})
					}
				}).catch(err => {
					console.log(err);
				})
			},
			initFetchInfoByCode(params) {
				let that = this
				this.typeId = params.typeId
				this.num = params.num
				this.parentId = params.parentId
				// 根据扫出的编码查询设备
				that.$api.fetchMaterialOutStore.fetchInfoByCode({
					maCode: params.code
				}, null).then(res => {
					console.log("", res);
					if (res.data.rows.length == 0) {

					} else {
						// that.infoList = res.data.rows
					}
				}).catch(err => {
					console.log(err);
				})
			},
			iniBackMaterialReceive(params) {
				let that = this
				this.typeId = params.typeId
				this.num = params.num
				this.parentId = params.parentId
				// 根据扫出的编码查询设备
				that.$api.backMaterialReceive.backMaterialQrcodeQuery({
					qrCode: params.code
				}, null).then(res => {
					console.log("backMaterialQrcodeQuery", res.data.data);
					if (res.data.data.length == 0) {
						// qrcodeQuery  页面数据
						uni.showToast({
							icon: 'none',
							title: '未查询到设备数据！'
						})
					} else {
						that.infoList = res.data.data
					}
				}).catch(err => {
					console.log(err);
				})
			},

		},
		onLoad(params) {
			// 测试代码 sjf-note 记得删除
			// const testParams = {
			// 	"code": "20231224-0067",
			// 	"typeId": "4",
			// 	"num": "4",
			// 	"parentId": "32",
			// 	"manageType": "0",
			// 	"createBy": "1",
			// 	scanType: 'back',
			// 	taskId: "357"
			// }
			// params = testParams
			this.initData = params
			console.log("paramsinitFetchInfoByCode",params)
			// this.initFetchInfoByCode(params)
			this.iniBackMaterialReceive(params)
		}
	}
</script>

<style lang="scss">
	.info-area {
		width: 90%;
		margin: 40rpx auto;
		display: flex;
		flex-direction: column;

		view {
			margin-bottom: 25rpx;
			display: flex;
			align-items: center;

			h4 {
				width: 35%;
				font-weight: normal;
				font-size: 14px;
				color: #989898;
			}

			span {
				font-size: 14px;
			}
		}
	}

	.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>