index.vue 9.83 KB
Newer Older
张成 committed
1 2 3 4 5 6 7 8 9 10 11 12 13
<template>
	<view class="page-body">
		<scroll-view class="nav-left" scroll-y :scroll-top="scrollLeftTop" scroll-with-animation>
			<view class="nav-left-item" v-for="item in classifyData" @click="categoryClickMain(item.id)" :key="item.id"
				:class="item.id == categoryId ? 'active' : ''">
				<span>{{ item.name }}</span>
				<view :class="item.id == categoryId ? 'active-line' : ''"></view>
			</view>
		</scroll-view>
		<scroll-view class="nav-right" scroll-y :scroll-top="scrollTop" @scroll="scroll" @touchstart="openScroll"
			scroll-with-animation>
			<view v-for="category in classifyData" :id="category.id" :key="category.id" class="box">
				<view :style="loads" class="right-title">{{ category.name }}</view>
14
				<view class="nav-right-item" v-for="item in category.goods" :key="item.goodsId">
张成 committed
15
					<image src="../../static/imgs/isRecommend.png" v-if="item.isRecommend == 1" class="isRecommend" />
16 17 18
					<image @click="cart(item, category)" class="thumbnail" v-if="item.pics.thumbnailApplet" :src="item.pics.thumbnailApplet" />
					<image @click="cart(item, category)" class="thumbnail" v-else :src="item.pics.thumbnail" />
					<view @click="cart(item, category)" class="info">
张成 committed
19
						<view class="goods-name">{{ item.name }}</view>
weijiguang committed
20
						<view class="tags" v-if="item.tags">
张成 committed
21 22
							<view class="tag-item" v-for="tag in item.tags" :key="tag">{{ tag }}</view>
						</view>
weijiguang committed
23 24
						<view class="desc-box">
							<view class="desc">{{ item.desc || '' }}</view>
张成 committed
25 26
						</view>
						<view class="mon">
weijiguang committed
27 28
							<view class="discount">{{ getSku(item).discount }}</view>
							<view class="price"><text class="num">{{ getSku(item).price }}</text></view>
张成 committed
29 30
						</view>
					</view>
weijiguang committed
31 32
					<u-icon v-if="getSku(item).state==1" class="add" name="plus-circle-fill" color="#2979ff" @click.stop="getallNum(item, category)" size="22"></u-icon>
					<div v-else style="color: orangered;font-size: 22rpx;">已售罄</div>
张成 committed
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
				</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
export default {
	name: 'menuAssembly',
	watch: {},
	data() {
		return {
			classifyData: [],
			categoryId: '',
			categoryPostion: [],
			scrollLeftTop: 0,
			scrollTop: 0,
			scrolled: true

		}
	},
	methods: {
weijiguang committed
55
		getSku(data) {
张成 committed
56
			const { skus } = data;
1  
weijiguang committed
57 58 59
			if (!skus || skus.length == 0) {
				return { discount: data.discount, price: data.price};
			}
weijiguang committed
60 61 62 63 64
			const sku = data.skus.find(v => v.isDefault == 1 && v.state == 1)
			|| data.skus.find(v => v.state == 1)
			|| data.skus.find(v => v.isDefault == 1)
			|| data.skus[0];
			return sku;
张成 committed
65 66 67
		},
		createList(data) {
			this.classifyData = data;
1  
weijiguang committed
68
			// console.log(this.classifyData)
张成 committed
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 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 202 203 204 205 206 207 208 209 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 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 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 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410
			this.$nextTick(() => {
				const query = uni.createSelectorQuery().in(this);
				query.selectAll('.box').boundingClientRect(data => {
					this.categoryPostion = data
				}).exec();
			})
		},
		getallNum(item, category) {
			this.$emit('getallNum', item, category)
		},
		openScroll() {
			this.scrolled = true
		},
		scroll(e) {
			if (!this.scrolled) return;
			const { categoryPostion } = this;
			const [el] = categoryPostion.filter(item => item.top - e.target.scrollTop >= 20);
			if (el) this.categoryId = el.id
		},
		categoryClickMain(id) {
			this.scrolled = false
			this.categoryId = id;
			this.categoryPostion.forEach(item => {
				if (item.id == id) {
					this.scrollTop = item.top - 320
				}
			});

		},
		cart: (item, category) => {
			uni.setStorageSync('goodsInfo', JSON.stringify({ ...item, category }));
			uni.navigateTo({ url: '/menuSubPackage/pages/goodsDetail/goodsDetail' })
		}
	}
}
</script>


