<template>
	<view class="collector">
		<u-navbar ref="uNavbar" :border-bottom="false" :title-width="340" :back-icon-color="setNav.backColor" :is-back="setNav.isdisPlayNavTitle"
		 :title-size="setNav.size" :title-bold="setNav.bold" :title="setNav.navTitle" :title-color="setNav.color" :background="setNav"></u-navbar>
		<view class="topNav" :style="{top: topNav + 'px'}">
			<view class="item">
				<view class="text" :class="yidu == 0?'active':''" @click="onNav(0)">全部</view>
			</view>
			<view class="item">
				<view class="text" :class="yidu == 1?'active':''"  @click="onNav(1)">已读</view>
			</view>
			<view class="item">
				<view class="text" :class="yidu == 2?'active':''"  @click="onNav(2)">未读</view>
			</view>
		</view>
		<view class="title">
			已发文给 <text>{{totals}}人</text>；其中有 <text>{{read}}人</text> 已读； <text>{{notRead}}人</text> 未读
		</view>
		<view class="table">
			<view class="thead">
				<view class="tr">
					<view class="th">收文员</view>
					<view class="th">单位</view>
					<view class="th">发文时间</view>
					<view class="th">收文时间</view>
					<view class="th">状态</view>
				</view>
			</view>
			<view class="tbody" v-if="data.length">
				<view class="tr" v-for="(item, index) in data" :key="index">
					<view class="td">
						{{item.receive_user_name}}
					</view>
					<view class="td">
						{{item.receive_dept_name}}
					</view>
					<view class="td">
						{{item.send_message_time}}
					</view>
					<view class="td">
						{{item.receive_time == null ? '未结束' : item.receive_time}}
					</view>
					<view :class="[item.status != '未读' ? 'yes' : 'no', 'td']">
						{{item.status}}
					</view>
				</view>
			</view>
			<view class="no-data" v-else>暂无数据</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				checked: false,
				topNav: 0,
				yidu: 0,
				setNav: {
					backgroundColor: '#fff', //背景色
					color: '#333', //字体颜色
					bold: true,
					size: '36',
					backColor: '#333',
					isdisPlayNavTitle: true, //是否显示返回按钮
					navTitle: '查看进度' //导航标题
				},
				data: [],
				id: '',
				name: '',
				pageNo: 1,
				total: 0,
				"totals": 0,
				      "notRead": 0,
				      "read": 0
			}
		},
		onReachBottom() {
			if (this.data.length >= this.total) {
				return
			}
			this.pageNo += 1
			this.statistic()
		},
		onLoad(options) {
			this.id = options.id
			this.name = options.name
			this.statistic()
			this.init()
			setTimeout(() => {
				this.topNav = (this.$refs.uNavbar.navbarHeight) + (this.$refs.uNavbar.statusBarHeight)
			}, 10)
		},
		methods: {
			onNav(val) {
				this.yidu = val
				this.pageNo = 1
				this.statistic()
			},
			checkboxChange: function(e) {
				var items = this.data,
					values = e.detail.value;
				for (var i = 0, lenI = items.length; i < lenI; ++i) {
					const item = items[i]
					if (values.includes(item.value)) {
						this.$set(item, 'checked', true)
					} else {
						this.$set(item, 'checked', false)
					}
				}
			},
			async statistic() {
				// 
				let res = await this.$u.post('boman-web-core/p/cs/queryList', {
					 "table": "boman_message_receive",
					    "pageNo": this.pageNo,
					    "isUi": false,
					    "pageSize": 20,
					    "orderBy": "status desc",
					    "fixedData": {
					        "condition": {
					            "visible": "Y",
					            "message_id": this.id,
					            "status": this.yidu == 0 ? '' : this.yidu == 1 ? 'Y' : 'N',
					            "is_del":"N"
					        }
					    }
				})
				if (res.data && res.data.rows) {
					
					if (this.pageNo == 1) {
						this.data = res.data.rows
						this.total = res.data.total
					} else {
						this.data = this.data.concat(res.data.rows)
					}
				}
			},
			async init() {
				// 
				let res = await this.$u.get('boman-web-core/messageReceive/recieve/statistic/'+ this.id)
				if (res.code == 200) {
					
					this.totals =  res.data.total
					this.notRead =  res.data.notRead
					this.read =  res.data.read
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.collector {
		width: 100%;
		height: 100%;
		background: #fff;
		
		.topNav{
			display: flex;
			align-items: center;
			background: #FFFFFF;
			height: 90rpx;
			box-shadow: 0px 14rpx 10rpx 0px rgba(218, 218, 218, 0.35);
			position: sticky;
			width: 100%;
			left: 0;
			z-index: 9;
			.item{
				flex: 1;
				display: flex;
				align-items: center;
				justify-content: center;
				.text{
					font-size: 26rpx;
					color: #191919;
					font-weight: 600;
				}
				.active{
					position: relative;
					&::after{
						content: '';
						position: absolute;
						width: 28rpx;
						height: 6rpx;
						background: #009FE8;
						border-radius: 6rpx;
						bottom: -14rpx;
						left: 50%;
						transform: translate(-50%,0);
					}
				}
			}
		}
	
		/deep/ .u-navbar-inner {
			box-shadow: none;
		}

		.title {
			height: 56rpx;
			background: #FFFFFF;
			line-height: 56rpx;
			font-size: 24rpx;
			color: #343434;
			padding-left: 32rpx;
			margin-top: 30rpx;
			text {
				color: #FF3131;
				margin: 0 6rpx;
				&:nth-child(1) {
					color: #009FE8;
				}
				&:nth-child(2) {
					color: #54BA10;
				}
			}
		}

		.btns {
			position: fixed;
			bottom: 0;
			height: 84rpx;
			display: flex;
			width: 100%;
			border-top: 1px solid #E5E5E5;
			/deep/ .left {
				width: 190rpx;
				background: #FFFFFF;
				text-align: center;
				font-size: 28rpx;
				font-weight: 500;
				color: #343434;
				line-height: 84rpx;
				uni-checkbox {
					margin-right: 20rpx;
				}
			}
			.right {
				flex: 1;
				background: #009FE8;
				color: #fff;
				text-align: center;
				line-height: 84rpx;
			}
		}

		.table {
			.tr {
				display: flex;

				.th,
				.td {
					flex: 1;
					text-align: center;
					display: flex;
					justify-content: center;
					align-items: center;
					max-width: 20%;
				}

				.td {
					padding: 20rpx 0;
					font-size: 20rpx;
					color: #333333;
					border-bottom: 1px solid #E5E5E5;
				}
				.yes {
					color: #54BA10;
				}
				.no {
					color: #FF0000;
				}
			}

			.thead {
				padding: 33rpx 0;
				font-size: 24rpx;
				font-weight: bold;
				color: #333333;
			}
		}
		/deep/ .check-td,
		.check-th {
			max-width: 8%;
		
			.uni-checkbox-input {
				margin: 0 auto;
				width: 0rpx;
				height: 0rpx;
				padding: 12rpx;
		
				&.uni-checkbox-input-checked {
					background-color: #009FE8;
					border: 1px solid #009FE8;
				}
		
				&.uni-checkbox-input-checked:before {
					font-size: 20rpx;
				}
			}
		}
	
	}
</style>
