<template>
	<view class="page">
		<view class="pageMain">
			<view class="topBox">
				<view class="bg-2f9 padding-lr-30">
					<ty-bar-search :value.sync="keyword" @search="search" @clear="clear" :autofocus="false"
						:clearable="true" :placeholder="'请输入您想咨询专家的专业方向、建筑类型'" :bgColor="'#fff'">
					</ty-bar-search>
				</view>
				<view class="bg-ff flex tabBox">
					<view class="eveTab line-height-90 position-relative" v-for="(item,index) in tabs" :key="index"
						:class="tabIndex == index ? 'text-28 text-bold' : 'text-33 text-26'"
						:style="index == (tabs.length - 1) ? '' : 'margin-right: 70rpx;'" @click="changeTab(index)">
						{{item.name}}
						<view class="activeTabLine" v-if="tabIndex == index"></view>
					</view>
					<view class="width-50" style="flex-shrink: 0;"></view>
				</view>
			</view>
			<view class="listBox padding-lr-30 padding-bottom-30">
				<ty-list-list :status="load_status">
					<view class="flex eveList" v-for="(item,index) in list" :key="index"
						@click="go('/pages/expert/detail?id='+item.id)">
						<view class="headerImg">
							<image :src="item.head_img" mode="aspectFill" class="width-100p height-100p">
							</image>
						</view>
						<view class="flex-one margin-left-15">
							<view class="flex justify-between align-center margin-bottom-5">
								<view class="text-34 text-33 text-bold">{{item.name}}</view>
								<view class="text-32 text-ff85 text-bold text-price">{{item.price}}</view>
							</view>
							<view class="text-cut-one text-26 text-909298 margin-bottom-10 text-cut-one">{{item.brief}}
							</view>
							<view class="flex justify-end">
								<view class="text-ff text-26 text-bold zxBtn" @click.stop="tapConsulting(item.id)">
									立即咨询
								</view>
							</view>
						</view>
					</view>
				</ty-list-list>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				keyword: '',
				tabIndex: 0,
				tabs: [],
				load_status: '',
				list: [],
			}
		},
		onLoad(options) {

		},
		onShow() {
			this.getCate()
			if(this.cn.isLogin()){
				this.getBottomTabRed()
			}
			
		},
		onPullDownRefresh() {
			this.loadList(1)
		},
		onReachBottom() {
			this.loadList(2)
		},
		methods: {
			// 获取底部导航栏红点是否显示
			getBottomTabRed(){
				this.rq.getData('chat/api/FriendsChat/getNoReadNumber').then((res)=>{
					if(res.code == 0){
						if(res.data.number > 0){
							uni.showTabBarRedDot({
								index: 1
							})
						}else{
							uni.removeTabBarBadge({ index: 1 })
						}
					}
				})
			},
			getCate() {
				this.rq.getData('fire/api/Fire/getExpertCategory').then(res => {
					if (res.code == 0) {
						this.tabs = res.data.category;
						if (uni.getStorageSync('expertKeyword') && uni.getStorageSync('expertKeyword') != this
							.keyword) {
							this.keyword = uni.getStorageSync('expertKeyword')
						}
						this.loadList(1)
					}
				})
			},
			search() {

				this.loadList(1)
			},
			clear() {
				this.keyword = '';
				this.search()
			},
			changeTab(i) {
				if (this.tabIndex == i) {
					return;
				} else {
					this.tabIndex = i;
					this.loadList(1)
				}
			},
			loadList(first_page) {
				this.rq.getList('fire/api/Fire/getExpertList', {
					category_id: this.tabs[this.tabIndex].id,
					keyword: this.keyword,
				}, {
					that: this,
					first_page
				}).then(() => {
					uni.setStorageSync('expertKeyword', this.keyword)
					uni.stopPullDownRefresh()
				})
			},
			tapConsulting(id) {
				if (this.cn.isLogin()) {
					uni.navigateTo({
						url: '/pages/expert/order?id=' + id
					})
				} else {
					uni.navigateTo({
						url: '/pages/home/login'
					})
				}
			}
		}
	}
</script>

<style scoped>
	.topBox {
		width: 100vw;
		position: fixed;
		top: 0;
		left: 0;
		z-index: 10;
	}

	.tabBox {
		width: 100vw;
		padding-left: 50rpx;
		box-sizing: border-box;
		overflow-x: scroll;
	}

	.tabBox .eveTab {
		flex-shrink: 0;
	}

	.activeTabLine {
		width: 40rpx;
		height: 4rpx;
		background: #2F97FF;
		position: absolute;
		left: 0;
		right: 0;
		bottom: 20rpx;
		margin: 0 auto;
	}

	.pageMain {
		padding-top: calc(var(--headerHeight) + 115rpx);
	}

	.headerImg {
		width: 160rpx;
		height: 160rpx;
		border-radius: 10rpx;
		overflow: hidden;
	}

	.eveList {
		width: 100%;
		background: #FFFFFF;
		border-radius: 15rpx;
		padding: 25rpx;
		box-sizing: border-box;
		margin-bottom: 25rpx;
	}

	.zxBtn {
		width: 160rpx;
		height: 60rpx;
		background: #2F97FF;
		border-radius: 32rpx;
		text-align: center;
		line-height: 60rpx;
	}
</style>