<style lang="scss" scoped>
.menu-box {
	min-height: 100vh;

	.shop-info {
		position: absolute;
		left: 32rpx;
		color: #FFFFFF;

		.shop-box {
			min-width: 300rpx;
			font-size: 28rpx;
			font-family: PingFangSC-Semibold, PingFang SC;
			font-weight: 600;
			display: flex;

			.shop-name {
				flex: 1;
			}

			.arrow-right-select {
				width: 9rpx;
			}
		}

		.distance {
			height: 46rpx;
			font-size: 24rpx;
			font-family: PingFangSC-Regular, PingFang SC;
			font-weight: 400;
			color: #FFFFFF;
			line-height: 42rpx;
		}
	}
}

.menu-banner {
	height: 376rpx;
	position: relative;

	image {
		width: 100%;
		height: 376rpx;
	}

	.login-area {
		display: flex;
		width: 624rpx;
		height: 88rpx;
		padding: 20rpx 22rpx;
		background: rgba(255, 255, 255, 0.2);
		box-shadow: 0rpx 4rpx 6rpx 0rpx rgba(0, 0, 0, 0.1);
		border-radius: 10rpx;
		backdrop-filter: blur(10rpx);
		position: absolute;
		z-index: 1;
		bottom: 0;
		left: 64rpx;
		box-sizing: border-box;

		.avatar {
			display: flex;
			justify-items: center;
			align-items: center;
			background: red;
			width: 50rpx;
			height: 48rpx;
			margin-right: 22rpx;
			box-shadow: 0rpx 4rpx 8rpx 0rpx rgba(50, 50, 50, 0.25);
			border-radius: 4rpx;

			image {
				width: 100%;
				height: 100%;
			}

			;
		}

		.user-info {
			flex: 1;

			.user-name {
				height: 28rpx;
				font-size: 20rpx;
				font-family: ArialMT;
				color: #FFFFFF;
				line-height: 22rpx;
			}

			.dialog {
				display: flex;
				height: 22rpx;
				font-size: 16rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #FFFFFF;
				line-height: 22rpx;

				.content {
					flex: 1;
				}

				.arrow {
					width: 10rpx;
					height: 12px;
					display: flex;
					font-size: 20rpx;
					justify-content: center;
					align-items: center;
				}
			}
		}

		.login-btn {
			//  width: 114rpx;
			height: 48rpx;
			background: #006ECF;
			border-radius: 4rpx;
			font-size: 20rpx;
			font-family: PingFangSC-Medium, PingFang SC;
			font-weight: 500;
			color: #FFFFFF;
			line-height: 48rpx;
			text-align: center;
		}

	}
}

.order-banner {
	width: 686rpx;
	height: 179rpx;
	background: #FFFFFF;
	box-shadow: 0rpx 4rpx 8rpx 0rpx rgba(166, 166, 166, 0.5);
	border-radius: 10rpx;
	box-sizing: border-box;
	position: relative;
	left: 32rpx;
	top: -8rpx;
	z-index: 1;
	display: flex;

	.info {
		padding-left: 32rpx;
		flex: 1;

		.first {
			height: 44rpx;
			font-size: 32rpx;
			font-family: PingFangSC-Semibold, PingFang SC;
			font-weight: 600;
			color: #323232;
			line-height: 44rpx;
			margin-top: 40rpx;
		}

		.second {
			margin-top: 20rpx;
			height: 34rpx;
			font-size: 24rpx;
			font-family: PingFangSC-Medium, PingFang SC;
			font-weight: 500;
			color: #323232;
			line-height: 34rpx;

			.time {
				font-size: 28rpx;
				font-family: Arial-BoldMT, Arial;
				font-weight: normal;
				color: #006ECF;
				margin: 0 16rpx;
			}
		}
	}

	.line {
		width: 0;
		height: 104rpx;
		border-right: 4rpx solid #006ECF;
		position: absolute;
		right: 188rpx;
		top: 36rpx;
	}

	.barCode-box {
		margin-top: 30rpx;
		width: 150rpx;
		height: 122rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		text-align: center;
		flex-direction: column;

		.barCode {
			width: 86rpx;
			height: 86rpx;
			background: #006ECF;

			image {
				width: 100%;
				height: 100%;
			}
		}

		.barCode-dis {
			text-align: center;
			margin-top: 14rpx;
			font-size: 16rpx;
			font-family: PingFangSC-Medium, PingFang SC;
			font-weight: 500;
			color: #666666;
			line-height: 22rpx;
		}
	}
}

