bigShots.vue 8.5 KB
<template>
	<view class="bigShots">
		<view class="bigShots-1">
			<view class="bigShots-1-1">
				<view @tap="tabsClick(BIGSHOTS.VIDEOLESSONS)" :class="{'bigShots-1-1-i': true, 'bigShots-1-1-is': type === BIGSHOTS.VIDEOLESSONS}">视频课程</view>
				<view @tap="tabsClick(BIGSHOTS.AUDIOLESSONS)" :class="{'bigShots-1-1-i': true, 'bigShots-1-1-is': type === BIGSHOTS.AUDIOLESSONS}">音频课程</view>
			</view>
			<view class="bigShots-1-2">
				<picker @change="bindpickerChange" :range="subjectList" range-key="title">
					<view class="bigShots-1-2-i">
						<text class="bigShots-1-2-i-t">{{ selectType.name || '请选择分类' }} </text>
						<u-icon size="10" name="arrow-down-fill" color="#646464"></u-icon>
					</view>
				</picker>
				<view class="bigShots-1-2-i" @click="setSorting(SORTINGTYPE.COMMENT)">
					<text class="bigShots-1-2-i-t" v-if="currentSorting !== SORTINGTYPE.COMMENT">评论量</text>
					<text class="bigShots-1-2-i-t" v-else style="color: #2d81ff;">评论量</text>
					
					<u-icon size="10" v-if="sortLog[SORTINGTYPE.COMMENT] !== SORTORDER.DESC" name="arrow-down-fill" :color="currentSorting !== SORTINGTYPE.COMMENT ? '#646464' : '#2d81ff'"></u-icon>
					<u-icon size="10" v-else name="arrow-up-fill" :color="currentSorting !== SORTINGTYPE.COMMENT ? '#646464' : '#2d81ff'"></u-icon>
				</view>
				<view class="bigShots-1-2-i" @click="setSorting(SORTINGTYPE.LIKECOUNT)">
					<text class="bigShots-1-2-i-t" v-if="currentSorting !== SORTINGTYPE.LIKECOUNT">点赞量</text>
					<text class="bigShots-1-2-i-t" v-else style="color: #2d81ff;">点赞量</text>
					
					<u-icon size="10" v-if="sortLog[SORTINGTYPE.LIKECOUNT] !== SORTORDER.DESC" name="arrow-down-fill" :color="currentSorting !== SORTINGTYPE.LIKECOUNT ? '#646464' : '#2d81ff'"></u-icon>
					<u-icon size="10" v-else name="arrow-up-fill" :color="currentSorting !== SORTINGTYPE.LIKECOUNT ? '#646464' : '#2d81ff'"></u-icon>
				</view>
			</view>
		</view>
		<view class="bigShots-2">
			<view class="bigShots-2-i" v-for="item in list" :key="item.id" @click="toBigShotsDetails(item)">
				<view class="bigShots-2-i-l">
					<image class="bigShots-2-i-l-i" :src="item.cover"></image>
				</view>
				<view class="bigShots-2-i-r">
					<view class="bigShots-2-i-r-1">{{ item.name }}</view>
					<view class="bigShots-2-i-r-2">
						<view class="bigShots-2-i-r-2-i">
							<image class="bigShots-2-i-r-2-i-l" src="@/static/imagesV2/icon44.png" mode="widthFix"></image>
							<text class="bigShots-2-i-r-2-i-t">{{ item.comment_count }}</text>
						</view>
						<view class="bigShots-2-i-r-2-i">
							<image class="bigShots-2-i-r-2-i-l" src="@/static/imagesV2/icon45.png" mode="widthFix"></image>
							<text class="bigShots-2-i-r-2-i-t">{{ item.up_count }}</text>
						</view>
					</view>
				</view>
			</view>
			<u-loadmore :status="status" v-if="!notData"/>
			<u-empty
				v-if="notData"
				mode="data"
				text="暂无数据"
				icon="/static/imagesV2/icon24.png"
			>
			</u-empty>
		</view>
	</view>
</template>

