<template>
	<view class="">
		<!-- <view class="line">
		</view> -->
		
		<view class="search">
			<view class="search-title">
				{{$t('dosugar.equipmentClientID')}}
			</view>
			<view class="search-input">
				<input type="text" :placeholder="$t('dosugar.placeholder')" v-model="searchClientId" />
			</view>
			<view class="search-button">
				<button type="primary" class="" @click="search()">
					<p class="">{{$t('dosugar.search')}}</P>
				</button>
			</view>
		</view>
		<view class="td-right">
			<view class="uni-list">
				<view class="uni-list-cell">
					<view class="uni-list-cell-left">
						{{$t('dosugar.chooseEquipment')}}
					</view>
					<view class="uni-list-cell-db" style="overflow: hidden;text-overflow: ellipsis;">
						<picker @change="changeEquipment" :value="index" :range="equipmentNameList">
							<view class="uni-input">{{equipmentNameList[index]}}</view>
						</picker>
					</view>
				</view>
			</view>
		</view>
		<view >
			<view class="body">
				<p class="p">炉头工作温度：</p>
				<input class="input" type="text" v-model="D418" />
				<button type="primary" class="button" @click="update('D418',D418)">
					<p class="p2">更新</P>
				</button>
			</view>
			<view class="line2"></view>
			<view class="body">
				<p class="p">炉头中速：</p>
				<input class="input" type="text" v-model="D406" />
				<button type="primary" class="button" @click="update('D406',D406)">
					<p class="p2">更新</P>
				</button>
			</view>
			<view class="line2"></view>
			<view class="body">
				<p class="p">水泵开启时间：</p>
				<input class="input" type="text" v-model="D408" />
				<button type="primary" class="button" @click="update('D408',D408)">
					<p class="p2">更新</P>
				</button>
			</view>
			<view class="line2"></view>
			<view class="body">
				<p class="p">风机吹气时间：</p>
				<input class="input" type="text" v-model="D409" />
				<button type="primary" class="button" @click="update('D409',D409)">
					<p class="p2">更新</P>
				</button>
			</view>
			<view class="line2"></view>
			<view class="body">
				<p class="p">下糖粗细系数：</p>
				<input class="input" type="text" v-model="D416" />
				<button type="primary" class="button" @click="update('D416',D416)">
					<p class="p2">更新</P>
				</button>
			</view>
			<view class="line2"></view>
			<view class="body">
				<p class="p">柜内允许做糖温度误差：</p>
				<input class="input" type="text" v-model="D419" />
				<button type="primary" class="button" @click="update('D419',D419)">
					<p class="p2">更新</P>
				</button>
			</view>
			<view class="line2"></view>
			<view class="body">
				<p class="p">回差调节：</p>
				<input class="input" type="text" v-model="M504" />
				<button type="primary" class="button" @click="update('M504',M504)">
					<p class="p2">更新</P>
				</button>
			</view>
			<view class="line2"></view>
			<!-- 320和301特有 -->
			<view class="" v-show="equimentType=='MG301'||equimentType=='MG320'">
				<view class="line2"></view>
				<view class="body">
					<p class="p">炉头低速：</p>
					<input class="input" type="text" v-model="D405" />
					<button type="primary" class="button" @click="update('D405',D405)">
						<p class="p2">更新</P>
					</button>
				</view>
				<view class="line2"></view>
				<view class="body">
					<p class="p">炉头高速：</p>
					<input class="input" type="text" v-model="D407" />
					<button type="primary" class="button" @click="update('D407',D407)">
						<p class="p2">更新</P>
					</button>
				</view>
				<view class="line2"></view>
				<view class="body">
					<p class="p">手动门关闭等待时间：</p>
					<input class="input" type="text" v-model="D412" />
					<button type="primary" class="button" @click="update('D412',D412)">
						<p class="p2">更新</P>
					</button>
				</view>
				<view class="line2"></view>
				<view class="body">
					<p class="p">低温环境设定(炉头升柜温)：</p>
					<input class="input" type="text" v-model="D460" />
					<button type="primary" class="button" @click="update('D460',D460)">
						<p class="p2">更新</P>
					</button>
				</view>
				<view class="line2"></view>
				<view class="body">
					<p class="p">高温环境设定(外循环风机)：</p>
					<input class="input" type="text" v-model="D461" />
					<button type="primary" class="button" @click="update('D461',D461)">
						<p class="p2">更新</P>
					</button>
				</view>
			</view>
			<!-- //320特有 -->
			<view class="" v-show="equimentType=='MG320'">
				<view class="line2"></view>
				<view class="body">
					<p class="p">加湿时炉头升温N度：</p>
					<input class="input" type="text" v-model="D467" />
					<button type="primary" class="button" @click="update('D467',D467)">
						<p class="p2">更新</P>
					</button>
				</view>
				<view class="line2"></view>
				<view class="body">
					<p class="p">加湿时候监控时间：</p>
					<input class="input" type="text" v-model="D468" />
					<button type="primary" class="button" @click="update('D468',D468)">
						<p class="p2">更新</P>
					</button>
				</view>
				<view class="line2"></view>
				<view class="body">
					<p class="p">加湿OFF时间：</p>
					<input class="input" type="text" v-model="D475" />
					<button type="primary" class="button" @click="update('D475',D475)">
						<p class="p2">更新</P>
					</button>
				</view>
				<view class="line2"></view>
				<view class="body">
					<p class="p">加湿ON时间：</p>
					<input class="input" type="text" v-model="D476" />
					<button type="primary" class="button" @click="update('D476',D476)">
						<p class="p2">更新</P>
					</button>
				</view>
				<view class="line2"></view>
				<view class="body">
					<p class="p">加湿启动延时：</p>
					<input class="input" type="text" v-model="D477" />
					<button type="primary" class="button" @click="update('D477',D477)">
						<p class="p2">更新</P>
					</button>
				</view>
				<view class="line2"></view>
				<view class="body">
					<p class="p">加湿停止延时：</p>
					<input class="input" type="text" v-model="D478" />
					<button type="primary" class="button" @click="update('D478',D478)">
						<p class="p2">更新</P>
					</button>
				</view>
				<view class="line2"></view>
				<view class="body">
					<p class="p">出棍后机械手等待时间：</p>
					<input class="input" type="text" v-model="D471" />
					<button type="primary" class="button" @click="update('D471',D471)">
						<p class="p2">更新</P>
					</button>
				</view>
			</view>
			<!-- 301和280特有 -->
			<view class="" v-show="equimentType=='MG301'||equimentType=='MG280'">
				<view class="line2"></view>
				<view class="body">
					<p class="p">基准系数：</p>
					<input class="input" type="text" v-model="D444" />
					<button type="primary" class="button" @click="update('D444',D444)">
						<p class="p2">更新</P>
					</button>
				</view>
				<view class="line2"></view>
				<view class="body">
					<p class="p">基准湿度：</p>
					<input class="input" type="text" v-model="D445" />
					<button type="primary" class="button" @click="update('D445',D445)">
						<p class="p2">更新</P>
					</button>
				</view>
			</view>
			<!-- 280特有 -->
			<view class="" v-show="equimentType=='MG280'">
				<view class="line2"></view>
				<view class="body">
					<p class="p">加湿OFF时间：</p>
					<input class="input" type="text" v-model="D472" />
					<button type="primary" class="button" @click="update('D472',D472)">
						<p class="p2">更新</P>
					</button>
				</view>
				<view class="line2"></view>
				<view class="body">
					<p class="p">加湿ON时间：</p>
					<input class="input" type="text" v-model="D473" />
					<button type="primary" class="button" @click="update('D473',D473)">
						<p class="p2">更新</P>
					</button>
				</view>
			</view>
		</view>
		<view class="line2"></view>
	</view>
