<template>
	<view >
		<view class="list_search card_banner flex">
			<uni-data-select class="list_search_select" v-model="searchForm.sendingAgency" :localdata="range"
				placeholder="发文部门"></uni-data-select>
			<uni-datetime-picker class="list_search_date" v-model="searchForm.createTime" type="daterange" />
			<u-icon class="list_search_icon" name="search" color="#fff" size="28" @click="doSearch"></u-icon>
		</view>
		<view class="list_content">
			<u-cell-group>
				<u-cell v-for="item in dataList" @click="toInfo(item)">
					<view slot="title">
						<view class="text-bold text-black">
							<view class="ellipsis-description">
								{{item.contentSummary}}
							</view>
							
						</view>
					</view>
					<view slot="value">
						
						<view class="text-grey text-sm list_label margin-top">
							{{item.createTime}} 
						</view>
						<view >
							<u-tag v-if="type==5" :text="item.state==1?'待办':item.state == 3?'归档':'已办'" plain  :type="item.state==1?'warning':item.state == 3?'primary':'success'">
							</u-tag>
						</view>
					</view>
					<view slot="label">
						<view class="text-grey  margin-top">
							{{item.sendingAgency}}
						</view>
					</view>
				</u-cell>
			</u-cell-group>
		</view>
		<u-loadmore :status="status" />
	</view>
</template>

<script>
	import gwCirculationCard2Service from '@/api/circulation/gwCirculationCard2.js'
	import gwFlowService from '@/api/circulation/gwFlowService.js'
	import * as $auth from "@/common/auth.js"
	export default {
		onLoad(option) {
			if (option) {
				this.type = option.type
				switch (option.type) {
					case "1":
						uni.setNavigationBarTitle({
							title: '待办列表' // 设置为你想要显示的标题文本
						});
						break;
					case "3":
						uni.setNavigationBarTitle({
							title: '归档列表' // 设置为你想要显示的标题文本
						});
						break;
					case "4":
						uni.setNavigationBarTitle({
							title: '已办列表' // 设置为你想要显示的标题文本
						});
						break;
					case "5":
						uni.setNavigationBarTitle({
							title: '公文列表' // 设置为你想要显示的标题文本
						});
						break;
				}
				this.searchForm.state = option.type
				this.loadmore()
			}
		},
		onShow() {
			uni.$on('refresh',(data)=>{
				this.dataList=[]
				this.searchForm.state = data.type
				this.tablePage.currentPage = 0
				this.status = 'loading';
				this.loadmore()
			})
			
		},
		onUnload() {
			uni.$off('refresh');
		},
		data() {
			return {
				status: 'loadmore',
				type: "",
				time: "",
				value: "",
				range: [],
				dataList: [],
				searchForm: {
					yearNum: '',
					cardNum: '',
					sendingAgency: '',
					docFontSize: '',
					fileSource: '',
					writtenTime: '',
					receivingTime: '',
					contentSummary: '',
					state: '',
					createTime: ""
				},
				tablePage: {
					pages: 0,
					currentPage: 0,
					pageSize: 10,
					orders: [{
						column: "a.create_time",
						asc: false
					}],
				},
				loading: false,
			}
		},
		methods: {
			// 查看详情
			toInfo(item) {
				if (this.type == 3 || this.type == 5 || this.type == 4) {
					uni.navigateTo({
						url: '/pages/fileTransmit/fileInfo?id=' + item.id
					})
				} else {
						uni.navigateTo({
							url: '/pages/fileTransmit/examineFile?id=' + item.id
						})
					// let user = $auth.getUserInfo()
					// let role = $auth.getUserInfo().roleNames
					// if (role == '办公室主任') {
					// 	uni.navigateTo({
					// 		url: '/pages/fileTransmit/examineFile?id=' + item.id
					// 	})
					// } else {
					// 	gwFlowService.queryByGwId(item.id).then(data => {
					// 		let gw = data.filter(item => {
					// 			return item.nextUser == user.id && item.state == 1
					// 		})
					// 		if (gw.length > 0) {
					// 			uni.navigateTo({
					// 				url: '/pages/fileTransmit/examineFile?id=' + item.id
					// 			})
					// 		} else {
								
					// 		}

					// 	})
					// }


				}
			},
			// 搜索
			doSearch() {
				console.log("search=============", this.searchForm);
				this.dataList = [];
				this.tablePage.currentPage = 0;
				this.tablePage.pageSize = 10;
				this.tablePage.pages = 0;
				this.loadmore()
			},
			onReachBottom() {
				this.loadmore()
			},
			loadmore() {
				if (this.tablePage.currentPage !== 0 && this.tablePage.pages <= this.tablePage.currentPage) {
					this.status = 'nomore';
					return;
				}
				this.tablePage.currentPage = ++this.tablePage.currentPage;
				//联网加载数据
				this.status = 'loading';
				let {
					createTime,
					...newForm
				} = this.searchForm
				gwCirculationCard2Service.list({
					current: this.tablePage.currentPage,
					size: this.tablePage.pageSize,
					orders: this.tablePage.orders,
					beginCreateDate: this.searchForm.createTime ? this.searchForm.createTime[0] : '',
					endCreateDate: this.searchForm.createTime ? this.searchForm.createTime[1] : '',
					...newForm
				}).then((data) => {
					//追加新数据
					this.dataList = this.dataList.concat(data.records);
					let places = []
					this.dataList.forEach(item => {
						places.push({
							text: item.sendingAgency,
							value: item.sendingAgency
						})
					});
					this.range = places.filter((item) => !places.includes(item.value) && places.push(item.value))

					this.tablePage.pages = data.pages;
					if (this.tablePage.pages <= this.tablePage.currentPage) {
						this.status = 'nomore'
					} else {
						this.status = 'loadmore'
					}
				})

			}
		}

	}
</script>

<style>
	.card_banner {
		width: 100%;
		height: 60px;
		background-color: #36a7f3;
	}
	.ellipsis-description {
		font-size: 20px;
	}
	.u-transition {
		align-items: flex-end;
	}
	.list_search_icon {
		line-height: 60px;
	}

	.list_search_select {
		width: 200px;
		background-color: #fff;
		height: 30px;
		border-radius: 10px;
		margin: 15px 5px 0;
	}

	.list_search_date {
		margin: 8px 5px 0;
	}

	.t-c {
		height: 34px;
		line-height: 34px;
	}

	.list_content {
		background-color: #fff;
	}

	.list_label {
		margin-top: 33px;
	}
</style>