<template>
	<view class="container supplier clearfix">
		<view class="supplier-search clearfix">
			<view class="search-from name">
				<text class="iconfont icon-sousuo"></text>
				<input class="input" 
					   type="text" 
					   confirm-type="search" 
					   v-model="listQuery.keyword" 
					   :focus="isFocus"
					   @input="onShowClose" 
					   @confirm="GetSearchEquipmentList()" 
					   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="searchsupplierList">搜索</button>
			</view>
		</view>
		<view class="equipment-main">
			<view v-if="isEmpty" class="empty-container">
				<image class="empty-container-image" :src="productNoneImage" mode="aspectFit"></image>
				<view class="txt">暂无项目仪器数据^_^</view>
			</view>
			<view v-else class="supplier-list">
					<view class="list clearfix" v-for="(item, index) in list" :key="index" @click.stop="navToDetailPage(item.id)">
						<image class="pros-item-image" :src="item.image" mode="scaleToFill"></image>
						<view class="pros-name">{{ isInterceptHtmlFn(item.name) }}</view>
					</view>
					<!--加载loadding-->
					<tui-loadmore :visible="loadding" :index="3" type="black"></tui-loadmore>
					<tui-nomore :visible="!pullUpOn" :backgroundColor="'#ffffff'" :text='nomoreText'></tui-nomore>
					<!--加载loadding-->
			</view>
		</view>
	</view>
</template>

<script>
	import authorize from '@/common/config/authorize.js'	
	import wxLogin from "@/common/config/wxLogin.js"
	import tuiLoadmore from "@/components/tui-components/loadmore/loadmore"
	import tuiNomore from "@/components/tui-components/nomore/nomore"
	import { mapState } from 'vuex'
	export default {
		components:{
			tuiLoadmore,
			tuiNomore
		},
		data() {
			return {
				iconClass:'icon-aixin',
				iconColor:'#ff9100',
				isShowClose:false,
				isEmpty:false,
				isFocus:true,
				productNoneImage:'https://static.caimei365.com/app/img/icon/icon-pnone.png',
				nomoreText: '上拉显示更多',
				loadding: false,
				pullUpOn: true,
				pullFlag: true,
				list:[],
				listQuery:{
					keyword: '',
					pageSize: 10,
					pageNum: 1
				},
				total:0
			}
		},
		onLoad(option){
			if(option.type =='share'){
				wxLogin.wxLoginAuthorize()
			}
			if(option.keyWord){
				this.listQuery.keyword = option.keyWord
				this.GetSearchEquipmentList();
			}
		},
		methods: {
			searchsupplierList(){//搜索
				this.listQuery.pageNum=1
				this.GetSearchEquipmentList()
				// 友盟埋点项目仪器搜索点击
				if(process.env.NODE_ENV != 'development'){
					this.$uma.trackEvent('Um_Event_SearchInstrumentButton', {
						Um_Key_Keyword: `${this.listQuery.keyword}`,
						Um_Key_PageName: '项目仪器',
						Um_Key_SourcePage: '搜索项目仪器',
					})
				}
			},
			GetSearchEquipmentList(){//查询供应商列表	
				this.ProductService.GetSearchEquipmentList(this.listQuery).then(response =>{
					let data = JSON.parse(response.data)
					let dataList = data.items
					console.log(data)
					this.total = data.total
					if(dataList && dataList.length > 0){
						this.isEmpty = false
						this.list = dataList
						this.pullFlag = false;
						setTimeout(()=>{this.pullFlag = true;},500)
						if(this.total>this.list.length){
							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)
				})
			},	
			GetSearchEquipmentListBottomData(){//上滑加载
				this.listQuery.pageNum+=1
				this.ProductService.GetSearchEquipmentList(this.listQuery).then(response =>{
					let data = JSON.parse(response.data)
					console.log(data)
					this.total = data.total
					this.list = this.list.concat(data.items) 
					if(this.total>this.list.length){
						this.pullUpOn = false
						this.nomoreText = '上拉显示更多'
					}else{
						this.pullUpOn = true
						this.loadding = false
						this.nomoreText = '已至底部'
					}
				}).catch(error =>{
					this.$util.msg(error.msg,2000)
				})
			},
			onShowClose () {//输入框失去焦点时触发
				if(this.listQuery.keyword != ''){
					this.isShowClose = true
				}else{					
					this.isShowClose = false
					this.listQuery.pageNum=1
					this.GetSearchEquipmentList()
				}
			},
			delInputText(){//清除输入框内容
				this.listQuery.keyword = ''
				this.isShowClose = false
				this.listQuery.pageNum=1
				this.GetSearchEquipmentList()
			},
			navToDetailPage(id) {//跳转仪器详情页
				this.$api.navigateTo(`/pages/goods/instrument-details?id=${id}`)
			},
			isInterceptHtmlFn(text){
				let name = this.$reg.interceptHtmlFn(text)
				return name
			},
		},
		onReachBottom() {
			if(this.total>this.list.length){
				this.loadding = true
				this.pullUpOn = true
				this.GetSearchEquipmentListBottomData()
			}	
		},
		onShareAppMessage(res){//分享转发
			if (res.from === 'button') {
		      // 来自页面内转发按钮
		    }
			return {
			  title: `做项目找仪器，上采美`,
			  path: `pages/search/search-instrument?type=share&keyWord=${this.listQuery.keyword}`
			}
		},
		onShow() {

		}
	}
</script>

<style lang='scss'>
	page {
		height: auto;
	}
	page,.container{
		/* padding-bottom: 120upx; */
		background: #F7F7F7;
	}
	.container{
		position: relative;
	}
	.supplier {
		width: 100%;
		height: auto;
		box-sizing: border-box;
	}
	.supplier-search{
		height: 84rpx;
		width: 100%;
		padding:10rpx 24rpx;
		background: #FFFFFF;
		display: flex;
		align-items: center;
		position: fixed;
		top: 0;
		left: 0;
		z-index: 999;
		box-sizing: border-box;
		.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-sousuo{
				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: #666666;
			float: left;
			background: #FFFFFF;
		}
	}
	.equipment-main{
		box-sizing: border-box;
		padding: 0 24rpx;
		margin-top: 94rpx;
	}
	.list{
		width: 340rpx;
		height: 301rpx;
		float: left;
		margin-right: 20rpx;
		margin-top: 10rpx;
		margin-bottom: 10rpx;
		border-radius: 6rpx;
		background-color: #FFFFFF;
		&:nth-child(2n){
			margin-right: 0;
		}
		.pros-item-image{
			width: 340rpx;
			height: 227rpx;
			display: block;
			float: left;
			border-radius: 6rpx 6rpx 0 0;
		}
		.pros-name{
			width: 100%;
			height: 74rpx;
			background-color: #FFFFFF;
			line-height: 74rpx;
			box-sizing: border-box;
			padding: 0 20rpx;
			font-size: $font-size-24;
			color: #666666;
			white-space: normal;
			word-break: break-all;
			overflow: hidden;
			text-overflow: ellipsis;
			display: -webkit-box;
			-webkit-box-orient: vertical;
			-webkit-line-clamp: 1;
			text-align: center;
		}
	}

</style>