</template>
<script>
	import {
		mapState,
		mapActions,
		mapMutations
	} from 'vuex'
	export default {
		data() {
			return {
				D418: 0,
				D405: 0,
				D406: 0,
				D407: 0,
				D408: 0,
				D409: 0,
				D412: 0,
				D416: 0,
				D460: 0,
				D461: 0,
				D419: 0,
				D435: 0,
				D467: 0,
				D468: 0,
				M504: 0,
				D475: 0,
				D476: 0,
				D477: 0,
				D478: 0,
				D471: 0,
				D444: 0,
				D445: 0,
				D472: 0,
				D473: 0,
				index: null,
				equipmentName: null,
				equimentType: null,
				equipmentId:null,
				equipmentNameList: [],
				globalUser: null,
				show: true,
				searchClientId:null
			}
		},
		onShow() {
			var token = uni.getStorageSync("token");
			this.globalUser = uni.getStorageSync("globalUser");
			if (token.length > 1) {
				this.getEquipmentListData();
				// this.getParam();
			} else {
				uni.reLaunch({
					url: '../Login/Login',
				});
			}

		},
		methods: {
			...mapActions('chart', ['getParameters', 'updateParameters', 'getEquipmentListByUser']),
			getEquipmentListData() {
				this.getEquipmentListByUser(this.globalUser)
					.then(data => {
						// this.merchantList = data;
						var listName = data[0].equipmentList;
						var equipmentNameList = [];
						for (var i = 0; i < listName.length; i++) {
							equipmentNameList.push("名称:" + listName[i].name + " 编号:" + listName[i].clientId.substring(
								listName[i].clientId.length - 6, listName[i].clientId.length));
						}
						this.equipmentNameList = equipmentNameList;
						var listId = data[0].id;
						if (listId != null && listId != '1') {
							uni.setStorageSync("listName", listName);
						}
						uni.stopPullDownRefresh();
					}, _ => void uni.stopPullDownRefresh());
			},
			search(){
				var clientId = this.searchClientId;
				var list = uni.getStorageSync("listName");
				var n = 0;
				for (var i = 0; i < list.length; i++) {
					var code = list[i].clientId.substring(list[i].clientId.length - 6, list[i].clientId.length);
					if(code==clientId){
						n++;
						this.D418=null;
						this.D405=null;
						this.D406=null;
						this.D407=null;
						this.D408=null;
						this.D409=null;
						this.D412=null;
						this.D416=null;
						this.D460=null;
						this.D461=null;
						this.D419=null;
						this.D435=null;
						this.D467=null;
						this.D468=null;
						this.M504=null;
						this.D475=null;
						this.D476=null;
						this.D477=null;
						this.D478=null;
						this.D471=null;
						this.D444=null;
						this.D445=null;
						this.D472=null;
						this.D473=null;
						this.index = i;
						var id = list[i].id;
						this.equipmentId =  id;
						this.equimentType = list[i].equimentType;
						this.clientId = list[i].clientId;
						this.show = true;
						if (this.equimentType == 'MG280') {
							this.show = false;
						}
						this.getParam();
						break;
					}
				}
				if(n==0){
					uni.showModal({
						title: "提示",
						content: "找不到该机器",
						success: (res) => {
					
						}
					})
				}
			},
			//改变机器
			changeEquipment: function(e) {
				this.D418=null;
				this.D405=null;
				this.D406=null;
				this.D407=null;
				this.D408=null;
				this.D409=null;
				this.D412=null;
				this.D416=null;
				this.D460=null;
				this.D461=null;
				this.D419=null;
				this.D435=null;
				this.D467=null;
				this.D468=null;
				this.M504=null;
				this.D475=null;
				this.D476=null;
				this.D477=null;
				this.D478=null;
				this.D471=null;
				this.D444=null;
				this.D445=null;
				this.D472=null;
				this.D473=null;
				this.searchClientId = null;
				this.index = e.target.value;
				var list = uni.getStorageSync("listName");
				// this.getProName(list[e.target.value].id);
				this.equipmentId = list[e.target.value].id;
				this.equimentType = list[e.target.value].equimentType;
				this.clientId = list[e.target.value].clientId;
				this.show = true;
				if (this.equimentType == 'MG280') {
					this.show = false;
				}
				// console.log("eid==" + this.equipmentId);
				// console.log("equimentType==" + this.equimentType);
				this.getParam();
			},
			getParam() {
				const param = {};
				param['id'] = this.equipmentId;
				// 0：通用参数；  1：进阶参数
				param['status'] = '0';
				param['clientId'] = this.clientId;
				this.getParameters(param).then(res => {
					var code = res.code;
					if(code==false){
						uni.showToast({
							title: data.data.message,
							duration: 2000
						});
						return;
					}
					var info = res.data;
					if (info != null || info != '') {
						for (var i = 0; i < info.length; i++) {
							if (info[i].name == 'D418') {
								this.D418 = info[i].val;
							}
							if (info[i].name == 'D405') {
								this.D405 = info[i].val;
							}
							if (info[i].name == 'D406') {
								this.D406 = info[i].val;
							}
							if (info[i].name == 'D407') {
								this.D407 = info[i].val;
							}
							if (info[i].name == 'D408') {
								this.D408 = info[i].val;
							}
							if (info[i].name == 'D409') {
								this.D409 = info[i].val;
							}
							if (info[i].name == 'D412') {
								this.D412 = info[i].val;
							}
							if (info[i].name == 'D416') {
								this.D416 = info[i].val;
							}
							if (info[i].name == 'D460') {
								this.D460 = info[i].val;
							}
							if (info[i].name == 'D461') {
								this.D461 = info[i].val;
							}
							if (info[i].name == 'D419') {
								this.D419 = info[i].val;
							}
							if (info[i].name == 'D435') {
								this.D435 = info[i].val;
							}
							if (info[i].name == 'D467') {
								this.D467 = info[i].val;
							}
							if (info[i].name == 'D468') {
								this.D468 = info[i].val;
							}
							if (info[i].name == 'M504') {
								this.M504 = info[i].val;
							}
							if (info[i].name == 'D475') {
								this.D475 = info[i].val;
							}
							if (info[i].name == 'D476') {
								this.D476 = info[i].val;
							}
							if (info[i].name == 'D477') {
								this.D477 = info[i].val;
							}
							if (info[i].name == 'D478') {
								this.D478 = info[i].val;
							}
							if (info[i].name == 'D471') {
								this.D471 = info[i].val;
							}
							if (info[i].name == 'D444') {
								this.D444 = info[i].val;
							}
							if (info[i].name == 'D445') {
								this.D445 = info[i].val;
							}
							if (info[i].name == 'D472') {
								this.D472 = info[i].val;
							}
							if (info[i].name == 'D473') {
								this.D473 = info[i].val;
							}
						}
					}

				}, _ => void uni.stopPullDownRefresh());
			},
			update(name, val) {
				const param = {};
				param['id'] = this.equipmentId;
				param['name'] = name;
				param['val'] = val;
				this.updateParameters(param).then(res => {
					if (res.data == 'SUCCESS') {
						uni.showToast({
							title: '发送成功',
							duration: 1000
						});
					}
				}, _ => void uni.stopPullDownRefresh());
			},
		},
	}
