<template>
	<view class="fullHeight">
		<headers :showBack="true" class="">
			<view class="headerName">
				定时任务
			</view>
		</headers>
		<view class="listBox">
			<view class="listItem" v-for="item in list" :key="item.id" @click="goAdd(item.id)">
				<view class="title">
					执行时间：{{item.executeTime}}
				</view>
				<view class="bottom">
					重复：{{formatRepeat(item)}}
				</view>
				<view class="bottom">
					开关：{{item.switchType===1?'关':item.switchType===2?'开':''}}
				</view>
				<!-- <view class="bottom">
					<text class="time">{{item.createTime}}</text>
				</view> -->
				<image src="/static/icon-right.png" class="icon-right"></image>
			</view>
			<view class="placeholderBox" v-show="list.length==0">
				<image src="/static/noData.png" class="noDataImg"></image>
				<view class="text">
					暂无数据
				</view>
			</view>
		</view>
		
		<image src="/static/addImg.png" class="addImg" @click="goAdd('')"></image>
	</view>
</template>

<script>
	import headers from "@/components/headers/headers.vue"
	export default {
		components:{headers},
		data() {
			return {
				list:[],
				sprayDevId:'',
				weekArr:['周一','周二','周三','周四','周五','周六','周日'],
			};
		},
		onLoad(options) {
			this.sprayDevId=options.id
		},
		onShow() {
			this.loadData()
		},
		onPullDownRefresh() {
			this.list=[]
			this.loadData()
		},
		methods:{
			formatRepeat(row){
				// console.log('formatRepeat',row)
				if(row.isRepeat=='1'){
					return '只执行一次'
				}else{
					var a = row.repeatExecuteWeek;
					var arr=[]
					if(a.indexOf(',')!=-1){
						arr=a.split(',')
					}else{
						arr=[a]
					}
					if(arr.length==7){
						return '每天'
					}else{
						let arr2=[]
						arr.forEach(element => {
							arr2.push(this.weekArr[parseInt(element)-1])
						});
						return arr2.join('、')
					}
					
				}
			},
			loadData(){
				var that = this
				this.sendRequest({
					url: 'xmgl/sprayDevTimingTask/selectList',
					data: {sprayDevId:this.sprayDevId},
					method: "POST",
					success(res){
						that.list=res.result
					}
				})
			},
			goAdd(id){
				uni.navigateTo({
					url:'./add?id='+id+'&sprayDevId='+this.sprayDevId
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
.addImg{
	position: fixed;
	bottom: 15px;
	right: 15px;
	width: 62px;
	height: 62px;
}
.listBox{
	margin: 15px;
}
.listItem{
	box-shadow: 0px 4px 13px 0px rgba(212, 220, 236, 0.53);
	position: relative;
	margin-bottom: 5px;
	padding: 15px;
	border-radius: 8px;
	.title{
		font-size: 15px;
		font-weight: bold;
		margin-bottom: 10px;
	}
	.bottom{
		color: rgba(55, 45, 102, 0.5);
		font-size: 12px;
	}
	.time{
		margin-right: 12px;
	}
}
.icon-right{
	position: absolute;
	width: 8px;
	height: 14px;
	right: 15px;
	top: calc(50% - 7px);
}
</style>
