<template>
	<view class="container club clearfix">
		<view class="club-search clearfix">
			<view class="search-from name">
				<text class="iconfont icon-iconfonticonfontsousuo1"></text>
				<input class="input" 
					   type="text" 
					   confirm-type="search" 
					   v-model="searchInputVal" 
					   @input="onShowClose" 
					   @confirm="initclubList()" 
					   placeholder="机构名称/姓名/手机号" 
					   maxlength="16"/>
				<text class="iconfont icon-shanchu1" v-if="isShowClose" @click="delInputText()"></text>
			</view>
			<view class="search-btn">
				<button class="search-btn" type="default" @click.stop="searchClubList">搜索</button>
			</view>
		</view>
		<view class="club-main">
			<view v-if="isEmpty" class="empty-container">
				<image class="club-empty-image" src="https://img.caimei365.com/group1/M00/03/71/Cmis2F3wna6AY2ZjAABpmnBICH4247.png" mode="aspectFit"></image>
				<view class="txt">暂无机构数据</view>
			</view>
			<view v-else class="club-list">
				<scroll-view scroll-y="true">
					<view class="list" v-for="(item, index) in clubList" :key="index">
						<view class="list-left">
							<view class="list-head"><image :src="item.headpic ? item.headpic : 'https://static.caimei365.com/app/img/icon/icon-club@3x.png'" mode=""></image></view>
							<view class="list-tel">
								<text class="txt">{{item.name == null ? item.username : item.name}}</text>
								<text class="txt sm">
									<text class="txt-le">{{checkData(item.linkMan)  ? desensitizationName(item.linkMan) : ''}}</text>
									{{item.contractMobile1 ? hidePhone(item.contractMobile1) : ''}}
								</text>
							</view>
						</view>
						<view class="list-opea">
							<view class="opea-type-cell" @click.stop="goOperator(item)">
								<text class="text">邀请运营人员</text>
							</view>
						</view>
					</view>
					<!--加载loadding-->
					<tui-loadmore :visible="loadding" :index="3" type="black"></tui-loadmore>
					<tui-nomore :visible="!pullUpOn" :backgroundColor="'#ffffff'" :text='nomoreText'></tui-nomore>
					<!--加载loadding-->
				</scroll-view>
			</view>
		</view>
	</view>
</template>

<script>
	import authorize from '@/common/config/authorize.js'	
	import tuiLoadmore from '@/components/tui-components/loadmore/loadmore'
	import tuiNomore from '@/components/tui-components/nomore/nomore'
	export default {
		components:{
			tuiLoadmore,
			tuiNomore,
		},
		data() {
			return {
				serviceProviderId:'',
				isShowClose:false,
				searchInputVal:'',
				isEmpty:false,
				nomoreText: '上拉显示更多',
				pageNum:1,
				pageSize:10,
				hasNextPage:false,
				loadding: false,
				pullUpOn: true,
				pullFlag: true,
				allowDataStatus:true,
				wrapperHeight:'100%',
				scrollHeight:'',
				deleteAddressId:'',
				currPage:'',//当前页面
				prevPage:'',//上一个页面
				tabCurrentIndex:0,
				listStatus:1,
				clubList:[],
				isIphoneX:this.$store.state.isIphoneX,
				show_index:0,//控制显示那个组件
			}
		},
		onLoad(){				
			this.setScrollHeight()
		},
		methods: {
			setScrollHeight() {
				// 窗口高度 - 底部距离
				setTimeout(()=> {
					const query = wx.createSelectorQuery().in(this)
					query.selectAll('.add-btn').boundingClientRect()
					query.exec(res => {
						if(res[0][0]){
							let winHeight = this.$api.getWindowHeight(),
								eleTop = res[0][0].top - 1
								this.scrollHeight =  eleTop
						}
					})
				}, 500)
			},
			searchClubList(){
				this.pageNum=1
				this.initclubList()
			},
			initclubList(){	
				let params = { searchWord:this.searchInputVal,pageNum:1,pageSize:this.pageSize }
				this.SellerService.GetFindAllClubList(params).then(response =>{
					let responseData = response.data
					if(responseData.list&&responseData.list.length > 0){
						this.isEmpty = false
						this.hasNextPage = response.data.hasNextPage
						this.clubList =responseData.list
						this.pullFlag = false
						setTimeout(()=>{this.pullFlag = true},500)
						if(this.hasNextPage){
							this.pullUpOn = false
							this.nomoreText = '上拉显示更多'
						}else{
							this.pullUpOn = true
							this.loadding = false
							this.nomoreText = '已至底部'
						}
					}else{
						this.isEmpty = true
					}
				}).catch(error =>{
					this.$util.msg(error.msg,2000)
				})
			},	
			getOnReachBottomData(){
				this.pageNum+=1
				let params = {searchWord:this.searchInputVal,pageNum:this.pageNum,pageSize:this.pageSize }
				this.SellerService.GetFindAllClubList(params).then(response =>{
					let responseData = response.data
					if(responseData.list&&responseData.list.length > 0){
						this.hasNextPage = response.data.hasNextPage
						this.clubList = this.clubList.concat(responseData.list) 
						this.pullFlag = false// 防上拉暴滑
						setTimeout(()=>{this.pullFlag = true},500)
						if(this.hasNextPage){
							this.pullUpOn = false
							this.nomoreText = '上拉显示更多'
						}else{
							this.pullUpOn = false
							this.loadding = false
							this.nomoreText = '已至底部'
						}
					}
				}).catch(error =>{
					this.$util.msg(error.msg,2000)
				})
			},
			goOperator(item){
				this.$api.setStorage('orderUserInfo',item)
				this.$api.navigateTo('/pages/seller/club/addoperator')
			},
			onShowClose () {//输入框失去焦点时触发
				if(this.searchInputVal != ''){
					this.isShowClose = true
				}else{					
					this.isShowClose = false
					this.pageNum=1
					this.initclubList()
				}
			},
			delInputText(){//清除输入框内容
				this.searchInputVal = ''
				this.isShowClose = false
				this.pageNum=1
				this.initclubList()
			},
			hidePhone(val){
				let phone
				if(val==null || val==''){
					phone = ''	
				}else{
					phone = this.$reg.hidePhone(val)
				}
				return phone
			},
			checkData (value){
				let data
				if(value == null || value ==''){
					data = ''
				}else{
					data = value
				}
				return data
			},
			desensitizationName(val){
				let name = this.$reg.desensitizationName(val)
				return name
			}
		},
		onReachBottom() {
			if(this.hasNextPage){
				this.loadding = true
				this.pullUpOn = true
				this.getOnReachBottomData()
			}	
		},
		onShow() {
			this.$api.getStorage().then(response =>{
				this.serviceProviderId = response.serviceProviderId
				this.pageNum = 1
				this.initclubList()
			})
		}
	}
