search.vue 13.1 KB
Newer Older
1 2 3 4
<template>
	<view class="content">
		<view class="navbar" :style="{position:headerPosition}">
			<view class="search-content">
郑秀明's avatar
郑秀明 committed
5
				<uni-icons color="#212121" class="search-icon-arrowleft" @click="backHome" size="24" type="arrowleft" />
6 7 8 9 10 11
				<view class="search-input_box" @click="searchClick">
					<view class="search-input_val">{{searchVal}}</view>
					<uni-icons color="#999999" class="uni-searchbar__box-icon-search" size="20" type="search" />
				</view>
			</view>
			<view class="search-condition">
郑秀明's avatar
郑秀明 committed
12
				<view class="search-condition_item" :class="{current: param.label === 'default'}" @click="tabClick('default')">
13 14
					<text>综合排序</text>
					<view class="icon_tips">
郑秀明's avatar
郑秀明 committed
15 16
						<text :class="{active: param.order === 'asc' && param.label === 'default'}" class="yticon"></text>
						<text :class="{active: param.order === 'desc' && param.label === 'default'}" class="yticon"></text>
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
					</view>
				</view>
				<view class="search-condition_item" :class="{current: param.label === 'sales'}" @click="tabClick('sales')">
					<text>销量排序</text>
					<view class="icon_tips">
						<text :class="{active: param.order === 'asc' && param.label === 'sales'}" class="yticon xia"></text>
						<text :class="{active: param.order === 'desc' && param.label === 'sales'}" class="yticon"></text>
					</view>
				</view>
				<view class="search-condition_item" :class="{current: param.label === 'price'}" @click="tabClick('price')">
					<text>价格排序</text>
					<view class="icon_tips">
						<text :class="{active: param.order === 'asc' && param.label === 'price'}" class="yticon xia"></text>
						<text :class="{active: param.order === 'desc' && param.label === 'price'}" class="yticon"></text>
					</view>
				</view>
				<view class="search-condition_item" :class="{current: param.label === 'add_time'}" @click="tabClick('add_time')">
					<text>新品排序</text>
					<view class="icon_tips">
						<text :class="{active: param.order === 'asc' && param.label === 'add_time'}" class="yticon xia"></text>
						<text :class="{active: param.order === 'desc' && param.label === 'add_time'}" class="yticon"></text>
					</view>
				</view>
			</view>
		</view>
		<!-- 空白页 -->
郑秀明's avatar
郑秀明 committed
43
		<empty v-if="goods_list.length === 0" title=''></empty>
44 45 46
		<!-- 商品列表 -->
		<view class="goods-list" v-if="goods_list.length > 0">
			<view class="goods-item" v-for="(item,index) in goods_list" :key="index">
王建威's avatar
王建威 committed
47
				<countDown v-if="item._source.is_pro === 1" :time="item._source.end_time"></countDown>
zhengxiuming's avatar
zhengxiuming committed
48
				<view class="image-outer" @click="jumpPhpPage(`app=goods&id=${item._source.goods_id}`, item._source.equipment_id, item._source.is_show)">
zhengxiuming's avatar
zhengxiuming committed
49
					<image class="goods_image" :src="item._source.default_image || $noGoodsImg" lazy-load  @error="$__reloadResource(item)" mode="aspectFit"></image>
zhengxiuming's avatar
zhengxiuming committed
50
					<image v-if="item._source.equipment_id && item._source.is_show == 1" src="https://dbc-static.oss-cn-beijing.aliyuncs.com/static/WechatIMG5.png" class="equipment_logo" mode="aspectFill"></image>
51
				</view>
zhengxiuming's avatar
zhengxiuming committed
52
				<view class="title">{{item._source.brand  ? `【${item._source.brand}】` : ''}}{{item._source.goods_name}}</view>
zhengxiuming's avatar
zhengxiuming committed
53
				<!-- <view class="sub-title">{{item._source.goods_subname}}</view> -->
王建威's avatar
王建威 committed
54 55 56 57 58 59 60 61 62 63 64
				<view v-if="isLogin">
					<view v-if="item._source.is_pro === 1">
						<view class="price"><text class="price-tips"></text>{{item._source.pro_price.toFixed(2)}}
							<text class="discount">{{(item._source.pro_price*10/Number(item._source.price)).toFixed(1)}}</text>
						</view>
						<view class="origin_price">¥{{item._source.price}}</view>
					</view>
					<view v-if="item._source.is_pro === 0">
						<view class="price"><text class="price-tips"></text>{{item._source.price}}</view>
					</view>
				</view>
郑秀明's avatar
郑秀明 committed
65
				<view v-if="!isLogin" class="unlogin_price">登录显示价格</view>
