<template>
	<view class="container">
		<image class="cbg" :src="base.imgHost('common_bg.png')"></image>
		<view class="search">
			<view class="search-icon" @click="showSearch=!showSearch">
				<image :src="base.imgHost('search.png')"></image>
			</view>
			<view class="search-tab">
				<u-tabs :bg-color="'#f0f7fc'" active-color="#b89155" :list="selectArr.company_industry" name="value"
					:is-scroll="true" :current="current" @change="changeSearch"></u-tabs>
			</view>
		</view>
		<!-- 字母 -->
		<view class="next-scroll-right">
			<view :class="{'next-scroll-right-name':true,'next-scroll-right-select':select.letter==''}"
			@click.stop="changeLetter('All')">
				All
			</view>
			<view :class="{'next-scroll-right-name':true,'next-scroll-right-select':select.letter===item}"
				v-for="(item,index) in letterList" :key="index" @click.stop="changeLetter(item)">{{item}}
			</view>
		</view>
		<view class="wrap">
			<view v-if="hasData">
				<view class="tips">
					按照姓名首字母顺序排列,排名不分先后
				</view>
				<scroll-view style="height:100vh" :scroll-y="true" @scrolltolower="scrollGet" class="list">
					<view class="left-item-card" v-for="(mess,inx) in list">
						<view class="left-item-card-info">
							<view class="left-item-card-name">
								<view>
									<text style="font-size:32rpx;color:#000">{{mess.name}}</text>
								</view>
							</view>
							<view v-if="mess['company_name']" style="font-size:28rpx;color:#666;margin-bottom:10rpx">
								{{mess['company_name']||''}}</view>
							<view v-if="mess['company_position']"
								style="font-size:28rpx;color:#666;margin-bottom:10rpx">{{mess['company_position']||''}}
							</view>
						</view>
					</view>
					<!-- <nextIndexedXlist :dataList="list" :show-avatar="false">
					</nextIndexedXlist> -->
				</scroll-view>
			</view>
			<view class="nodata" v-else>
				<u-empty mode="data"></u-empty>
			</view>
		</view>


		<view class="modal" v-if="showSearch">
			<view>
				<text>姓名：</text>
				<u-input v-model="select.name" border placeholder="请输入姓名"></u-input>
			</view>
			<view>
				<text>公司名称：</text>
				<u-input v-model="select.company_name" border placeholder="请输入公司名称"></u-input>
			</view>
			<!-- <view>
				<text>职务：</text>
				<u-input v-model="select.company_position" type="select" @click="showPosition=true" border
					placeholder="请选择"></u-input>
			</view> -->
			<view>
				<text>企业性质：</text>
				<u-input v-model="select.company_type" type="select" @click="showType=true" border
					placeholder="请选择"></u-input>
			</view>
			<view>
				<text>所属行业：</text>
				<u-input v-model="select.company_industry" type="select" @click="showIndustry=true" border
					placeholder="请选择"></u-input>
			</view>
			<view>
				<text>所属区域：</text>
				<u-input v-model="select.company_area" type="select" @click="showArea=true" border
					placeholder="请选择"></u-input>
			</view>

			<view class="modal-btn">
				<view @click="resetSearch">重置</view>
				<view class="modal-btn-search" @click="confirmSearch">检索</view>
			</view>
		</view>

		<!-- <u-picker @confirm="selectPosition" v-model="showPosition" :range="selectArr.company_position" range-key="value"
			mode="selector"></u-picker> -->
		<u-picker @confirm="selectArea" v-model="showArea" :range="selectArr.company_area" range-key="value"
			mode="selector"></u-picker>
		<u-picker @confirm="selectType" v-model="showType" :range="selectArr.company_type" range-key="value"
			mode="selector"></u-picker>
		<u-picker @confirm="selectIndustry" v-model="showIndustry" :range="selectArr.company_industry" range-key="value"
			mode="selector"></u-picker>


	</view>
</template>

