<template>
	<view class="page">
		<u-navbar title="设备故障" :border-bottom="false" :background="bgc" title-color='#000' title-size='36'
			height='58'></u-navbar>
		<view class="box">
			<view class="nav">
				<view class="top">
					<u-search placeholder="搜索" input-align="center" v-model="keyword" @custom="serch"></u-search>
					<view class="yc" @click="btnyc">上报异常</view>
				</view>
				<view class="tab">
					<u-tabs :list="list" :is-scroll="false" active-color="#1DBE7B" :current="current" @change="change"></u-tabs>
				</view>
			</view>
			
			<view class="list" @scrolltolower="onReachBottom" v-for="(item,index) in wateringList" :key="index">
				<view class="list_val">
					<view class="wz">设备编号</view> <view class="gl">{{item.cabinetSn}}</view>
				</view>
				<view class="list_val">
					<view class="wz">故障原因</view> 
					<view class="gl" v-if="item.type == 1">弹出失败</view>
					<view class="gl" v-if="item.type == 2">卡槽损坏</view>
					<view class="gl" v-if="item.type == 3">设备破坏</view>
					<view class="gl" v-if="item.type == 4">仓位异常</view>
				</view>
				<view class="list_val">
					<view class="wz">备注</view> <view class="gl">{{item.remark}}</view>
				</view>
			</view>
			
			<view class="" style="width: 448rpx;height: 448rpx;margin: auto;margin-top: 100rpx;text-align: center;"
				v-if="showflag">
				<image style="width: 448rpx;height: 448rpx;"
					src="https://api.ccttiot.com/smartmeter/img/static/ufLi6IZd5kh1MIEZFYTo" mode=""></image>
				<view class="" style="font-size: 30rpx;color: #ccc;margin-top: 30rpx;">暂无更多记录...</view>
			</view>
			
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [{
					name: '全部'
				}, {
					name: '弹出失败'
				}, {
					name: '卡槽损坏'
				}, {
					name: '设备破坏'
				}, {
					name: '仓位异常'
				}],
				current: 0,
				pagenum: 1,
				wateringList: [],
				pagesize: 10, // 一页多少数据
				isLoading: false, // 是否正在加载数据  
				noMoreData: false, // 是否没有更多数据  
				total: 0,
				keyword:'',
				type:'',
				bgc:{
					background:'#25CE88'
				},
				showflag: false
			}
		},
		onLoad() {
			
		},
		onShow() {
			this.wateringList = []
			this.pagenum = 1
			this.getlist()
		},
		methods: {
			serch(){
				this.wateringList = []
				this.pagenum = 1
				this.getlist()
			},
			change(index) {
				this.wateringList = []
				this.pagenum = 1
				this.current = index;
				if(index == 0){
					this.type = ''
					this.getlist()
				}else{
					this.type = index
					this.getlist()
				}
			},
			
			btnyc(){
				uni.navigateTo({
					url:'/pages/agentpages/devicemanagement/failure/yichang/index'
				})
			},
			getlist(){
				this.$u.get('/agent/abnormal/list?pageNum=' + this.pagenum + '&pageSize=' + this.pagesize +'&type=' +this.type + '&keyword=' + this.keyword).then(res => {
					if (res.code == 200) {
					    this.total = res.total
						if (this.total > 0) {
							this.showflag = false
						} else {
							this.showflag = true
						}
					    if (res.rows.length > 0) {
					    	// 有数据，追加到列表  
					    	this.wateringList = this.wateringList.concat(res.rows)
					    	this.pagenum++
					    } else {
					    	// 没有更多数据  
					    	this.noMoreData = true;
					    }
					    this.isLoading = false;
					}
				})
			},
			onReachBottom() {
				let sum = this.total / this.pagesize
				if (this.pagenum-1 < sum) {
					this.getlist();
				} else {
					uni.showToast({
						title: '没有更多记录了',
						icon: 'none',
						duration: 1000
					});
				}
			},
		}
	}
</script>

<style lang="scss">
	/deep/ .u-title,
	/deep/ .uicon-nav-back{
		padding-bottom: 40rpx;
	}
	
	page {
		background: #F4F5F7
	}

	.page {
		width: 750rpx;
		// position: fixed;
		// top: 0;
		// left: 0;
		.box{
			width: 750rpx;
			height: 100%;
			background: #F4F5F7;
			padding-bottom: 200rpx;
			.list{
				width: 680rpx;
				padding: 20rpx 40rpx;
				box-sizing: border-box;
				background-color: #fff;
				margin: auto;
				margin-top: 30rpx;
				border-radius: 24rpx;
				padding-bottom: 40rpx !important;
				.list_val{
					display: flex;
					margin-top: 20rpx;
					.wz{
						font-size: 28rpx;
						color: #3D3D3D;
						width: 120rpx;
						margin-right: 30rpx;
					}
					.gl{
						width: 500rpx;
						font-size: 28rpx;
						color: #808080;
						flex-wrap: wrap;
					}
				}
			}
			.nav{
				width: 750rpx;
				height: 180rpx;
				background: #FFFFFF;
				padding: 32rpx 36rpx;
				box-sizing: border-box;
				.top{
					.yc{
						width: 178rpx;
						height: 68rpx;
						background: #1DBE7B;
						border-radius: 20rpx;
						color: #FFFFFF;
						line-height: 68rpx;
						text-align: center;
						margin-left: 28rpx;
					}
					display: flex;
					justify-content: space-between;
					/deep/ .u-content{
						border: 1px solid #ccc;
						border-radius: 50rpx 0 0 50rpx  !important;
					}
					/deep/ .u-action{
						border-radius:  0 50rpx 50rpx 0   !important;
						width: 112rpx;
						height: 65rpx;
						line-height: 65rpx;
						border: 2rpx solid #ccc;
						margin-left: 0;
						color: #3D3D3D;
						background-color: #f2f2f2;
					}
				}
				.tab{
					/deep/ .u-tab-item{
						font-size: 24rpx !important;
						color: #3D3D3D;
					}
				}
			}
		}
	}
</style>