<template>
	<view class="view">
		<u-search :show-action="false" v-model="curWord" @change="inputWord" margin="20rpx 50rpx"></u-search>
		
		<u-cell-group customStyle="padding: 20px">
			<u-cell
			    title="收件箱"
				icon="email"
			    isLink
				:iconStyle="{color: '#fbbd08'}"
				:value="`${noReadCount}/${mailBoxCount}`"
			    url="/pages/apps/mail/inbox"
			></u-cell>
			<u-cell
			    title="已发送"
				icon="tags"
			    isLink
				:iconStyle="{color: '#39b54a'}"
				:value="`${mailComposeCount}`"
			    url="/pages/apps/mail/outbox"
			></u-cell>
			<u-cell
			    title="草稿箱"
				icon="edit-pen"
			    isLink
				:iconStyle="{color: '#8799a3'}"
				:value="`${mailDraftCount}`"
			    url="/pages/apps/mail/draft"
			></u-cell>
			<u-cell
			    title="已删除"
				icon="trash"
			    isLink
				:iconStyle="{color: '#e54d42'}"
				:value="`${mailTrashCount}`"
			    url="/pages/apps/mail/trash"
			></u-cell>
		</u-cell-group>
			<uni-fab
				horizontal="right"
				vertical="bottom"
				@fabClick="toAdd"
			></uni-fab>
	</view>
</template>

<script>
	import mailBoxService from "@/api/mail/mailBoxService";	
	export default {
		data() {
			return {
				curWord:'',
				mailBoxCount: '',
				mailComposeCount: '',
				mailDraftCount: '',
				mailTrashCount: '',
				noReadCount: ''
			}
		},
		async onShow() {
		  let data = await mailBoxService.queryStatus();
		  this.mailBoxCount = data.mailBoxCount
		  this.mailComposeCount = data.mailComposeCount
		  this.mailDraftCount = data.mailDraftCount
		  this.noReadCount = data.noReadCount
		  this.mailTrashCount = data.mailTrashCount
		},
		methods: {
			// 输入监听
			inputWord(e){
				// this.curWord = e.detail.value // 已使用v-model,无需再次赋值
				// 节流,避免输入过快多次请求
				this.searchTimer && clearTimeout(this.searchTimer)
				this.searchTimer = setTimeout(()=>{
			
				},300)
			},
			toAdd (){
				uni.navigateTo({
				  url: '/pages/apps/mail/sendEmailForm'
				})
			},
			toInbox (){
				uni.navigateTo({
				    url: '/pages/apps/mail/inbox'
				});
			},
			toDraft () {
				uni.navigateTo({
				    url: '/pages/apps/mail/draft'
				});
			},
			toOutbox () {
				uni.navigateTo({
				    url: '/pages/apps/mail/outbox'
				});
			},
			toTrash () {
				uni.navigateTo({
				    url: '/pages/apps/mail/trash'
				});
			}
		}
	}
</script>