<script>
	import { BIGSHOTS } from '@/emit/index.js'
	/**
	 * 排序方式
	 */
	const SORTORDER = {
		/**
		 * 升序
		 * @value asc
		 */
		'ASC': 'asc',
		/**
		 * 降序
		 * @value desc
		 */
		'DESC': 'desc'
	}
	/**
	 * 排序类型
	 */
	const SORTINGTYPE = {
		/**
		 * 评论量
		 * @value 1
		 */
		'COMMENT': 'comment_count',
		/**
		 * 点赞量
		 * @value 2
		 */
		'LIKECOUNT': 'up_count'
	}
	export default {
		watch: {
			type(newVal) {
				this.onRetry()
			}
		},
		data() {
			return {
				SORTINGTYPE,
				BIGSHOTS,
				SORTORDER,
				page: 1,
				sortLog: {
					comment_count: SORTORDER.ASC,
					up_count: SORTORDER.ASC
				},
				currentSorting: '',
				list: [],
				// 加载前值为loadmore,加载中为loading,没有数据为nomore
				status: 'loadmore',
				type: BIGSHOTS.VIDEOLESSONS,
				subjectList: [],
				selectType: {}
			}
		},
		computed: {
			notData() {
				return this.status === 'nomore' && !this.list.length
			}
		},
		onReachBottom() {
			this.getData()
		},
		onShow() {
			this.onRetry()
			this.getClass()
		},
		methods: {
			bindpickerChange(e) {
				this.selectType = this.subjectList[e.detail.value]
				this.onRetry()
			},
			setSorting(type) {
				let result = this.sortLog[type]
				if(result === SORTORDER.ASC) {
					result = SORTORDER.DESC
				} else {
					result = SORTORDER.ASC
				}
				this.sortLog[type] = result
				this.currentSorting = type
				this.onRetry()
			},
			onRetry(){
				this.page=1
				this.list = []
				this.status = 'loadmore'
				this.getData()
			},
			getClass() {
				this.$service.P_get('/course/cate', {}).then(res => {
					console.log(res)
					this.subjectList = res.data.map(item => {
						return {
							title: item.name,
							id: item.id,
							...item
						}
					})
				})
			},
			getData() {
				if(this.status === 'loading' || this.status === 'nomore') return;
				this.status = 'loading';
				uni.showLoading({
					title: '加载中',
					mask: true
				})
				this.$service.P_get('/course', {
					page: this.page,
					order_field: this.currentSorting,
					order_sort: this.currentSorting ? this.sortLog[this.currentSorting] : '',
					cate_id: this.selectType.id || '',
					type: this.type
				}).then(res => {
					uni.hideLoading();
					if (res.code == 1) {
						this.page++;
						this.list = [
							...this.list,
							...res.data.data
						];
						this.status = res.data.data.length < res.data.per_page ? 'nomore' : 'loadmore'
					} else {
						this.status = 'loadmore';
						if (res.msg) {
							uni.showToast({
								icon: 'none',
								title: res.msg
							})
						} else {
							uni.showToast({
								icon: 'none',
								title: '获取数据失败'
							})
						}
					}
				})
			},
			tabsClick(type) {
				this.type = type
			},
			toBigShotsDetails(item) {
				if(item.type === BIGSHOTS.VIDEOLESSONS) {
					uni.navigateTo({
						url: '/pagesStu/bigShotsDetails/bigShotsDetails?id=' + item.id
					})
				} else {
					uni.navigateTo({
						url: '/pagesStu/audioFrequency/audioFrequency?id=' + item.id
					})
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.bigShots{
		.bigShots-1{
			width: 100%;
			position: fixed;
			top: 0;
			background-color: #f3f4f6;
			.bigShots-1-1{
				border-top:1rpx solid #f3f4f6;
				display: flex;
				background: #fff;
				justify-content: space-around;
				.bigShots-1-1-i{
					font-size: 28rpx;
					color: #323232;
					height: 88rpx;
					display: flex;
					align-items: center;
					justify-content: center;
				}
				.bigShots-1-1-is{
					color: #2D81FF;
					position: relative;
					&:before{
						content: '';
						position: absolute;
						bottom: 0;
						left: 50%;
						background-image: url(@/static/imagesV2/icon23.png);
						background-size: 100% 100%;
						transform: translateX(-50%);
						height: 24rpx;
						width: 24rpx;
					}
				}
			}
			.bigShots-1-2{
				color: #646464;
				font-size: 26rpx;
				display: flex;
				height: 85rpx;
				align-items: center;
				padding: 0 25rpx;
				background-color: #f8f8f8;
				.bigShots-1-2-i{
					padding-right: 25rpx;
					display: flex;
					align-items: center;
					.bigShots-1-2-i-t{
						margin-right: 10rpx;
					}
				}
			}
		}
		.bigShots-2{
			padding: 0 25rpx;
			padding-top: calc(88rpx + 85rpx);
			padding-bottom: calc(env(safe-area-inset-bottom) + 30rpx);
			.bigShots-2-i{
				display: flex;
				background: #FFFFFF;
				border-radius: 20rpx;
				padding: 30rpx;
				margin-bottom: 20rpx;
				.bigShots-2-i-l{
					.bigShots-2-i-l-i{
						height: 200rpx;
						width: 150rpx;
						border-radius: 10rpx;
					}
				}
				.bigShots-2-i-r{
					display: flex;
					flex-direction: column;
					justify-content: space-between;
					margin-left: 28rpx;
					.bigShots-2-i-r-1{
						font-size: 30rpx;
						line-height: 45rpx;
					}
					.bigShots-2-i-r-2{
						padding-bottom: 16rpx;
						display: flex;
						.bigShots-2-i-r-2-i{
							display: flex;
							align-items: center;
							line-height: 1.4;
							position: relative;
							margin-right: 18rpx;
							padding-right: 18rpx;
							&:before{
								content: '';
								height: 18rpx;
								border-left: 1rpx solid #E6E6E6;
								position: absolute;
								right: 0;
								top: 50%;
								transform: translateY(-50%);
							}
							&:last-child{
								padding-right: 0;
								margin-right: 0;
								&:before{
									border-left: none;
								}
							}
							.bigShots-2-i-r-2-i-l{
								height: 26rpx;
								width: 26rpx;
							}
							.bigShots-2-i-r-2-i-t{
								font-size: 24rpx;
								margin-left: 8rpx;
								color: #979797;
							}
						}
					}
				}
			}
		}
	}
</style>