<template>
	<view class="page">
		<view class="mybox" v-if="listCards.length>0">
			<view v-for="(item,index) in listCards" :key="index" class="people-box myContainer myContentBox"  @click="selectPeople(item,index)">
				<view class="name_">{{item.NAME}}</view>
				<view class="user_container">
					 <img src="../../static/img/user2.png">
					 <view class="username">{{item.deptName}}</view>
				</view>
				<view class="user_container">
					 <img src="../../static/img/phone.png">
					 <view class="username">{{item.mobile}}</view>
				</view>
			</view>
			<uni-load-more  :status="loading_status"></uni-load-more>
		</view>
		<view class="mybox" v-else>
			<xinsoft-no-record noRecordContent="暂无满足条件的内容,请输入关键字重新搜索" ></xinsoft-no-record>
		</view>
		<view class="goHome" @click='goMain("taskInfo")'>
			<img src="../../static/img/gohome.png">
		</view>
	</view>
</template>

<script>
	import uniIcons from '@/components/uni-icons/uni-icons.vue'
	import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
	import xinsoftNoRecord from '@/components/xinsoft-no-record/xinsoft-no-record.vue';
	export default {
		components: {
			uniIcons,
			uniLoadMore,xinsoftNoRecord
		},
		data() {
			return {
				id:'',
				search_text:'',
				listCards: [],
				pagenumber:1,//当前第几页
				pagesize:20,//每页加载数据条数
				loading_status: 'more',//more（loading前）、loading（loading中）、noMore（没有更多了）
				flag:'',
				id:''
			}
		},
		onLoad(option) {
			this.flag = option.flag;
			this.id = option.id;
		},
		created() {
			this.getDateList();
		
		},
		//滚动到底部加载下一页
		onReachBottom(obj){
			if(this.loading_status=='noMore'){
				return false;
			}
			this.pagenumber++;
			this.getDateList();
		},
		//下拉刷新
		onPullDownRefresh(){
			this.listCards=[];
			this.pagenumber=1;
			this.loading_status="more";
			this.getDateList();
			  
		},
		methods: {
			//获取列表数据
			getDateList(){
				this.loading_status="loading";
				var filterRes = {};
				filterRes.pageno = this.pagenumber;
				filterRes.pagesize = this.pagesize;
				filterRes.query=this.search_text;
				this.$http.request({
					url: '/apis/user/list',
					params: filterRes,
					method:"GET"
				}).then(res => {
					uni.stopPullDownRefresh();
					if(!res.data.data){
					this.loading_status="noMore";
					}else if(res.data.data.datas.length<this.pagesize){
						this.loading_status="noMore";
					}else{
						this.loading_status="more";
					}
					
					if (res.data.code == 0) {
						this.listCards = this.listCards.concat(res.data.data.datas);
					}
				}).catch(err => {
					this.loading_status="noMore";
				});
			},			
			//点击搜索 实现效果  这里需要根据情况判断。处理方式和前面差不多。
			selectPeople(item,index){
				if(this.flag == 'zrr'){  //zrrr
					var arrays =  {
							userId :item.userId,
							name:item.NAME
						};
					var taskInfo =  uni.getStorageSync('taskInfo');
					if(!taskInfo){
						taskInfo = {}
					}
					taskInfo.zrr = arrays;
					uni.setStorage({
						key: 'taskInfo',
						data: taskInfo,
						success: function () {
							uni.navigateTo({
							    url: 'addTask'
							});
						}
					});
					
				}
				else if(this.flag == 'csr'){  //抄送人
					var arrays =  [{
							userId :item.userId,
							name:item.NAME
					}];
					var taskInfo =  uni.getStorageSync('taskInfo');
					if(!taskInfo){
						taskInfo = {}
					}
					taskInfo.targetList = arrays;
					uni.setStorage({
						key: 'taskInfo',
						data: taskInfo,
						success: function () {
							uni.navigateTo({
							    url: 'addTask'
							});
						}
					});
				}
				else if(this.flag == 'msgcsr'){  //回复信息里面的抄送人
					var arrays =  [{
							userId :item.userId,
							name:item.NAME
					}];
					var msgInfo =  uni.getStorageSync('msgInfo');
					if(!msgInfo){
						msgInfo = {}
					}
					msgInfo.targetList = arrays;
					uni.setStorage({
						key: 'msgInfo',
						data: msgInfo,
						success: function () {
							uni.navigateTo({
								url: 'sendMsg'
							});
						}
					});
				}else if(this.flag == 'zp'){
					var _this = this;
					var arrays = {
							userId :item.userId,
							name:item.NAME
					};
					//调用指派接口
					this.$http.request({
						url: '/apis/taskMain/reventTurnToSend',
						params: {
							taskId:_this.id,
							userId:arrays.userId
						}
					}).then(res => {
						if (res.data.code == 0) {
							uni.showToast({
							    title: res.data.msg,
							    duration: 2000,
								icon:"none"
							});
							setTimeout( function(){
								uni.redirectTo({
								    url: 'taskDetail?id='+_this.id
								});
							},1000)
						}
						else{
							uni.showToast({
								title: res.data.msg,
								duration: 1000,
								icon:"none"
							});
						}
					}).catch(err => {
						uni.showToast({
							title: '操作失败',
							duration: 1000,
							icon:"none"
						});
					});
				}
			}
		},
		onPageScroll : function(e) {  
			uni.hideKeyboard()
		},
		//搜索框文本变化
		onNavigationBarSearchInputChanged(n){
			this.search_text=n.text;
		},
		//点击软键盘搜索按钮
		onNavigationBarSearchInputConfirmed(){
			this.listCards=[];
			this.pagenumber=1;
			this.loading_status="more";
			this.getDateList();
		},
		//点击搜索按钮
		onNavigationBarButtonTap(obj) {
			this.listCards=[];
			this.pagenumber=1;
			this.loading_status="more";
			this.getDateList();
		}
	}
</script>

<style scoped>
	>>>.noRecord{
		padding-top: 30%;
		margin-top: 0 !important;
	}
</style>
