<template>
	<view class="page-wraper">
		<view class="page-header flex"
			style="font-size: 32rpx; padding-left: 10rpx; padding-top: 10rpx; flex-direction: column;">
			<view class="flex u-col-center space-between">
				<view class="">
					<view class="" style="margin: 5rpx;">
						设备编号 : {{deviceCode}}
					</view>
					<view class="" style="margin: 5rpx;" v-if="deviceName!=''">
						设备名称 : {{deviceName}}
					</view>
					
					<!-- <text v-if="deviceName!=''">({{deviceName}})</text> -->
				</view>
				<view class="">
					<button type="primary" size="mini" @click="openScanPopup">扫描</button>
				</view>
				
			</view>
			<view class="" style="margin: 5rpx;" v-if="deviceName!=''">
				点检日期 : {{dateTime}}
			</view>
			<view class="" style="margin: 5rpx;" v-if="deviceName!=''">
				点检人 : {{worker}}
			</view>
			<view class="" style="width: 100%;background-color: gray;height: 2rpx; margin-top: 10rpx;" />

		</view>
		<view class="page-main">
			<scroll-view scroll-y="true" class="page-main-scroll">
				<view style="padding-bottom: 80rpx;">
					<customerFrom ref="customerFrom" :formData="dataList"> </customerFrom>
				</view>
			</scroll-view>
		</view>
		<view class="page-footer" v-if="dataList.length>0">
			<view class="uni-flex u-col-center space-between padding_10"
				style="background-color:ghostwhite; width: 100%; ">
				<view class="">
					<button class="btn_single_reset" hover-class="btn_single_after" @click="reset">重置</button>
				</view>
				<view class=" uni-flex uni-row">
					<button class="btn_single_commit" hover-class="btn_commit_after" @click="submit">提交</button>
				</view>
			</view>
		</view>
		<winScanNormal ref="scanPopup" title="设备编号" @getResult='getScanResult'></winScanNormal>
		<showModal ref="comMessage"></showModal>
	</view>


</template>