.page-body {
	display: flex;
	background: #fff;
	overflow: hidden;
}

.nav {
	display: flex;
	width: 100%;
}

.nav-left {
	width: 152rpx;
	background: #fff;
	border-right: 2rpx solid #D5D5D5;
	height: calc(100vh - 376rpx);
	overflow: auto;
}

.nav-left-item {
	position: relative;
	height: 170rpx;
	line-height: 170rpx;
	font-size: 24rpx;
	font-family: PingFangSC-Regular, PingFang SC;
	font-weight: 400;
	color: #666666;
	display: flex;
	align-items: center;
	justify-content: center;
}

.nav-left-item:last-child {
	border-bottom: none;
}

.nav-right {
	height: calc(100vh - 376rpx);
	overflow: auto;
	box-sizing: border-box;
	padding-top: 30rpx;
	width: 596rpx;
}

.box {
	display: block;
	overflow: hidden;
	/* min-height: 100vh; */
	/*若您的子分类过少想使得每个子分类占满屏请放开上边注视 */
}

.box:last-child {
	border: none;
	// min-height: 100vh;
}

.right-title {
	padding-left: 28rpx;
	margin-bottom: 40rpx;
	height: 44rpx;
	font-size: 32rpx;
	font-family: PingFangSC-Semibold, PingFang SC;
	font-weight: 600;
	color: #000000;
	line-height: 44rpx;
}

.nav-right-item {
	display: flex;
	padding: 0rpx 36rpx 0rpx 42rpx;
	margin-bottom: 50rpx;
	height: 162rpx;
	background: #fff;
	position: relative;

	.thumbnail {
		//缩略图
		display: flex;
		align-items: center;
		width: 140rpx;
		height: 140rpx;
		margin-right: 34rpx;
	}

	.info {
		flex: 1;
weijiguang committed
411
	
张成 committed
412 413 414 415 416 417
		.goods-name {
			font-size: 28rpx;
			font-family: PingFangSC-Medium, PingFang SC;
			font-weight: 500;
			color: #000000;
		}
weijiguang committed
418
	
张成 committed
419 420 421 422 423 424 425 426 427 428 429 430 431 432
		.tags {
			.tag-item {
				height: 24rpx;
				border-radius: 4rpx;
				border: 2rpx solid #006ECF;
				margin-right: 10rpx;
				padding: 4rpx 6rpx;
				font-size: 16rpx;
				font-family: ArialMT;
				color: #006ECF;
				line-height: 24rpx;
				display: inline-block;
			}
		}
weijiguang committed
433 434
	
		.desc-box {
张成 committed
435 436 437 438 439 440
			display: flex;
			font-size: 20rpx;
			font-family: PingFangSC-Regular, PingFang SC;
			font-weight: 400;
			color: #666666;
			line-height: 40rpx;
weijiguang committed
441 442
	
			.desc {
张成 committed
443 444 445
				flex: 1;
			}
		}
weijiguang committed
446
	
张成 committed
447 448 449 450 451 452 453 454 455 456
		.mon {
			.discount {
				display: inline-block;
				height: 32rpx;
				font-size: 24rpx;
				font-family: Arial-BoldMT, Arial;
				color: #EB5F17;
				line-height: 32rpx;
				margin-right: 6rpx;
			}
weijiguang committed
457
	
张成 committed
458
			.price {
weijiguang committed
459
				flex: 1;
张成 committed
460 461 462 463 464 465
				display: inline-block;
				height: 22rpx;
				font-size: 20rpx;
				font-family: ArialMT;
				color: #666666;
				line-height: 22rpx;
weijiguang committed
466
	
张成 committed
467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511
				.num {
					text-decoration: line-through;
				}
			}
		}
	}

	.isRecommend {
		position: absolute;
		width: 30rpx;
		height: 30rpx;
		top: 10rpx;
		left: 50rpx
	}
}

.nav-right-item image {
	width: 150rpx;
	height: 150rpx;
}

.active {
	font-weight: 600;
	color: #000000;
	background: #fff;
}

.active-line {
	height: 170rpx;
	width: 2rpx;
	position: absolute;
	right: -2rpx;
	top: 0;
	z-index: 1;
	border-right: 8rpx solid #006ECF;
	;
}

::-webkit-scrollbar {
	/*取消小程序的默认导航条样式*/
	width: 0;
	height: 0;
	color: transparent;
}
</style>