<template>
	<view>
		<uni-nav-bar fixed="true" statusBar="true" left-icon="back" title="转派" @clickLeft="back">
			<template slot="right">
				<text class="btn-right" @click="submitReassign">确定</text>
			</template>
		</uni-nav-bar>
		<TurnSendInfo :list="list" @inputChange="changeUserData" @radioChange="getUserData"></TurnSendInfo>
	</view>
</template>
<script>
	import TurnSendInfo from '@/components/TurnSendInfo.vue'
	import {
		postJ
	} from "@/utils/api.js"
	let [page, size, isEnd] = [1, 20, true];
	export default {
		components:{
			TurnSendInfo
		},
		data() {
			return {
				pageId:'',
				executorId:'',
				executorName:'',
				list:[],
				searchForm: {deptCode:''} //筛选条件
			}
		},
		onLoad(option) {
			console.log(option)
			this.searchForm.deptCode = option.code;
			this.getList();
		},
		onReachBottom: function() {
			if (isEnd) {
				return;
			}
			// 显示加载图标
			// uni.showLoading({
			// 	title: "数据加载中"
			// });
			// this.getMoreLists();
		},
		methods: {
			//获取第一次数据
			getFirstList: function() {
				page = 1;
				isEnd = true;
				uni.showLoading({
					title: "数据加载中"
				});
				this.getList();
			},
			getMoreLists: function() {
				//获取更多数据
				page++;
				this.getList();
			},
			//获取列表数据
			getList() {
				postJ(this.apiUrl + "/main/user/users", this.searchForm).then(res => {
					this.list = res.data;
					// let pageTotal = res.data.pageTotal;
					// if (page === 1) {
					// 	data.forEach(el => {
					// 		el.num = 0
					// 	})
					// 	this.list = data;
					// } else {
					// 	data.forEach(element => {
					// 		element.num = 0;
					// 		this.list.push(element);
					// 	});
					// }
					// page < pageTotal ? (isEnd = false) : (isEnd = true);
				}).then(() => {
					uni.hideLoading()
				})
			},
			//筛选-重新获取数据
			changeUserData(data){
				this.searchForm = {
					name: data.name || ''
				};
				this.getFirstList();
			},
			//获取选中信息
			getUserData(data){
				this.executorId = data.executorId;
				this.executorName = data.executorName;
			},
			//确定
			submitReassign(){
				if(!this.executorId){
					uni.showToast({
						title:'请选择转派人员',
						icon:'none'
					})
					return
				}
				let data = {
					executorId: this.executorId, 
					executorName: this.executorName
				}
				this.$store.dispatch("tour_tally/setExecutor", data);
				this.back()
			},
			
		}
	}
</script>

<style scoped lang="scss">
	
</style>
