<template>
	<view class="container">
		<view class="tabs">
			<scroll-view scroll-x class="bg-white nav">
				<view class="flex text-center">
					<view class="cu-item flex-sub" :class="index==current?'base-color text-xl text-bold cur':'text-lg'" v-for="(item,index) in tabs" :key="index" @tap="tabChange(index)" >
						{{item.name}}
					</view>
				</view>
			</scroll-view>
		</view>
		<view style="height: 100%;">
			<swiper style="height: 100%;" :current="current"  @change="swiperChange"
				@animationfinish="animationfinish">
				<swiper-item  v-for="(item, index) in tabs" :key="index">
					<scroll-view scroll-y style="height: 100%;">
						<item :fireType="fireType" :refresh="refresh" :i="index" :item="item" :type="current"></item>
					</scroll-view>
				</swiper-item>
			</swiper>
		</view>
	</view>
</template>
<script>
	import item from "./comps/item.vue"
	export default {
		components: {
			item
		},
		data() {
			return {
				//0 烟感报警 1 燃气告警 2 消防水压
				fireType:0,
				//是否第一次进入页面
				isfirst:false,
				//让item主动刷新
				refresh:false,
				scrollLeft:0,
				current: 0,
				swiperCurrent:0,
				tabs: [
					{
						name: '全部',
						value:''
					},
					{
						name: '正常',
						value:1
					},
					{
						name: '告警',
						value:2
					},
					{
						name:'失联',
						value:3
					},
					{
						name:'停用',
						value:4
					},
				],
			}
		},
		onShow(){
			
		},
		onLoad(options) {
			this.fireType=options.fireType || 0
			getApp().globalData.fireType=this.fireType
			if (this.fireType==1) {
				uni.setNavigationBarTitle({
				    title: '气感'
				});
			}else if (this.fireType==2) {
				uni.setNavigationBarTitle({
				    title: '消防栓'
				});
			}else if (this.fireType==3) {
				uni.setNavigationBarTitle({
				    title: '电表'
				});
			}
		},
		methods:{
			tabChange(index) {
				this.current = index
				// this.scrollLeft = (index - 1) * 60
			},
			swiperChange(e) {
			  uni.pageScrollTo({
			      scrollTop: 0,
			      duration: 0
			  });
			  this.current = e.detail.current
			  // this.scrollLeft = (this.current - 1) * 60
			},
			animationfinish({detail: { current }}) {
				this.swiperCurrent = current;
				this.current = current;
			},
		}
	}
</script>

<style lang="scss" scoped>
	.text-blue{
		color: #59a5f0;
	}
	.text-xl{
		font-size: 34rpx;
	}
	.container {
	  height: calc(100vh);
	  background-color: #F6F6F6;
	  padding: 78rpx 0rpx 0rpx;
	 .tabs {
	    position: fixed;
	    top: -10rpx;
		left: 0;
		display: flex;
		align-items: center;
		width: 100%;
		background-color: #FFFFFF;
		box-sizing: border-box;
		z-index: 3;
	  }
}
</style>