<template>
	<view class="list">
		<view class="search"><u-search placeholder="输入姓名按回车搜索" :animation="true" v-model="param.name" @search="search()"></u-search></view>
		<view class="item" v-for="(item, index) in list" :key="index" @click="select(item)">
			<view class="icon select check" v-if="item.check">&#xe600;</view>
			<view class="icon select" v-else>&#xe8bb;</view>
			<view class="title">{{ item.name }}</view>

			<view class="icon more">&#xe631;</view>
			<view class="clear"></view>
		</view>
		<view class="footer">
			<button class="btn ws" @click="back">确定（{{ selects.length }}）</button>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			list: [],
			selects: {}, //选中
			id: '',
			flowId:'',
			nodeId:'',
			selectId:'',
			param: {
				
			}
		};
	},
	onLoad(e) {
		
		this.param=JSON.parse(e.item);
		console.log('this.param' + JSON.stringify(this.param));
		this.flowId=this.param.flowId;
		this.nodeId=this.param.nodeid;
		this.id=this.param.document.id;
		this.getData();
	},
	methods: {
		getData() {
			
			this.http.request({
				url:  this.http.urls.documents + this.id+'/workflows/'+ this.flowId+'/selectApprovers?nodeId='+ this.nodeId+'&type=3&selectId='+ this.selectId,
				//data: this.param,
				method: 'GET',
				success: res => {
					console.log('res.data.data.page===' + JSON.stringify(res));
					res.data.data.datas.forEach(item => {
						this.list.push(item);
					});
				}
			});
		},
		//搜索
		search() {
			//console.log("asd:"+this.param.keyword);
			//this.param.name=this.param.keyword;
			this.list=[];
			this.selectId=this.param.name;
			this.getData();
		},
		//选择
		select(item) {
			item.check = !item.check;
			
			console.log('this.item===' + JSON.stringify(item));
			//this.selects = item;
			//uni.$emit('select', this.selects);
			//uni.navigateBack();
			//this.selects = this.list.filter(item => item.check);
			
			
			item.nodeId=this.nodeId;
			//console.log("this.item==="+JSON.stringify(item));
			this.selects = this.list.filter(item => item.check);
		},
		//选中并返回
		back() {
			uni.$emit('selectu', this.selects);
			uni.navigateBack();
		}
	}
};
</script>

<style lang="scss">
.list {
	padding: 10px;
	.item {
		padding: 13px;
		background-color: white;
		border-bottom: 1px solid #efecec;
		.select {
			float: left;
			padding-right: 7px;
			margin-top: 1px;
			font-size: 20px;
		}
		.check {
			color: #4581fb;
		}
		.more {
			float: right;
			margin-top: -18px;
			color: darkgray;
		}
	}
}
</style>