<script>
	import showModal from '../../mycomponents/common/showModal.vue'
	import customerFrom from "@/mycomponents/form/customerFrom.vue"
	import winScanNormal from "@/mycomponents/scan/winScanNormal.vue"
	import {
		getCurrDateTime,
		deepCopyData
	} from "@/common/basic.js"
	import {
		getPlaneNumberList,
		getMaterialLists,
		foamCheckSubmit,
		getDeviceInfo
	} from '@/api/request2.js';
	export default {
		components: {
			customerFrom,
			winScanNormal,
			showModal
		},
		data() {
			return {
				dateTime: "",
				deviceCode: "",
				deviceName: "",
				worker: "admin",
				dataList: [],
				formData: [{
						type: "stateSelect",
						position: "PB",
						content: "检查各个管路及接头",
						methond: "目视野无液体渗出",
						placeholder: "请输入点检状态",
						name: "",
						value: "",
					},
					{
						type: "inputAndSelect",
						check: true,
						position: "开孔机",
						content: "检查油温",
						methond: "目视80°C~100°C",
						lower: 80,
						upper: 100,
						placeholder: "请输入点检状态",
						name: '',
						value: "",
					},
					{
						type: "inputAndSelect",
						position: "开孔机",
						content: "待机状态下真空度",
						methond: "目视<=6Bar",
						lower: 0,
						upper: 6,
						placeholder: "请输入待机状态下真空度",
						name: '',
						value: "",
					},
					{
						type: "inputAndSelect",
						position: "开孔机",
						content: "工作时真空度",
						methond: "达到-0.07~0.08Mpa",
						lower: -0.07,
						upper: 0.08,
						placeholder: "请输入工作时真空度",
						name: '',
						value: "",
					},
					{
						type: "inputAndSelect",
						position: "开孔机",
						content: "检查开孔机压缩空气压力",
						methond: "主表6±0.5bar,副表4±0.5bar",
						placeholder: "请输入检查开孔机压缩空气压力",
						name: '',
						value: "",
						main: {
							name: "",
							value: "",
							placeholder: "请输入主表压力",
							hint: "主表压力范围5.5~6.5bar",
							lower: "5.5",
							upper: "6.5"
						},
						minor: {
							name: "",
							value: "",
							placeholder: "请输入副表压力",
							hint: "副表压力范围3.5~4.5bar",
							lower: "3.5",
							upper: "4.5"
						}


					},
					{
						type: "stateSelect",
						position: "PB",
						content: "电机检查",
						methond: "倾听无异响",
						placeholder: "请输入点检状态2",
						name: '',
						value: "",
					},
					{
						type: "stateSelect",
						position: "PB",
						content: "检查气源气压",
						methond: "倾听无异响",
						placeholder: "请输入点检状态",
						name: '',
						value: "",
					},
					{
						type: "inputRange",
						position: "PB",
						content: "检查气袋气压",
						methond: "压力表示数范围2.5bar-4.5bar",
						inputLow: {
							name: "",
							value: "",
							placeholder: "请输入最低压力",
							lower: "2.5",
							upper: "4.5"
						},
						inputHigh: {
							name: "",
							value: "",
							placeholder: "请输入最高压力",
							lower: "2.5",
							upper: "4.5"
						}
					},
					{
						type: "groupSelect",
						content: "选择班组",
						placeholder: "请选择班组",
						name: '',
						value: "",
					}
				],


			}
		},
		computed: {},
		onLoad() {
			
		},
		onReady() {
			this.openScanPopup();
		},
		methods: {
			getScanResult(result) {
				uni.showLoading({
					title:"加载中",
					mask:true
				})
				getDeviceInfo(result).then(res=>{
					uni.hideLoading()
					this.deviceCode = result;
					console.log(result)
					this.reset();
					this.closeScanPopup();
					var groupSelect ={
						Type: "groupSelect",
						Content: "选择班组",
						placeholder: "请选择班组",
						name: '',
						value: "",
					}
					this.dataList = this.formData
					// res.Result;
					// this.dataList.push(groupSelect)
					// this.dataList.forEach(res=>{
					// 	res.SelectName=""
					// })
					// this.deviceName=this.dataList[0].Name;
					this.dateTime = getCurrDateTime()
				}).catch(error=>{
					uni.hideLoading()
					this.showMessage(error)
				})
				// this.deviceCode = result;
				// this.deviceName = "自配料系统"
				// console.log(result)
				// this.reset();
				// this.closeScanPopup();
				// this.dataList = this.formData;
				// this.dateTime = getCurrDateTime()
				
				
			},
			submit() {
				if (this.deviceCode == "") {
					this.$refs.comMessage.showMessage("提示", "请先扫描设备编号")
					return
				}
				this.$refs.customerFrom.submit(data => {
					var param =data
					console.log("提交", JSON.stringify(data))
					// foamCheckSubmit(param).then(res=>{
					// 	uni.hideLoading()
					// 	this.showMessage("提交成功")
					// 	this.clearData()
					// }).catch(error=>{
					// 	uni.hideLoading()
					// 	this.showMessage(error)
					// })

				})
			},
			clearData(){
				this.deviceCode=""
				this.dateTime = "",
				this.deviceCode= "",
				this.deviceName="",
				this.reset();
			},
			reset() {
				this.$refs.customerFrom.reset()
			},
			openScanPopup() {
				this.$refs.scanPopup.openScanPopup();
			},

			closeScanPopup() {
				this.$refs.scanPopup.closeScanPopup();
			},

		}
	}
</script>

<style lang="scss">
	.example {
		padding: 15px;
		background-color: #fff;
	}

	.segmented-control {
		margin-bottom: 15px;
	}

	.button-group {
		margin-top: 15px;
		display: flex;
		justify-content: space-around;
	}

	.form-item {
		display: flex;
		align-items: center;
		flex: 1;
	}

	.button {
		display: flex;
		align-items: center;
		height: 35px;
		line-height: 35px;
		margin-left: 10px;
	}
</style>