<template>
	<view class="page">
		<u-navbar :title="title" :border-bottom="false" :background="bgc" title-color='#000' title-size='36'
			:title-bold='true' height='45' id="navbar">
		</u-navbar>
		<view class="tit">
			<image src="https://api.ccttiot.com/smartmeter/img/static/ufvwKG3vcJYtbkf0Oeij" mode=""></image>
			除螨设置
		</view>
		<view class="tit1">
			<image src="https://api.ccttiot.com/smartmeter/img/static/utZh1saVjZgOBz3orDkL" mode=""></image>
			间隔时长
		</view>
		<view class="set_li">
			每隔<view class="ipt_box"><input type="text" class="ips" v-model="miteInterval" placeholder=" "
					placeholder-class="my-placeholder" /> </view>天/次 除螨工作
		</view>
		<view class="tit">
			<image src="https://api.ccttiot.com/smartmeter/img/static/ufvwKG3vcJYtbkf0Oeij" mode=""></image>
			保护设置
		</view>
		<view class="tit1">
			<image src="https://api.ccttiot.com/smartmeter/img/static/utZh1saVjZgOBz3orDkL" mode=""></image>
			电量保护（%）
		</view>
		<view class="set_li">
			电量少于<view class="ipt_box"><input type="text" class="ips" v-model="minPower" placeholder=" "
					placeholder-class="my-placeholder" /> </view>加热板/风扇停止工作
		</view>
		<view class="tit1">
			<image src="https://api.ccttiot.com/smartmeter/img/static/utZh1saVjZgOBz3orDkL" mode=""></image>
			加热（℃）
		</view>
		<view class="set_li">
			箱外温度低于<view class="ipt_box"><input type="text" class="ips" v-model="minHeat" placeholder=" "
					placeholder-class="my-placeholder" /> </view>加热板工作
		</view>
		<view class="set_li">
			箱内高于箱外<view class="ipt_box"><input type="text" class="ips" v-model="maxHeat" placeholder=" "
					placeholder-class="my-placeholder" /> </view>加热板停止工作
		</view>
		<view class="tit1">
			<image src="https://api.ccttiot.com/smartmeter/img/static/utZh1saVjZgOBz3orDkL" mode=""></image>
			风扇（℃）
		</view>
		<view class="set_li">
			箱内温度高于<view class="ipt_box"><input type="text" class="ips" v-model="maxFan" placeholder=" "
					placeholder-class="my-placeholder" /> </view>风扇工作
		</view>
		<!-- <view class="set_li">
			箱内温度降到<view class="ipt_box"><input type="text" class="ips" v-model="code" placeholder=" "
					placeholder-class="my-placeholder" /> </view>风扇停止工作
		</view> -->
		<view class="set_li">
			CO₂浓度高于<view class="ipt_box"><input type="text" class="ips" v-model="maxCo2" placeholder=" "
					placeholder-class="my-placeholder" /> </view>风扇工作
		</view>
		<view class="set_li">
			CO₂浓度低于<view class="ipt_box"><input type="text" class="ips" v-model="minCo2" placeholder=" "
					placeholder-class="my-placeholder" /> </view>风扇停止工作
		</view>
		<view class="tit">
			<image src="https://api.ccttiot.com/smartmeter/img/static/ufvwKG3vcJYtbkf0Oeij" mode=""></image>
			震动通知
		</view>
		<view class="tit1">
			<image src="https://api.ccttiot.com/smartmeter/img/static/utZh1saVjZgOBz3orDkL" mode=""></image>
			单次震动
		</view>
		<view class="" style="padding-left: 50rpx;padding-top: 20rpx;box-sizing: border-box;">
			<u-checkbox-group>
				<u-checkbox active-color="#FFCC25" @change="checkboxChange(item.type)" v-model="item.checked"
					v-for="(item, index) in list" :key="index" :name="item.name">{{item.name}}</u-checkbox>
			</u-checkbox-group>
		</view>
		<view class="tit1">
			<image src="https://api.ccttiot.com/smartmeter/img/static/utZh1saVjZgOBz3orDkL" mode=""></image>
			持续震动
		</view>
		<view class="" style="padding-left: 50rpx;padding-top: 20rpx;box-sizing: border-box;">
			<u-checkbox-group>
				<u-checkbox active-color="#FFCC25" @change="checkboxChanges(item.type)" v-model="item.checked"
					v-for="(item, index) in lists" :key="index" :name="item.name">{{item.name}}</u-checkbox>
			</u-checkbox-group>
		</view>
		<view class="btn_box">
			<view class="btns">
				重置
			</view>
			<view class="btn1" @click="btnbc">
				保存
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				bgc: {
					backgroundColor: " #F4FAF8",
				},
				title: "设置",
				code: '',
				list: [{
						name: '短信',
						disabled: false,
						checked: false,
						type: 1
					},
					{
						name: '电话',
						disabled: false,
						checked: false,
						type: 2
					},
					{
						name: '微信',
						disabled: false,
						checked: false,
						type: 3
					}
				],
				lists: [{
						name: '短信',
						disabled: false,
						checked: false,
						type: 1
					},
					{
						name: '电话',
						disabled: false,
						checked: false,
						type: 2
					},
					{
						name: '微信',
						disabled: false,
						checked: false,
						type: 3
					}
				],
				value: [],
				values: [],
				miteInterval: '', //除螨间隔时间（天）
				minPower: '', //电量保护最低电量%
				minHeat: '', //加热板开始工作的最低箱外温度℃
				maxHeat: '', //加热板停止工作的箱内外温差℃
				maxFan: '', //风扇开始工作的最高箱内温度℃
				minCo2: '', //风扇停止工作的最低二氧化碳浓度℃
				maxCo2: '', //风扇开始工作的最高二氧化碳浓度℃
			}
		},
		onLoad() {
			this.getinfo()
		},
		onShow() {

		},
		methods: {
			checkboxChange(e) {
				let index = this.value.indexOf(e)
				if (index > -1) {
					this.value.splice(index, 1)
				} else {
					this.value.push(e)
				}
				console.log(this.value)
			},
			checkboxChanges(e) {
				let index = this.values.indexOf(e)
				if (index > -1) {
					this.values.splice(index, 1)
				} else {
					this.values.push(e)
				}
			},
			// 获取设置
			getinfo() {
				this.$u.get(`farm/userSetting/my`).then(res => {
					if (res.code == 200) {
						this.miteInterval = res.data.miteInterval,
							this.minPower = res.data.minPower,
							this.minHeat = res.data.minHeat,
							this.maxHeat = res.data.maxHeat,
							this.maxFan = res.data.maxFan,
							this.minCo2 = res.data.minCo2,
							this.maxCo2 = res.data.maxCo2
						this.list.forEach(item => {
							if (res.data.singleNotice.includes(item.type.toString())) {
								item.checked = true;
							}
						})
						this.value = res.data.singleNotice
						this.lists.forEach(item => {
							if (res.data.multipleNotice.includes(item.type.toString())) {
								item.checked = true;
							}
						})
						this.values = res.data.multipleNotice
					}
				})
			},
			btnbc() {
				let data = {
					miteInterval: this.miteInterval,
					minPower: this.minPower,
					minHeat: this.minHeat,
					maxHeat: this.maxHeat,
					maxFan: this.maxFan,
					minCo2: this.minCo2,
					maxCo2: this.maxCo2,
					singleNotice: this.value,
					multipleNotice: this.values
				}
				this.$u.put(`farm/userSetting/user`, data).then(res => {
					if (res.code == 200) {
						uni.showToast({
							title: '保存成功',
							icon: 'success',
							duration: 1000
						})
					}else if(res.code == 401){
						uni.navigateTo({
							url:'/pages/login/login'
						})
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none',
							duration: 2000
						});
					}
				})
			}

		}
	}
