<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; font-weight: bold;">
						设备编号 : {{deviceCode}}
					</view>
					<view class="" style="margin: 5rpx; font-weight: bold;" 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="">
				<view class="uni-flex uni-row space-between u-col-center"  >
					<view class="" style="margin: 5rpx; font-weight: bold;">
						设备编号: 
					</view>
					<uni-easyinput
					 class="" 
					 trim="all" 
					 ref="inputDevice"
					 v-model="deviceCode"
					 @clear="deviceClear"
					 :focus="true"
						@confirm="onConfirmDevice"></uni-easyinput>
				</view>
				<view class="" style="margin: 5rpx; font-weight: bold;" v-if="deviceName!=''">
					设备名称 : {{deviceName}}
				</view>
				<view class="" style="margin: 5rpx;" v-if="deviceName!=''">
					点检日期 : {{dateTime}}
				</view>
				<view class="" style="margin: 5rpx;" v-if="deviceName!=''">
					点检人 : {{worker}}
				</view>
			</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="clearData">清空</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 {
		foamCheckSubmit,
		getPlasticsDeviceInfo
	} from '@/api/request2.js';
	export default {
		components: {
			customerFrom,
			winScanNormal,
			showModal
		},
		data() {
			return {
				dateTime: "",
				deviceCode: "",
				deviceCheckCode:"",
				deviceName: "",
				worker: this.$store.state.user.name,
				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() {

		},
		mounted() {
			this.$refs.inputDevice.focused = true
		},
		onReady() {
			// this.openScanPopup();
		},
		methods: {
			getScanResult(result) {
				uni.showLoading({
					title: "加载中",
					mask: true
				})
				getPlasticsDeviceInfo(result).then(res => {
					uni.hideLoading()
					this.deviceCode = result;
					console.log(result)
					this.closeScanPopup();
					var groupSelect = {
						Type: "4",
						Content: "选择班组",
						SelectName: "",
						SelectValue: "",
					}
					// this.dataList = this.formData
					this.dataList = res.Result;
					this.dataList.push(groupSelect)
					
					this.deviceName=this.dataList[0].Name;
					this.dateTime = getCurrDateTime()
					this.worker = this.$store.state.user.name
				}).catch(error => {
					uni.hideLoading()
					this.showMessage(error)
				})

			},
			submit() {
				if (this.deviceCode == "") {
					this.deviceCheckCode=""
					this.$refs.comMessage.showMessage("提示", "请先扫描设备编号")
					return
				}
				this.$refs.customerFrom.submit(data => {
					var groupName="";
					var groupValue=""
					data.forEach(res=>{
						if(res.Type=="4"){
							groupName=res.SelectName;
							groupValue=res.SelectValue;
						}
					})
					var commitData={
						id:this.$store.state.user.id,
						createTime:getCurrDateTime(),
						groupName:groupName,
						groupValue:groupValue,
						dataList:data
					}
					
					console.log("提交", JSON.stringify(commitData))
					foamCheckSubmit(commitData).then(res=>{
						uni.hideLoading()
						this.showMessage("提交成功")
						this.clearData()
					}).catch(error=>{
						uni.hideLoading()
						this.showMessage(error)
					})
				})
			},
			clearData() {
				this.deviceCode = ""
				this.deviceName="";
				this.dateTime ="";
				this.dateTime = "",
				this.deviceCode = "",
				this.deviceName = "",
				this.worker=""
				this.dataList=[]
					// this.reset();
		},
			reset() {
				this.$refs.customerFrom.reset()
			},
			openScanPopup() {
				this.$refs.scanPopup.openScanPopup();
			},

			closeScanPopup() {
				this.$refs.scanPopup.closeScanPopup();
			},
			deviceClear(){
				this.deviceCode="";
				this.deviceCheckCode=""
			},
			showMessage(hint){
				this.$refs.comMessage.showMessage("提示", hint)
			},
			onConfirmDevice(data){
				if(data==undefined||data==""){
					this.showMessage("请扫描设备编号")
					return;
				}
			
				uni.showLoading({
					title: "加载中",
					mask: true
				})
				getPlasticsDeviceInfo(data).then(res => {
					uni.hideLoading()
					this.deviceCode = data;
					this.deviceCheckCode = data;
					console.log(data)
					this.closeScanPopup();
					var groupSelect = {
						Type: "4",
						Content: "选择班组",
						SelectName: "",
						SelectValue: "",
					}
					this.dataList = res.Result;
					this.dataList.unshift(groupSelect)
					this.deviceName=this.dataList[1].Name;
					this.dateTime = getCurrDateTime()
				}).catch(error => {
					uni.hideLoading()
					this.showMessage(error)
				})
			},

		}
	}
</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>