<template>
	<view class="archive">
		<u-navbar ref="uNavbar" :border-bottom="false" :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="{active: active == 0}" @click="setNavs(0)">发文</view>
			</view>
			<view class="item">
				<view class="text" :class="{active: active == 1}" @click="setNavs(1)">收文</view>
			</view>
		</view>
		<view class="searchBox">
			<view class="inputBox">
				<u-input class="input" v-model="searchVal" type="text" height="70" placeholder="请输入标题" placeholderStyle="{'color:#AAAAAA'}" />
				<view class="btn" @click="search">查询</view>
			</view>
			<view class="timeBox" @click="showTime = true">
				<image class="r" src="/static/img/icon_xzrq.png" mode=""></image>
				<view class="text">{{message_time || '选择日期'}}</view>
				<image class="d" src="/static/img/icon_xzrq_xl.png" mode=""></image>
			</view>
		</view>
		<view class="contentMain" v-if="list.length">
			<view 
				v-for="(item, index) in list" 
				:key="item.id" 
				class="u-swipe-action "
					>
				<view class="item">
					<view class="title">{{item.message_title}}</view>
					<view class="userInfo">
						<view class="user">
							<view class="name">拟稿人：{{item.send_user_name}}</view>
							<view class="name">发文日期：{{item.message_time}}</view>
							<view class="name">流程结束日期：{{item.finish_time}}</view>
						</view>
						<view class="status">{{item.status}}</view>
					</view>
				</view>
			</view>
		</view>
		<view class="no-data" v-else>暂无数据</view>
		<u-picker mode="time" v-model="showTime" :params="params" @confirm="getTime"></u-picker>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				setNav:{
					backgroundColor:'#fff',  //背景色
					color:'#333',  //字体颜色
					bold: true,
					size: '36',
					backColor: '#333',
					isdisPlayNavTitle: true, //是否显示返回按钮
					navTitle:'已归档' //导航标题
				},
				showTime: false,
				searchVal: '',
				topNav: 0,
				list: [],
				disabled: false,
				btnWidth: 180,
				show: false,
				userInfo: {},
				pageNo: 1,
				active: 0,
				message_time: '',
				options: [
					{
						text: '归档',
						style: {
							backgroundColor: '#00B034'
						}
					}
				],
				params: {
					year: true,
					month: true,
					day: true
				},
				total: 0
			}
		},
		onReachBottom() {
			if (this.list.length >= this.total) {
				return
			}
			this.pageNo += 1
			this.getQueryList()
		},
		onLoad() {
			this.userInfo = JSON.parse(uni.getStorageSync('userInfo') || '{}');
			this.getQueryList()
			setTimeout(() => {
				this.topNav = (this.$refs.uNavbar.navbarHeight) + (this.$refs.uNavbar.statusBarHeight)
			}, 10)
		},
		methods:{
			search () {
					this.pageNo = 1
					this.getQueryList()
			},
			async getQueryList() {
				let res = await this.$u.post(`boman-web-core/p/cs/queryList`, {
					"table": "boman_message",
					"pageNo": this.pageNo,
					"isUi": false,
					"pageSize": 10,
					"orderBy": "create_time desc",
					"fixedData": {
						"condition": {
							"place_on_file": 2,
							"send_user_id": this.userInfo.id,
							"message_title": this.searchVal,
							"create_time": this.message_time,
							"is_del":"N"
						}
					}
				})
				if (res.data && res.data.rows) {
					res.data.rows = res.data.rows.map(item => {
						return Object.assign({}, item, {
							show: false
						})
					})
					if (this.pageNo == 1) {
						this.list = res.data.rows
					} else {
						this.list = this.list.concat(res.data.rows)
					}
				}
			},
			getTime(e) {
				// console.log(e);
				this.message_time = `${e.year}-${e.month}-${e.day}`
				this.pageNo = 1
				this.getQueryList()
			},
			async click(index, index1) {
				let res = await this.$u.get('boman-web-core/p/cs/objectSave', {
					"table": "boman_message",
					    "objId": this.data[index].id,
					    "fixedData": {
					        "place_on_file": "2"
					    }
				})
				if (res.code == 200) {
					uni.showToast({
						title: res.msg
					})
					this.pageNo = 1
					this.getQueryList()
				} else {
					uni.showToast({
						title: res.msg,
						icon: 'none'
					})
				}
			},
			// 如果打开一个的时候，不需要关闭其他，则无需实现本方法
			open(index) {
				// 先将正在被操作的swipeAction标记为打开状态，否则由于props的特性限制，
				// 原本为'false'，再次设置为'false'会无效
				this.list[index].show = true;
				this.list.map((val, idx) => {
					if(index != idx) this.list[idx].show = false;
				})
			},
			setNavs (active) {
				this.active = active
				this.pageNo = 1
				if (active == 0) {
					this.getQueryList()
				} else {
					this.list = []
				}
			}
		}
	}
</script>
<style>
	page{
		background: #FFFFFF;
	}
</style>
<style lang="scss" scoped>
.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);
			}
		}
	}
}
.searchBox{
	padding: 30rpx;
	.inputBox{
		display: flex;
		align-items: center;
		.input{
			flex: 1;
			width: 100%;
			margin-right: 30rpx;
			background: #EDEDED;
			border-radius: 40rpx;
			padding: 0 30rpx !important;
		}
		.btn{
			background: #009FE8;
			color: #FFFFFF;
			font-size: 26rpx;
			height: 60rpx;
			line-height: 60rpx;
			padding: 0 30rpx;
			text-align: center;
			border-radius: 40rpx;
		}
	}
	
}
.timeBox{
	padding: 30rpx 0 20rpx 0;
	display: flex;
	align-items: center;
	.r{
		width: 30rpx;
		height: 33rpx;
	}
	.text{
		font-size: 26rpx;
		color: #343434;
		margin: 0 14rpx;
	}
	.d{
		width: 20rpx;
		height: 20rpx;
	}
}
.contentMain{
	.item{
		.title{
			font-size: 28rpx;
			font-weight: 700;
			color: #343434;
			padding: 30rpx 30rpx 0 30rpx;
			white-space: break-word;
			word-break:break-all;
		}
		.userInfo{
			display: flex;
			align-items: flex-end;
			border-bottom: solid 1rpx #DADADA;
			padding: 30rpx;
			.user{
				flex: 1;
				color: #666;
				font-size: 24rpx;
				.name{
					margin-bottom: 10rpx;
				}
			}
			.status{
				color: #AAAAAA;
				font-size: 26rpx;
				margin-bottom: 4rpx;
			}
		}
	}
}
</style>