</script>

<style lang='scss'>
	page {
		height: auto;
	}
	page,.container{
		/* padding-bottom: 120upx; */
		background: #F7F7F7;
	}
	.container{
		position: relative;
	}
	.club-search{
		height: 64rpx;
		width: 702rpx;
		padding: 24rpx;
		background: #FFFFFF;
		display: flex;
		align-items: center;
		position: fixed;
		top: 0;
		left: 0;
		z-index: 999;
		.search-from{
			width: 582rpx;
			height: 64rpx;
			background: #F7F7F7;
			border-radius: 32rpx;
			float: left;
			position: relative;
			.input{
				width: 500rpx;
				height: 64rpx;
				float: left;
				line-height: 64rpx;
				color: $text-color;
				font-size: $font-size-24;
			}
			.icon-iconfonticonfontsousuo1{
				width: 64rpx;
				height: 64rpx;
				line-height: 64rpx;
				text-align: center;
				display: block;
				font-size: $font-size-38;
				float: left;
				color: #999999;
			}
			.icon-shanchu1{
				font-size: $font-size-32;
				color: #999999;
				position: absolute;
				width: 64rpx;
				height: 64rpx;
				line-height: 64rpx;
				text-align: center;
				top: 0;
				right: 0;
				z-index: 10;
			}
		}
		.search-btn{
			width: 120rpx;
			line-height: 64rpx;
			text-align: center;
			font-size: $font-size-28;
			color: $color-system;
			float: left;
			background: #FFFFFF;
		}
	}
	.club-main{
		padding-top: 122rpx;
		.list{
			display: flex;
			align-items: center;
			width: 702rpx;
			height: auto;
			padding: 24rpx;
			background: #FFFFFF;
			position: relative;
			border-bottom: 1px solid #EBEBEB;
			.list-left{
				display: flex;
				flex: 8;
				.list-head{
					width: 92rpx;
					height: auto;
					display: flex;
					align-items: center;
					image{
						width: 92rpx;
						height: 92rpx;
						border-radius: 14rpx;
					}
				}
				.list-tel{
					margin: 0 15rpx;
					width: 320rpx;
					.txt{
						display: flex;
						flex: 1;
						font-size: $font-size-26;
						color: $text-color;
						line-height: 40rpx;
						&.sm{
							font-size: $font-size-24;
							color: #666666;
							.txt-le{
								margin-right: 26rpx;
							}
						}
					}
				}
			}
			.list-opea{
				display: flex;
				flex: 2;
				color: #166CE1;
				flex-direction: column;
				.opea-type-cell{
					font-size: 24rpx;
					.text{
						width: 156rpx;
						height: 60rpx;
						padding: 0 20rpx;
						line-height: 60rpx;
						border-radius: 30rpx;
						font-size: $font-size-24;
						color: #FFFFFF;
						text-align: center;
						background: $btn-confirm;
						display: block;
					}
				}
			}
		}
	}
</style>