66
				<!-- <view class="old-price"><text class="price-tips"></text>30.00</view> -->
王建威's avatar
王建威 committed
67
				<text class="cart-icon eosfont" @click="addCart(item._source.default_spec, 1)">&#xe74a;</text>
68 69 70
			</view>
		</view>
		<uni-load-more :status="loadingType"></uni-load-more>
郑秀明's avatar
郑秀明 committed
71
		<BottomBar />
72 73 74 75 76
	</view>
</template>

<script>
	import uniIcons from "@/components/uni-icons/uni-icons.vue";
王建威's avatar
王建威 committed
77
	import countDown from "@/components/countDown.vue";
78
	import uniLoadMore from "@/components/uni-load-more/uni-load-more.vue";
郑秀明's avatar
郑秀明 committed
79
	import BottomBar from "@/components/BottomBar/BottomBar.vue";
80 81 82 83 84 85 86
	import empty from '@/components/empty.vue';
	import service from '@/components/service.vue';
	import { php, go } from '../../common/host.js';
	export default {
		components: {
			uniIcons,
			empty,
王建威's avatar
王建威 committed
87 88
			uniLoadMore,
			countDown
89 90 91 92 93 94 95 96 97 98 99 100 101
		},
		data() {
			return {
				goods_list: [],
				searchVal: '',
				loadingType: 'more', //加载更多状态
				headerPosition: "fixed",
				headerTop: "0px",
				isLogin: false,
				param: {
					keyword: '',
					pageSize: 20,
					current: 1,
郑秀明's avatar
郑秀明 committed
102
					label: 'default',
103 104 105 106 107 108 109 110 111 112 113 114
					order: 'desc'
				}
			};
		},
		onLoad(option){
			// var pages = getCurrentPages(); // 当前页面
			// var beforePage = pages[pages.length - 2];
			// #ifdef H5
			//默认请求微信分享
			if (this.$wechat && this.$wechat.isWechat()) {
				this.$wechat.share({titie: this.$getNavigationBarTitle()});
			}
115
			this.postData();
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
			// #endif
			this.param = {...this.param, ...option};
			this.searchVal = option.keyword;
			this.getData();
		},
		onPageScroll(e){
			//兼容iOS端下拉时顶部漂移
			if(e.scrollTop>=0){
				this.headerPosition = "fixed";
			}else{
				this.headerPosition = "absolute";
			}
		},
		//下拉刷新
		onPullDownRefresh(){
			this.getData('refresh');
		},
		//加载更多
		onReachBottom(){
			this.getData();
		},
		methods: {
郑秀明's avatar
郑秀明 committed
138
			backHome(){
郑秀明's avatar
郑秀明 committed
139
				uni.reLaunch({
郑秀明's avatar
郑秀明 committed
140 141 142
					url: '/pages/home/home'
				})
			},
143 144 145 146 147 148 149 150 151 152 153 154 155 156
			// 向小程序发送数据
			postData(){
				jWeixin.miniProgram.getEnv(function (res) {
					//获取当前环境
					if(res.miniprogram){ 
						// this.$wechat.postData('谛宝多多商城-首页');
						const postData = {
							link: window.location.href,
							title: '谛宝多多商城'
						}
						jWeixin.miniProgram.postMessage({ data: JSON.stringify(postData) });
					}
				});
			},
157 158 159 160 161 162 163 164 165 166 167 168
			// 加入购物车
			addCart(spec_id, quantity) {
				this.$addCart(spec_id, quantity, this.isLogin);
			},
			// 搜索框点击
			searchClick() {
				const keyword = this.searchVal || '';
				uni.navigateTo({
					url: `/pages/searchhistory/searchhistory?keyword=${keyword}`
				})
			},
			// 跳转商品详情页
zhengxiuming's avatar
zhengxiuming committed
169
			jumpPhpPage(url, id, is_show) {
170
				let link = url ? `${php}${url}` : php;
zhengxiuming's avatar
zhengxiuming committed
171
				if(id && is_show == 1){
zhengxiuming's avatar
zhengxiuming committed
172
					link = window.location.origin + `/uni/pages/installment/installmentinfo?id=${id}`;
zhengxiuming's avatar
zhengxiuming committed
173
				}
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
				window.location.href = link;
			},
			// 获取数据
			getData(type = 'add', loading) {
				if(type === 'add'){
					if(this.loadingType === 'nomore'){
						return;
					}
					// 区分是不是首次加载
					if(this.goods_list.length > 0){
						this.param.current += 1;
					}
					this.loadingType = 'loading';
				}else{
					this.param.current = 1;
					this.loadingType = 'more'
				}
				uni.request({
					url: '/uni/api/search_goods/search_goods_list',
					method: 'POST',
					data: this.param,
					dataType: 'json',
					success: (res) => {
						const { data } = res;
						if(data.code == 0){
							if(type === 'refresh'){
								this.goods_list = [];
							}
郑秀明's avatar
郑秀明 committed
202
							this.goods_list = this.goods_list.concat(data.data || []);
王建威's avatar
王建威 committed
203
							this.goods_list.map((item, key) => {
zhengxiuming's avatar
zhengxiuming committed
204 205
								let end_time = item._source.end_time ? item._source.end_time.replace(/-/g, '/') : '';
								if(item._source.is_pro === 1 && new Date(end_time).getTime() < new Date().getTime()){
zhengxiuming's avatar
zhengxiuming committed
206 207
									item._source.is_pro = 0;
								}
王建威's avatar
王建威 committed
208
							});
郑秀明's avatar
郑秀明 committed
209
							this.isLogin = data.login_flg === 1;
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249
							const {total, page_size, current} = data.page;
							this.param.current = current;
							//判断是否还有下一页,有是more,没有是nomore
							this.loadingType = this.goods_list.length >= total ? 'nomore' : 'more';
							if(type === 'refresh'){
								if(loading == 1){
									uni.hideLoading();
								}else{
									uni.stopPullDownRefresh();
								}
							}
						}
					}
				});
			},
			// tab搜索条件
			tabClick(name) {
				if(this.param.label !== name){
					this.param.order = 'desc';
				}else{
					this.param.order = this.param.order === 'desc' ? 'asc': 'desc';
				}
				this.param.label = name;
				
				uni.pageScrollTo({
					duration: 100,
					scrollTop: 0
				})
				this.getData('refresh', 1);
				uni.showLoading({
					title: '正在加载'
				})
			}
		}
	}
