<template>
	<view class="cleared-details-container">
		<scroll-view class="scroll-con" scroll-y :scroll-top="scrollTop" @scrolltolower="onreachBottom">
			<!-- 列表数据 -->
			<view class="cell-item-con">
				<view class="cell-item" v-for="(item, index) in listdata" :key="index">
					<view class="cell-item-c">
						<u-image class="cell-item-pic" src="/static/md-big-pic.png" width="100rpx" height="100rpx"></u-image>
						<view class="cell-item-info">
							<view class="cell-item-info-network">{{item.stationName || '--'}}</view>
							<view class="cell-item-info-weight">清运总重量：<text>{{ (item.totalWeight/1000).toFixed(2) }}kg</text></view>
						</view>
					</view>
					<u-grid :col="3" :hover-class="none">
						<u-grid-item>
							<view class="cell-item-main">
								<text class="cell-item-number blue">{{ (item.clothes/1000).toFixed(2) }}</text>
								<text class="cell-item-unit">kg</text>
							</view>
							<view class="cell-item-exp">废旧衣物</view>
						</u-grid-item>
						<u-grid-item>
							<view class="cell-item-main">
								<text class="cell-item-number green">{{ (item.paper/1000).toFixed(2) }}</text>
								<text class="cell-item-unit">kg</text>
							</view>
							<view class="cell-item-exp">废旧纸张</view>
						</u-grid-item>
						<u-grid-item>
							<view class="cell-item-main">
								<text class="cell-item-number red">{{ (item.plastic/1000).toFixed(2) }}</text>
								<text class="cell-item-unit">kg</text>
							</view>
							<view class="cell-item-exp">废旧塑料</view>
						</u-grid-item>
						<u-grid-item>
							<view class="cell-item-main">
								<text class="cell-item-number yellow">{{ (item.metal/1000).toFixed(2) }}</text>
								<text class="cell-item-unit">kg</text>
							</view>
							<view class="cell-item-exp">废旧金属</view>
						</u-grid-item>
						<u-grid-item>
							<view class="cell-item-main">
								<text class="cell-item-number yellow">{{ (item.plaMet/1000).toFixed(2) }}</text>
								<text class="cell-item-unit">kg</text>
							</view>
							<view class="cell-item-exp">废旧金属/塑料</view>
						</u-grid-item>
						<u-grid-item>
							<view class="cell-item-main">
								<text class="cell-item-number yellow">{{ (item.glass/1000).toFixed(2) }}</text>
								<text class="cell-item-unit">kg</text>
							</view>
							<view class="cell-item-exp">废旧玻璃</view>
						</u-grid-item>
						<u-grid-item>
							<view class="cell-item-main">
								<text class="cell-item-number yellow">{{ (item.recycling/1000).toFixed(2) }}</text>
								<text class="cell-item-unit">kg</text>
							</view>
							<view class="cell-item-exp">可回收物</view>
						</u-grid-item>
					</u-grid>
				</view>
			</view>
			<u-empty class="nodata" :text="noDataText" v-if="listdata.length==0 && status!='loading'" mode="list"></u-empty>
			<view class="loadmore" v-if="listdata.length!=0">
				<u-loadmore v-if="total>pageSize || status=='loading'" :status="status" />
			</view>
		</scroll-view>
	</view>
</template>

<script>
	import { getAlreadyCleanDetails } from '@/api/cleared.js'
	export default{
		data(){
			return{
				listdata: [],
				pageNo: 1,  //  当前页码
				pageSize: 10,  //  每页条数
				total: 0,  //  数据总条数
				noDataText: '暂无数据',  //  列表请求状态提示语
				status: 'loadmore',  //  加载中状态
				scrollTop: 0,  //  滚动条位置
				createDate: ''  //  时间
			}
		},
		onLoad(options) {
			this.createDate = options.createDate
		},
		onShow() {
			this.refresh()
		},
		methods: {
			// 获取查询参数 刷新列表
			refresh(){
				this.listdata = []
				this.total = 0
				this.searchHandle(1)
			},
			// 搜索查询
			searchHandle (pageNo) {
				uni.showLoading({
					mask: true,
				    title: '加载中'
				})
				this.status = "loading"
				pageNo ? this.pageNo = pageNo : null
				getAlreadyCleanDetails({
					pageNo: this.pageNo,
					pageSize: this.pageSize,
					createDate: this.createDate
				}).then(res => {
					uni.hideLoading()
					if (res.status == 200) {
						if(this.pageNo>1){
							this.listdata = this.listdata.concat(res.data.list || [])
						}else{
							this.listdata = res.data.list || []
							this.scrollTop = 0
						}
						this.total = res.data.count || 0
						this.noDataText = '暂无数据'
					} else {
						this.noDataText = res.message
						this.listdata = []
						this.total = 0
					}
					this.status = "loadmore"
				})
			},
			// scroll-view到底部加载更多
			onreachBottom() {
				if(this.listdata.length!=0 && this.listdata.length < this.total){
					this.pageNo++
					this.searchHandle()
				}else{
					uni.showToast({ title: '已经到底了', icon: 'none' })
					this.status = "nomore"
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.cleared-details-container{
		width: 100%;
		//  列表
		.scroll-con{
			overflow: auto;
			height: 100vh;
		}
		.cell-item-con{
			.cell-item{
				margin: $uni-spacing-col-base $uni-spacing-row-base;
				background-color: #fff;
				border-radius: $uni-border-radius-base;
				color: $uni-text-color;
				font-size: $uni-font-size-base;
				box-shadow: 3rpx 3rpx 5rpx #eee;
				.cell-item-c{
					display: flex;
					align-items: center;
					padding: $uni-spacing-col-base $uni-spacing-row-base;
					.cell-item-pic{
						flex-shrink: 0;
						margin-right: 20rpx;
					}
					.cell-item-info{
						flex-grow: 1;
						.cell-item-info-network{
							word-break: break-all;
							margin-bottom: 10rpx;
						}
						.cell-item-info-weight{
							font-size: 26rpx;
							text{
								font-weight: bold;
							}
						}
					}
				}
				.cell-item-main{
					margin-bottom: 10rpx;
					.cell-item-number{
						margin-right: 5rpx;
					}
					.cell-item-unit{
						font-size: 26rpx;
					}
					.blue {
						color: #1890FF;
					}
					.green {
						color: #16b50e;
					}
					.red {
						color: red;
					}
					.yellow {
						color: #ff9900;
					}
				}
			}
		}
		.nodata{
			padding-top: 400rpx;
		}
	}
</style>