</script>

<style lang="scss">
	page {
		background-color: #F4FAF8;
	}

	.page {
		// position: relative;
		width: 750rpx;
		padding: 40rpx;

		.btn_box {
			margin-top: 136rpx;
			display: flex;
			flex-wrap: nowrap;
			align-items: center;

			.btns {
				display: flex;
				align-items: center;
				justify-content: center;
				width: 322rpx;
				height: 88rpx;
				background: #FFF5D6;
				border-radius: 20rpx 20rpx 20rpx 20rpx;
				border: 2rpx solid #FFC107;

				font-weight: 500;
				font-size: 32rpx;
				color: #FFC107;
			}

			.btn1 {
				display: flex;
				align-items: center;
				justify-content: center;
				margin-left: 30rpx;
				width: 322rpx;
				height: 88rpx;
				background: #FFCC25;
				border-radius: 20rpx 20rpx 20rpx 20rpx;

				font-weight: 500;
				font-size: 32rpx;
				color: #3D3D3D;
			}
		}

		.tit {
			display: flex;
			flex-wrap: nowrap;
			align-items: center;

			image {
				margin-right: 22rpx;
				width: 52rpx;
				height: 52rpx;

			}

			font-weight: 600;
			font-size: 36rpx;
			color: #3D3D3D;
		}

		.tit1 {
			margin-top: 32rpx;
			display: flex;
			flex-wrap: nowrap;
			align-items: center;

			image {
				margin-right: 18rpx;
				width: 46rpx;
				height: 46rpx;

			}

			font-weight: 400;
			font-size: 32rpx;
			color: #3D3D3D;
		}

		.set_li {
			margin-top: 34rpx;
			margin-left: 104rpx;
			display: flex;
			flex-wrap: nowrap;
			align-items: center;
			font-weight: 400;
			font-size: 32rpx;
			color: #808080;

			.ipt_box {
				display: flex;
				align-items: center;
				justify-content: center;
				margin: 0 16rpx;
				// width: 98rpx;
				height: 88rpx;
				background: #FFFFFF;
				box-shadow: 0rpx 0rpx 8rpx 0rpx rgba(0, 0, 0, 0.15);
				border-radius: 20rpx 20rpx 20rpx 20rpx;

				.ips {
					margin-left: 15rpx;
					width: 100rpx;

				}



				.my-placeholder {
					font-weight: 400;
					font-size: 32rpx;
					color: #808080;
				}

			}


		}

	}
</style>