<template>
	<view>
		<view style="padding: 20rpx;background-color: #fff;">
			<u-search v-model="model.mainTitle" placeholder="请输入邮件标题" :showAction="true" actionText="搜索"
				:animation="true" @custom="search" @clear="search">

			</u-search>
		</view>
		<view style="background-color: #fff;">
			<u-cell-group>
				<u-cell v-for="(v,i) in list" :key="v.mailId" :title="v.mainTitle" :titleStyle="{fontSize:'30rpx'}"
					:value="showtime($u.timeFormat(v.sendTime, 'yyyy-mm-dd'))" @click="emailInfo(v.mailId,i)">
				</u-cell>
			</u-cell-group>
		</view>
		
		<view style="padding: 20rpx;" v-show="status != 'loadmore'">
			<u-loadmore :status="status" fontSize="28rpx" />
		</view>
	</view>
</template>

<script>
	import {showtime} from "@/utils/wjw.js"
	export default {
		data() {
			return {
				model: {
					pageNum: 1,
					pageSize: 20,
					mainTitle: null
				},
				total: 0,
				//加载状态
				status: 'loadmore',
				//邮件列表
				list: [],
				//搜索
				keyword: null,
				showtime:showtime,
			}
		},
		onLoad() {
			let that = this
			this.getList()
		},
		onShow() {
			
		},
		onPullDownRefresh() {
			this.model.pageNum = 1
			this.list = []
			this.getList()
		},
		onReachBottom() {
			if (this.model.pageNum == this.total) {
				this.status = 'nomore'
			} else {
				this.model.pageNum++
				this.getList()
			}
		},
		methods: {
			//查询邮件列表
			getList() {
				let that = this
				uni.$u.http.get('/oa/mail/yfList', {
					params: that.model
				}).then(res => {
					uni.hideLoading()
					that.list = [...that.list, ...res.rows]
					if (res.total < this.model.pageSize) {
						that.status = "nomore"
					} else {
						that.status = "loadmore"
					}
					if (that.model.pageNum === 1) {
						that.total = Math.ceil(res.total / that.model.pageSize)
						uni.stopPullDownRefresh()
					}
				})
			},
			//查看邮件详细信息
			emailInfo(id, i) {
				if (this.list[i].isRead == 'N') {
					this.list[i].isRead = 'Y'
				}
				uni.navigateTo({
					url: "/pages/emailInfo/emailInfo?id=" + id+'&type=2'
				})
			},
			//根据标题搜索邮件内容
			search() {
				uni.showLoading({
					title: "搜索中...",
					mask: true
				})
				this.pageNum = 1
				this.list = []
				this.getList()
			}
		}
	}
</script>

<style>

</style>