</script>

<style lang="less">
.content{
	padding-top: 168rpx;
郑秀明's avatar
郑秀明 committed
250
	padding-bottom:100rpx;
251 252 253 254 255 256 257
}
.navbar{
	left: 0;
	width: 100%;
	z-index: 999;
	background-color: #fff;
	box-shadow: 0 2upx 10upx rgba(0,0,0,.06);
郑秀明's avatar
郑秀明 committed
258 259
	// top: var(--window-top);
	top: 0;
260 261 262
}
.search-content{
	display: flex;
郑秀明's avatar
郑秀明 committed
263
	justify-content: flex-start;
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278
	align-items: center;
	height: 88rpx;
	padding: 0 20rpx;
	.search-icon-arrowleft{
		margin-right: 20rpx;
		width: 40rpx;
	}
	.search-input_box{
		flex: 1;
		height: 60rpx;
		line-height: 60rpx;
		position: relative;
		background-color: #F8F8F8;
		border-radius: 60rpx;
		display: flex;
郑秀明's avatar
郑秀明 committed
279
		justify-content: flex-start;
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381
		align-items: center;
		.search-input_val{
			position: absolute;
			font-size: 26rpx;
			color: #212121;
			font-family:PingFangSC-Regular,PingFang SC;
			font-weight:400;
			box-sizing: border-box;
			padding-left: 70rpx;
			text-overflow: ellipsis;
			overflow: hidden;
			white-space: nowrap;
			width: 100%;
		}
		.uni-searchbar__box-icon-search{
			width: 56rpx;
			height: 56rpx;
			position: absolute;
			top: 0rpx;
			left: 10rpx;
		}
		.search-input{
			height: 60rpx;
			line-height: 60rpx;
			flex: 1;
			padding-left: 75rpx;
			padding-right: 25px;
			font-size: 26rpx;
			color: #212121;
		}
		.search-close{
			position: absolute;
			right: 20rpx;
			top: 0rpx;
		}
	}
	.active{
		border: 3rpx solid #FFCD00;
	}
	.cancel-button{
		height: 40rpx;
		line-height: 40rpx;
		padding-left: 20rpx;
		font-size: 28rpx;
		color: #212121;
	}
}
.search-condition{
	display: flex;
	justify-content: center;
	align-items: center;
	height: 80rpx;
	border-bottom: 2rpx solid #ececec;
	.search-condition_item{
		flex: 1;
		font-size: 26rpx;
		color: #7c7c7c;
		font-weight: 400;
		text-align: center;
		height: 100%;
		line-height: 80rpx;
		.icon_tips{
			display: inline-block;
			.yticon{
				display: block;
				width: 20rpx;
				height: 20rpx;
				background: url(data:image;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUBAMAAAB/pwA+AAAAKlBMVEUAAAAAAAAqKioeHh4jIyMkJCQjIyMkJCQjIyMfHx8jIyMiIiIhISEjIyMLPgjcAAAADnRSTlMAAQwRJCssMjNJUGFjZnUvgGkAAAA6SURBVAjXY2CgLmDtAIIAMJPlLhA4QITn3r17E6pC++7dTVAm2927CVAm49pbAjAzbA7DjWMvoMAtAFI2ESM4e3ZZAAAAAElFTkSuQmCC) no-repeat;
				background-size: cover;
				margin-left: 4rpx;
				display: none;
				&.active{
					display: block;
					width: 20rpx;
					height: 20rpx;
					background: url(data:image;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUBAMAAAB/pwA+AAAAKlBMVEUAAAAAAAAhISEkJCQiIiIhISEgICAhISEgICAgICAhISEhISEhISEhISFyXSx2AAAADXRSTlMAAh8rW2tufH+2x/P5faSp4gAAADpJREFUCNdjYKAuYO0AggAwk+UuEDhAhOfevXsTqkL77t1NUCbb3bsJUCbj2lsCMDNsDsONYy+gwC0AUjYRIzh7dlkAAAAASUVORK5CYII=) no-repeat;
					background-size: cover;
					.xia{
						display: block;
						transform: scaleY(-1);
					}
				}
			}
			.xia{
				display: none;
				transform: scaleY(-1);
			}
		}
		&.current{
			color: #212121;
			font-family:PingFangSC-Medium,PingFang SC;
			font-weight:500;
		}
	}
}
.goods-list{
	display:flex;
	flex-wrap:wrap;
	padding: 20rpx 0;
	background: #fff;
	.goods-item{
		width: 374rpx;
郑秀明's avatar
郑秀明 committed
382
		height: 576rpx;
383 384 385 386 387 388 389 390
		box-sizing: border-box;
		padding: 40rpx 27rpx 24rpx 27rpx;
		position: relative;
		&:nth-child(2n+1){
			margin-right: 2rpx;
		}
		.image-outer{
			width: 320rpx;
郑秀明's avatar
郑秀明 committed
391
			height: 320rpx;
392
			position: relative;
zhengxiuming's avatar
zhengxiuming committed
393
			.goods_image{
394 395 396 397 398 399 400 401 402
				position: absolute;
				top: 0;
				left: 0;
				right: 0;
				bottom: 0;
				max-width: 100%;
				max-height: 100%;
				margin: auto;
			}
zhengxiuming's avatar
zhengxiuming committed
403 404 405 406 407 408 409
			.equipment_logo{
				position: absolute;
				left: 0;
				top: 0;
				width: 125rpx;
				height: 45rpx;
			}
410 411
		}
		.title{
zhengxiuming's avatar
zhengxiuming committed
412
			height: 76rpx;
413 414 415 416
			line-height: 38rpx;
			font-size: 26rpx;
			color: #212121;
			width: 100%;
zhengxiuming's avatar
zhengxiuming committed
417 418 419
			display: -webkit-box;
			-webkit-box-orient: vertical;
			-webkit-line-clamp: 2;
420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437
			overflow: hidden;
			margin-top: 20rpx;
			margin-bottom: 4rpx;
		}
		.sub-title{
			height: 38rpx;
			line-height: 38rpx;
			font-size: 26rpx;
			color: #7C7C7C;
			width: 100%;
			overflow: hidden;
			text-overflow: ellipsis;
			white-space: nowrap;
		}
		.price{
			height: 44rpx;
			line-height: 44rpx;
			font-size: 32rpx;
王建威's avatar
王建威 committed
438
			color: #AE8A57;
439 440 441
			.price-tips{
				font-size: 26rpx;
			}
王建威's avatar
王建威 committed
442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460
			.discount {
				display: inline-block;
				padding: 0 14rpx;
				height: 28rpx;
				line-height: 28rpx;
				text-align: center;
				background:rgba(254,244,232,1);
				color: #AE8A57;
				font-size: 20rpx;
				margin-left: 8px;
				position: relative;
				top: -4rpx;
			}
		}
		.origin_price {
			color: #aeaeae;
			font-size: 24rpx;
			line-height: 34rpx;
			text-decoration: line-through;
461 462 463 464 465 466 467 468 469 470 471 472 473 474 475
		}
		.old-price{
			height: 34rpx;
			line-height: 34rpx;
			text-align: left;
			font-size: 24rpx;
			color: #AEAEAE;
			text-decoration: line-through;
			.price-tips{
				font-size: 24rpx;
			}
		}
		.cart-icon{
			position: absolute;
			right: 24rpx;
王建威's avatar
王建威 committed
476 477
			bottom: 72rpx;
			color: #7C7C7C;
478 479 480
		}
	}
}
郑秀明's avatar
郑秀明 committed
481 482 483
.unlogin_price{
	font-size: 30rpx;
}
484 485

</style>