</script>

<style>
	.search{
		width: 100%;
		padding-top: 10upx;
		display: flex;
		flex-direction: row;
		justify-content: flex-start;
	}
	.search-title{
		width: 28%;
		text-align: center;
		font-size: 26upx;
		font-family: "PingFang-SC-Bold";
	}
	.search-input{
		width: 45%;
		text-align: center;
		font-size: 26upx;
		font-family: "PingFang-SC-Bold";
		box-shadow: 0upx 0upx 20upx #D3D3D3;
		border-radius: 5upx;
	}
	.search-button{
		width: 20%;
		padding-left: 7upx;
		text-align: center;
	}
	.line {
		height: 50upx;
	}

	.line2 {
		height: 10upx;
	}

	.body {
		background-color: #FFFFFF;
		width: 700upx;
		padding: 10upx 10upx 10upx 10upx;
		display: flex;
		flex-direction: row;
		justify-content: flex-start;
		font-size: 32upx;
	}

	.p {
		width: 350upx;
		text-align: right;
	}

	.input {
		width: 200upx;
		box-shadow: 0upx 0upx 20upx #D3D3D3;
		border-radius: 5upx;
		text-align: center;
	}

	.button {
		width: 120upx;
		height: 60upx;
		text-align: left;
		border-radius: 10upx;

	}

	.p2 {
		font-size: 30upx;
		/* #ifndef H5 */
		padding-top: 3upx;
		/* #endif */
		position: absolute;
		/* 水平居中 */
		left: 50%;
		-webkit-transform: translateX(-50%);
		transform: translateX(-50%);
	}
</style>
