<template>
	<view class=" m-w u-flex f-d-c ">
		<view class="scr-hei">
			<!-- <scroll-view v-if="taskList != null && taskList.length > 0" @scrolltolower="getlist" :scroll-y="true" class="scr-hei "> -->
			<view v-if="taskList.length > 0 " v-for="(index,key) in taskList" :key="key">
				<slectdicsk :parobj="index"
					:prourl="`/scan_pages/scanning/scanning?roomId=${roomId}&taskId=${index.id}`" />
			</view>
			<!-- </scroll-view> -->
			<view v-if="taskList.length == 0">
				<u-empty margin-top="400" text="暂无数据" mode="list"></u-empty>
			</view>
		</view>

		<u-tabbar :height="tabheight" :before-switch="beforeSwitch" :list="tabbar" :mid-button="true"></u-tabbar>
	</view>
</template>

<script>
	import {
		mapState,
	} from 'vuex'
	import slectdicsk from '@/components/slectdicsk/index.vue'
	export default {
		components: {
			slectdicsk
		},
		data() {
			return {
				tabheight: 0,
				taskList: []
			}
		},
		computed: {
			...mapState({
				tabbar: state => state.tabbar.tabbar,
				roomId: state => state.user.roomId
			})
		},
		watch: {
			taskList: {
				deep: true,
				immediate: true,
				handler(n, o) {
					// console.log('taskList', n)
				}
			}
		},
		onLoad() {
			this.taskList = this.$store.state.user.taskList
			this.tabheight = getApp().globalData.tabhei
			this.getlist()
		},
		methods: {
			//底部导航栏
			beforeSwitch(id) {
				if (id == 1) {
					// this.taskList = this.$store.state.user.taskList
					this.$store.dispatch("user/gettasklist");
					return false;
				} else {
					return true;
				}
			},
			//判定房间计划是否为一条 一条则直接跳转去巡检
			async getlist() {
				if (this.taskList.length == 1) {
					const index = this.taskList[0]
					uni.redirectTo({
						url: `/scan_pages/scanning/scanning?roomId=${this.roomId}&taskId=${index.id}`,
					})
				}
				// this.taskList.length == 0 && (this.taskList = null)
			},
		}
	}
</script>

<style>
	.scr-hei {
		/* height: calc( 100vh - 74rpx ); */
		background: #FFFFFF;
		/* 	box-shadow: 0px 0px 6rpx 0px rgba(6, 0, 1,.3); */
		border-radius: 10rpx 10rpx 0px 0px;
		width: 750rpx;
	}
</style>