<script>
	import nextIndexedXlist from '@/components/next-indexed-xlist/components/next-indexed-xlist/next-indexed-xlist.vue';
	export default {
		components: {
			nextIndexedXlist
		},
		data() {
			return {
				showSearch: false,
				showPosition: false,
				showArea: false,
				showType: false,
				showIndustry: false,
				selectArr: {
					// company_position: [],
					company_area: [],
					company_type: [],
					company_industry: [{
						value: '全部'
					}],
				},
				select: {
					name: '',
					company_name: '',
					// company_position: '',
					company_area: '',
					company_type: '',
					company_industry: '',
					letter:''
				},
				current: 0,
				list: [],
				current_page: 1,
				total_page: 0,
				hasData: true,
				letterList:["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
			}
		},
		onLoad() {
			this.getMyCourseTxl()
			this.getIndustry()
		},
		methods: {
			scrollGet() {
				if (!this.hasData) {
					return
				}

				if (this.current_page > this.total_page) {
					this.base.toast('没有更多了')
					return
				}
				this.current_page = this.current_page + 1
				this.getMyCourseTxl()
			},

			changeLetter(e){
				if(e==='All'){
					this.select.letter = ''
				}else{
					
					this.select.letter = e
				}
				this.current_page = 1
				this.total_page = 0
				this.hasData = true
				this.list = []
				this.getMyCourseTxl()
			},
			async getMyCourseTxl() {
				uni.showLoading({
					title: "...",
					icon: 'none'
				})
				const res = await this.$u.api.courseUserList({
					// course_id: id,
					name: this.select.name,
					company_name: this.select.company_name,
					// company_position: this.select.company_position,
					company_area: this.select.company_area,
					company_type: this.select.company_type,
					company_industry: this.select.company_industry,
					type: 1,
					page: this.current_page,
					letter: this.select.letter
				})
				this.total_page = res.list.last_page
				
				if (res.list.data.length === 0 && this.current_page === 1) {
					this.hasData = false
				}
				this.list.push(...res.list.data)
				this.showSearch = false
				console.log("qwe",this.list)
				uni.hideLoading()
			},
			selectIndex(e) {
				console.log("e", e)
			},
			getIndustry() {
				this.$u.api.getparameter({
					'number[0]': 'company_industry',
					// 'number[1]': 'company_position',
					'number[2]': 'company_area',
					'number[3]': 'company_type',
				}).then(res => {
					res.map(item => {
						if (item.number == 'company_industry') {
							this.selectArr[item.number].push(...item.detail)
						} else {
							this.selectArr[item.number] = item.detail
						}

					})
					console.log("123", this.selectArr)
					// this.industryList.push(...res.detail)
				})
			},
			changeSearch(e) {
				console.log(e)
				this.current = e
				if (e > 0) {
					this.select.company_industry = this.selectArr.company_industry[e]['value']
				} else {
					this.select.company_industry = ''
				}
				this.current_page = 1 
				this.total_page = 0
				this.list = []
				this.hasData = true
				this.select.letter = ""
				this.getMyCourseTxl()
			},
			// selectPosition(e) {
			// 	this.select.company_position = this.selectArr.company_position[e[0]]['value']
			// },
			selectArea(e) {
				this.select.company_area = this.selectArr.company_area[e[0]]['value']
			},
			selectType(e) {
				this.select.company_type = this.selectArr.company_type[e[0]]['value']
			},
			selectIndustry(e) {
				this.select.company_industry = this.selectArr.company_industry[e[0]]['value']
			},
			resetSearch() {
				this.select = {
					name: '',
					company_name: '',
					// company_position: '',
					company_area: '',
					company_type: '',
					company_industry: '',
					letter:''
				}
				this.current = 0
				this.current_page = 1
				this.total_page = 0
				this.list = []
				this.hasData = true
				this.getMyCourseTxl()
			},
			confirmSearch() {
				this.getMyCourseTxl()
			}
		}

	}
</script>

<style scoped lang="scss">
	.container {
		padding: 30rpx;
		width: 100%;
		height: 100vh;
		overflow: scroll;

		.cbg {
			position: absolute;
			top: 0;
			left: 0;
			width: 100%;
			height: 100vh;
		}

		.search {
			width: 100%;
			position: fixed;
			top: 0;
			left: 0;
			height: 100rpx;
			padding: 20rpx 0;
			background-color: #f0f7fc;
			box-shadow: 1rpx -4rpx 15rpx 0 #333;
			display: flex;
			justify-content: space-between;
			align-items: center;
			z-index: 999;

			&-tab {
				width: calc(100% - 100rpx);
			}

			&-icon {
				width: 100rpx;
				height: 100rpx;
				background-color: #eaedeb;
				display: flex;
				justify-content: center;
				align-items: center;

				image {
					width: 39rpx;
					height: 31rpx;
				}
			}
		}


		.wrap {
			position: relative;
			padding-top: 100rpx;
			height: 100%;
			overflow: scroll;
			padding-right: 60rpx;
			.nodata {
				height: calc(100vh - 160rpx);
			}
			.tips{
				font-size: 24rpx;
				text-align: left;
				padding-left:30rpx;
				color:#999999;
				margin-bottom:30rpx;
				border-bottom:1rpx solid #cfd5d9;
				padding-bottom:20rpx;
			}
			.left-item-card {
				width: 100%;
				// height: 112rpx;
				background-color: #FFFFFF;
				box-sizing: border-box;
				padding-left: 24rpx;
				display: flex;
				align-items: center;
				justify-content: flex-start;
				margin-bottom: 30rpx;
				padding: 30rpx;
				background-color: #fff;
				border-radius: 20rpx;
			
				.left-item-card-img {
					width: 80rpx;
					min-width: 80rpx;
					height: 80rpx;
					background-color: #CFCFCF;
					display: flex;
					align-items: center;
					justify-content: center;
					font-size: 36rpx;
					font-weight: bold;
					color: #FFFFFF;
				}
			
				.img-info {
					background: none;
					border: solid #f0f0f0 1rpx;
				}
			
				.left-item-card-info {
					width: 100%;
					// margin-left: 32rpx;
					height: 100%;
					display: flex;
					align-items: flex-start;
					justify-content: center;
					flex-direction: column;
			
					&>view {
						margin-bottom: 10rpx;
			
					}
			
					.left-item-card-name {
						font-size: 32rpx;
						color: #333;
			
						.courseName {
							color: #b89155;
							margin: 0 10rpx;
							font-size: 28rpx;
						}
					}
			
					.left-item-card-phone {
						margin-top: 14rpx;
						font-size: 28rpx;
						line-height: 28rpx;
						color: #999999;
					}
				}
			}
		}
		.next-scroll-right {
			position: fixed;
			right: 10rpx;
			top: 50%;
			transform: translateY(-47%);
			z-index: 999 !important;
			display: flex;
			align-items: center;
			justify-content: center;
			flex-direction: column;
			.next-scroll-right-name {
				width: 40rpx;
				height: 40rpx;
				font-size: 32rpx;
				color: #333333;
				line-height: 40rpx;
				margin: 6rpx 10rpx;
				margin-top:0;
				display: flex;
				align-items: center;
				justify-content: center;
			}
		
			.next-scroll-right-select {
				width: 40rpx;
				height: 40rpx;
				border-radius: 50%;
				background: #b89155;
				color: #FFFFFF;
				font-size: 24rpx;
				line-height: 40rpx;
				margin: 0 10rpx;
		
			}
		}

		.modal {
			width: 100%;
			height: 100vh;
			position: fixed;
			top: 0;
			left: 0;
			z-index: 1000;
			// z-index: 999999;
			background-color: #fff;
			padding: 30rpx 60rpx;
			// padding-top: 130rpx;
			overflow: scroll;

			&>view {
				display: flex;
				align-items: center;
				margin-bottom: 30rpx;

				&>text:first-child {
					width: 140rpx;
				}

				u-input {
					width: calc(100% - 140rpx)
				}
			}

			&-btn {
				display: flex;
				justify-content: space-between;
				align-items: center;
				margin-top: 60rpx;

				&>view {
					width: 45%;
					text-align: center;
					margin: 0 auto;
					color: #fff;
					background: linear-gradient(to right, #5e5fbc, #0d0398);
					border-radius: 10rpx;
					padding: 20rpx;
				}

				&-search {
					background: linear-gradient(to right, #e4cdb4, #c69c6d) !important;
				}
			}

		}
		
	}
</style>