<template>
	<view>
		<view class="status_bar"></view>
		<view class="" style="position: relative;top: 44px;">
			<view style="position: fixed;z-index: 100;width: 100%;">
				<uni-nav-bar @clickLeft="clickLeft" left-icon="back" left-text="返回" title="设备控制"></uni-nav-bar>
			</view>
			<view class="operation">
				<p class="operation_title">操作</p>
				<view class="operation_btn">
					<button @click="chongqi">重 启</button>
					<button @click="shengji">升 级</button>
					<button @click="search">查询时间上传间隔</button>
				</view>
			</view>
			<view class="viewing">
				<p class="operation_title">显示屏设置</p>
				<view class="viewing_text">
					<view class="viewing_text_top">
						标题文字设置 ：
						<input type="text" v-model="config.content" />
					</view>
					<view class="viewing_text_bot">
						显示时间设置(min) ：
						<input type="number" v-model="config.timeout" />
					</view>
				</view>
			</view>
			<view class="timing">
				<p class="operation_title">上传时间间隔(min)</p>
				<view class="timing_text">
					<slider value="1" @change="sliderChange" step="1" min="1" max="360" show-value block-size="18" activeColor="#57C878" />
				</view>
			</view>
			<view class="ensure">
				<view class="ensure_btn" @click="ensure">
					确 定
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				config: {
					content: "",
					timeout: "",
					interval: ""
				},
				id: ''
			}
		},
		methods: {
			//forecast.send_control.device_control  config: {"interval":10,"content":"content","timeout":"1"}
			async timing(datas) { //提交数据
				const res = await this.$myRequest({
					url: '/api/api_gateway?method=weather.weather.qxz_status',
					data: {
						device_type_id: 5,
						d_id: this.id,
						config: JSON.stringify(datas)
					}
				})
			},
			//forecast.send_control.admin_device_control
			async restart(datas) { //重启
				const res = await this.$myRequest({
					url: '/api/api_gateway?method=forecast.send_control.admin_device_control',
					data: {
						device_type_id: 5,
						d_id: this.id,
						cmd: datas
					}
				})
				if (res == true) {
					uni.showToast({
						title: '指令下发成功!'
					});
				} else {
					uni.showToast({
						title: '指令下发失败!'
					});
				}
			},
			//forecast.send_control.get_device_config
			async uploading() { //上传时间
				const res = await this.$myRequest({
					url: '/api/api_gateway?method=forecast.send_control.get_device_config',
					data: {
						device_type_id: 5,
						d_id: this.id,
						control_type: "data"
					}
				})
				console.log(res)
				if (res == true) {
					uni.showToast({
						title: '指令下发成功!'
					});
				} else {
					uni.showToast({
						title: '指令下发失败!'
					});
				}
			},
			clickLeft() { //返回
				uni.navigateBack({
					delta: 1
				})
			},
			ensure() { //提交
				this.timing(this.config)
			},
			sliderChange(e) { //滑动块
				this.config.interval = e.detail.value
			},
			chongqi() { //重启按钮
				this.restart('reboot')
			},
			shengji() { //升级按钮
				this.restart('update')
			},
			search() { //查询按钮
				this.uploading()
			}
		},
		onLoad(option) {
			this.id = option.id
		}
	}
</script>

<style lang="scss">
	.operation_title {
		border-left: 6rpx solid #28AE4F;
		padding-left: 20rpx;
		margin-bottom: 20rpx;
		height: 36rpx;
	}

	.operation {
		position: absolute;
		top: 54px;
		width: 90%;
		left: 5%;

		.operation_btn {
			display: flex;
			padding-left: 20rpx;

			button {
				font-size: 24rpx;
				padding: 0 38rpx;
				background-color: #28AE4F;
				color: #FFFFFF;
			}

			button:last-child {
				width: 360rpx !important;
			}
		}
	}

	.viewing {
		position: absolute;
		top: 124px;
		width: 90%;
		left: 5%;

		.viewing_text {

			.viewing_text_top,
			.viewing_text_bot {
				display: flex;
				background-color: #F7F8FA;
				padding-left: 20rpx;
				margin-bottom: 20rpx;
				height: 60rpx;
				line-height: 60rpx;
				font-size: 24rpx;

				input {
					font-size: 24rpx;
					margin-top: 16rpx;
					width: 400rpx;
				}
			}
		}
	}

	.timing {
		position: absolute;
		top: 234px;
		width: 90%;
		left: 5%;
	}

	.ensure {
		width: 100%;
		position: absolute;
		top: 600rpx;
		.ensure_btn {
			width: 90%;
			margin: 0 auto;
			height: 60rpx;
			line-height: 60rpx;
			text-align: center;
			background-color: #28AE4F;
			color: #FFFFFF;
			border-radius: 200rpx;
		}
	}
</style>
