<template>
	<view id="warp">
		<view class="list" >
			<index-list 
				:list="indexList" 
				:multi="multi" 
				:selectList="selectList" 
				@change="change"
			>
			</index-list>
		</view>
		<view class="btn_css" @tap="nextHandle">确定</view>
	</view>
</template>

<script>
	import {IndexList} from '@/components/index-list/index-list.vue'
	const {urlList,https} = require('@/static/api');
	export default {
		components: {
			IndexList
		},
		data() {
			return {
				currentPage: 1,
				pageSize: 20,
				roleId: 0,
				urlType: '',
				indexList: [],
				multi: false,
				selectList: [],
			};
		},
		onLoad(options) {
			const that = this;
			this.selectList = JSON.parse(options.selectList)
			console.log(this.selectList)
			const type = options.type;
			that.urlType = type;
			let title = '请选择业务员'
			if (type == 'ywy') {
				title = '请选择业务员'
				that.multi = false
				this.roleId = 1006
				var key=""
				var	 url=urlList.getemployee+'?key='+key+'&status=1&currentPage='+this.currentPage+'&pageSize='+this.pageSize+'&roleId='+this.roleId
				https(url, 'GET', '', '').then(res => {
					console.log(1,res)
					console.log(this.selectList)
					this.indexList = res.data.employeeList
					console.log(this.indexList)
				}).catch(err => {
					console.log(err)
				})
			} else if (type == 'bdr') {
				title = '请选择工地联系人'
				that.multi = true;
				this.roleId = 1009
				var	 url=urlList.getemployee+'?key='+key+'&status=1&currentPage='+this.currentPage+'&pageSize='+this.pageSize+'&roleId='+this.roleId
				https(url, 'GET', '', '').then(res => {
					console.log(this.selectList)
					console.log(this.indexList)
					this.indexList = res.data.employeeList	
					console.log(this.indexList)
				}).catch(err => {
					console.log(err)
				})
			}else if(type == 'sgdw'){
				title = '请选择施工单位'
				that.multi = false;
				// this.roleId = 1009
				var	 url=urlList.get_construction+'?key='+key
				https(url, 'GET', '', '').then(res => {
					this.indexList = res.data.constructionLetterOutputs
				}).catch(err => {
					console.log(err)
				})
			}
			uni.setNavigationBarTitle({
				title
			});
		},
		methods: {
			change(data) {
				this.selectList = data
				console.log(data)
			},
			changeUser(item, index) {
				console.log(123)
				if (this.urlType == 'ywy') {
					if (this.indexList[index].is_choose) {
						this.selectList = []
						this.indexList[index].is_choose = !this.indexList[index].is_choose
					} else {
						this.selectList = [item]
						this.indexList[index].is_choose = !this.indexList[index].is_choose
					}

				} else if(this.urlType == 'bdr'){
					var is_have = -1
					this.selectList.forEach((item2, index) => {
						if (item.id == item2.id) {
							is_have = index
						}
					})
					if (is_have != -1) {
						this.selectList.splice(is_have, 1)
					} else {
						this.selectList.push(item)
					}
					this.indexList[index].is_choose = !this.indexList[index].is_choose
				}else if(this.urlType == 'sgdw'){
					if (this.indexList[index].is_choose) {
						this.selectList = []
						this.indexList[index].is_choose = !this.indexList[index].is_choose
					} else {
						this.selectList = [item]
						this.indexList[index].is_choose = !this.indexList[index].is_choose
					}
				}
				console.log(this.indexList)
			},
			nextHandle() {
				const that = this;
				var pages = getCurrentPages();
				var prevPage = pages[pages.length - 2]; //上一个页面
				if (that.urlType == 'ywy') {
					prevPage.$vm._data.gcInfo.ywy = that.selectList;
					// console.log(prevPage.$vm._data.gcInfo.ywy)
				} else if(this.urlType == 'bdr') {
					prevPage.$vm._data.gcInfo.baodan = that.selectList;
				}else if(this.urlType == 'sgdw'){
					prevPage.$vm._data.gcInfo.sgdw = that.selectList;
				}
				uni.navigateBack() //返回上一页面
			}
		}
	}
</script>

<style lang="scss" scoped>
	
	/* 隐藏滚动条 */
	::-webkit-scrollbar {
	  width: 0;
	  height: 0;
	  color: transparent;
	}
	#warp {
		width: 100%;
		height: 100vh;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		background-color: #fff;
		.top_indexList {
			width: 100%;
			height: calc(100vh - 100rpx);

			.item {
				height: 50rpx;
				line-height: 50rpx;
				padding: 20rpx;
				border-bottom: 2rpx solid #C0C0C0;
				width: 100%;
				display: flex;
				justify-content: space-between;
				align-items: center;
				font-size: 24rpx;
				.item_1 {
					flex: 1;
					display: flex;
					.item_1_1 {
						flex: 1;
					}

					.item_1_2 {
						width: 200rpx;
						color: #45b1e2;
					}
				}
			}
		}
		.list{
			height:calc(100vh - 110rpx);
			width:100%
		}
		.btn_css {
			width: 700rpx;
			height: 90rpx;
			margin: 0 auto;
			background-color: #1B64F8FF;
			color: white;
			margin-bottom: 20rpx;
			border-radius: 10rpx;
			display: flex;
			align-items: center;
			justify-content: center;
		}
	}
</style>
