<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="12"
				/>
				<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="(club, index) in clubList" :key="index">
						<view class="club-list-top">
							<view class="list-left">
								<view class="list-head"
									><image
										:src="
											club.headpic
												? club.headpic
												: 'https://static.caimei365.com/app/img/icon/icon-club@3x.png'
										"
										mode=""
									></image
								></view>
							</view>
							<view class="list-item">
								<view class="list-title">
									<text class="list-name">{{ club.name }}</text>
									<text class="list-hist" @click.stop="_goHistory(club)"
										><text class="iconfont icon-dingdanxuanzhong"></text>订单列表</text
									>
								</view>
								<view class="list-opea">
									<text class="tags" v-if="club.vipFlag == 0 && club.userIdentity === 2 ">VIP</text>
									<text class="tags sv" v-if="club.vipFlag == 1">SVIP</text>
								</view>
							</view>
						</view>
						<view class="club-list-bot">
							<view class="list-opea">
								<view class="btn org" @click.stop="_goImmediately(club)"> <text>立即下单</text> </view>
								<view class="btn gre" @click.stop="_goSecond(club)"> <text>二手下单</text> </view>
								<view class="btn yel" @click.stop="_goBuyagain(club)"> <text>再次购买</text> </view>
								<view class="btn yeo" @click.stop="_goRechargeOrder(club)">
									<text>充值/下订金</text>
								</view>
							</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: '上拉显示更多',
			status: 66,
			pageNum: 1,
			pageSize: 10,
			hasNextPage: false,
			loadding: false,
			pullUpOn: true,
			pullFlag: true,
			scrollHeight: '',
			currPage: '', //当前页面
			prevPage: '', //上一个页面
			clubList: []
		}
	},
	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 = {
				userIdentity: '',
				name: this.searchInputVal,
				pageNum: 1,
				pageSize: this.pageSize,
				spId: this.serviceProviderId,
				status: this.status
			}
			this.SellerService.GetSellerClubList(params)
				.then(response => {
					let data = response.data
					if (data.list && data.list.length > 0) {
						this.isEmpty = false
						this.hasNextPage = response.data.hasNextPage
						this.clubList = data.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 = {
				userIdentity: '',
				name: this.searchInputVal,
				pageNum: this.pageNum,
				pageSize: this.pageSize,
				spId: this.serviceProviderId,
				status: this.status
			}
			this.SellerService.GetSellerClubList(params)
				.then(response => {
					let data = response.data
					if (data.list && data.list.length > 0) {
						this.hasNextPage = response.data.hasNextPage
						this.clubList = this.clubList.concat(data.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)
				})
		},
		onShowClose() {
			//输入框失去焦点时触发
			if (this.searchInputVal != '') {
				this.isShowClose = true
			} else {
				this.isShowClose = false
			}
		},
		delInputText() {
			//清除输入框内容
			this.searchInputVal = ''
			this.isShowClose = false
		},
		_goImmediately(item) {
			this.$api.setStorage('orderUserInfo', item)
			this.$api.navigateTo('/pages/seller/cart/immediately')
		},
		_goBuyagain(item) {
			this.$api.setStorage('orderUserInfo', item)
			this.$api.navigateTo('/pages/seller/cart/buyagain')
		},
		_goRechargeOrder(item) {
			this.$api.setStorage('orderUserInfo', item)
			this.$api.navigateTo('/pages/seller/order/create-recharge-order')
		},
		_goSecond(item) {
			this.$api.setStorage('orderUserInfo', item)
			this.$api.navigateTo('/pages/seller/cart/second')
		},
		_goHistory(item) {
			this.$api.setStorage('orderUserInfo', item)
			this.$api.navigateTo(`/pages/seller/order/order-historylist?clubID=${item.clubID}&listType=0`)
		}
	},
	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;
		.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;
		}
		.input {
			width: 500rpx;
			height: 64rpx;
			float: left;
			line-height: 64rpx;
			color: $text-color;
			font-size: $font-size-24;
		}
	}
	.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 {
		align-items: center;
		width: 702rpx;
		height: auto;
		padding: 24rpx;
		background: #ffffff;
		position: relative;
		border-bottom: 1px solid #ebebeb;
		float: left;
		.club-list-top {
			width: 100%;
			height: 140rpx;
			float: left;
			display: flex;
			align-items: center;
			.list-left {
				height: 140rpx;
				flex: 2;
				margin-right: 10rpx;
				.list-head {
					width: 140rpx;
					height: 140rpx;
					border-radius: 14rpx;
					image {
						width: 140rpx;
						height: 140rpx;
						border-radius: 14rpx;
					}
				}
			}
			.list-item {
				height: 140rpx;
				flex: 8;
				display: flex;
				flex-direction: column;
				.list-title {
					flex: 2;
					line-height: 80rpx;
					width: 100%;
					font-size: $font-size-28;
					color: $text-color;
					padding-left: 11rpx;
					flex-direction: row;
					justify-content: flex-start;
					.list-name {
						width: 390rpx;
						display: block;
						float: left;
						text-align: left;
						-o-text-overflow: ellipsis;
						text-overflow: ellipsis;
						display: -webkit-box;
						word-break: break-all;
						-webkit-box-orient: vertical;
						-webkit-line-clamp: 1;
						overflow: hidden;
					}
					.list-hist {
						display: block;
						float: right;
						color: #e19b30;
						font-size: $font-size-24;
						text-align: right;
						padding-right: 30rpx;
						.icon-dingdanxuanzhong {
							font-size: $font-size-34;
							color: #e19b30;
						}
					}
				}
				.list-opea {
					width: 100%;
					display: flex;
					flex: 4;
					color: #166ce1;
					flex-direction: row;
					align-items: center;
					.tags {
						display: inline-block;
						width: 60rpx;
						height: 32rpx;
						border-radius: 8rpx;
						background: #f0cb72;
						font-size: $font-size-22;
						color: #4e4539;
						text-align: center;
						line-height: 32rpx;
						margin-left: 10rpx;
						&.sv {
							background: #333333;
							color: #f0cb72;
						}
					}
				}
			}
		}
		.club-list-bot {
			width: 100%;
			height: 60rpx;
			float: left;
			margin-top: 20rpx;
			.list-opea {
				width: 100%;
				display: flex;
				flex: 1;
				color: #166ce1;
				flex-direction: row;
				align-items: center;
				.btn {
					width: 160rpx;
					height: 60rpx;
					line-height: 60rpx;
					border-radius: 30rpx;
					font-size: $font-size-24;
					color: $text-color;
					text-align: center;
					margin: 0 15rpx;
					&.org {
						background: rgba(22, 225, 77, 0.1);
						color: #16e14d;
					}
					&.gre {
						background: rgba(22, 123, 225, 0.1);
						color: #167be1;
					}
					&.yel {
						background: rgba(225, 86, 22, 0.1);
						color: #e15616;
					}
					&.yeo {
						background: #fff5cf;
						color: #ffaa01;
					}
				}
			}
		}
	}
}
</style>
