myQuestion.vue 6.2 KB
<template>
	<view class="myQuestion">
		<view class="myQuestion-1">
			<view @click="switchItem(MYQUESTIONTYPE.ANSWERED)" :class="{'myQuestion-i': true, 'myQuestion-is': type === MYQUESTIONTYPE.ANSWERED}">已解答</view>
			<view @click="switchItem(MYQUESTIONTYPE.UNANSWERED)" :class="{'myQuestion-i': true, 'myQuestion-is': type === MYQUESTIONTYPE.UNANSWERED}">未解答</view>
		</view>
		<view class="myQuestion-2">
			<view class="myQuestion-2-i"  v-for="d in list" :key="d.id" @click="toAnswerDetails(d)">
				<view class="myQuestion-2-i-1">
					<view class="myQuestion-2-i-1-l">
						<view class="myQuestion-2-i-1-l-i">
							<image :src="d.img || '/static/images/tx.png'" mode="widthFix"></image>
						</view>
					</view>
					<view class="myQuestion-2-i-1-r">
						<view class="myQuestion-2-i-1-r-1">{{d.name}}</view>
						<view class="myQuestion-2-i-1-r-2">{{d.create_time}}发布</view>
					</view>
				</view>
				<view class="myQuestion-2-i-2">
					{{d.question}}
				</view>
				<view class="myQuestion-2-i-4" v-if="d.imgs && d.imgs.length">
					<u--image
						v-for="(item, index) in d.imgs"
						:key="index"
						radius="15rpx"
						height="145rpx"
						width="145rpx"
						@click.stop="seeImg(d.imgs, index)"
						:src="item"></u--image>
				</view>
				<view class="myQuestion-2-i-3">
					<view class="myQuestion-2-i-3-l">
						<view class="myQuestion-2-i-3-l-1" v-if="type === MYQUESTIONTYPE.ANSWERED">已解答</view>
						<view class="myQuestion-2-i-3-l-1 myQuestion-2-i-3-l-1s" v-else>未解答</view>
						<view class="myQuestion-2-i-3-l-t">{{d.tname}}</view>
					</view>
					<view class="myQuestion-2-i-3-r">
						{{d.answer_time || ''}}
					</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>
</template>

<script>
	import { MYQUESTIONTYPE } from "@/emit/index.js"
	export default {
		components: {
		},
		data() {
			return {
				MYQUESTIONTYPE,
				type: MYQUESTIONTYPE.ANSWERED,
				page: 1,
				list: [],
				// 加载前值为loadmore,加载中为loading,没有数据为nomore
				status: 'loadmore'
			}
		},
		onLoad() {
			this.onRetry()
		},
		onReachBottom() {
			this.getData()
		},
		methods: {
			toAnswerDetails(data) {
				uni.navigateTo({
					url: '/pagesStu/answerDetails/answerDetails?id=' + data.id
				})
			},
			// 切换tab
			switchItem(type) {
				this.type = type
				this.onRetry();
			},
			seeImg(urls, current = 0) {
				uni.previewImage({
				    current, // 当前显示图片的链接,不填则默认为 urls 的第一张图片
				    urls // 需要预览的图片链接列表
				})
			},
			onRetry(){
				this.page= 1;
				this.list = [];
				this.status = 'loadmore';
				this.getData()
			},
			getData() {
				if(this.status === 'loading' || this.status === 'nomore') return;
				this.status = 'loading';
				uni.showLoading({
					title: '加载中',
					mask: true
				})
				this.$service.P_get('/question/my', {
					page: this.page,
					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: '获取数据失败'
							})
						}
					}
					
					
				}).catch(e => {
					this.status = 'loadmore';
					uni.hideLoading()
					uni.showToast({
						icon: 'none',
						title: '获取数据失败,请检查您的网络连接'
					})
				})
			}
			
		}
	}
</script>

<style lang="scss" scoped>
.myQuestion{
	.myQuestion-1{
		position: absolute;
		top: 0;
		border-top:1rpx solid #f3f4f6;
		display: flex;
		background: #fff;
		justify-content: space-around;
		width: 100%;
		.myQuestion-i{
			font-size: 28rpx;
			color: #323232;
			height: 88rpx;
			display: flex;
			align-items: center;
			justify-content: center;
		}
		.myQuestion-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;
			}
		}
	}
	.myQuestion-2{
		padding: 20rpx 25rpx;
		width: 100%;
		padding-top: calc(88rpx + 20rpx);
		.myQuestion-2-i{
			padding: 30rpx;
			background-color: #FFFFFF;
			box-sizing: border-box;
			border-radius: 20rpx;
			margin-bottom: 20rpx;
			.myQuestion-2-i-1{
				display: flex;
				align-items: center;
				.myQuestion-2-i-1-l{
					.myQuestion-2-i-1-l-i{
						height: 60rpx;
						width: 60rpx;
						border-radius: 50%;
						overflow: hidden;
					}
				}
				.myQuestion-2-i-1-r{
					margin-left: 30rpx;
					.myQuestion-2-i-1-r-1{
						font-size: 26rpx;
						color: #323232;
						font-weight: bold;
					}
					.myQuestion-2-i-1-r-2{
						font-size: 24rpx;
						color: #979797;
						margin-top: 5rpx;
					}
				}
			}
			.myQuestion-2-i-2{
				line-height: 39rpx;
				color: #323232;
				font-size: 26rpx;
				margin: 30rpx 0;
			}
		}
	}
	.myQuestion-2-i-3{
		padding-top: 20rpx;
		border-top: 1rpx solid #F3F3F7;
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-top: 20rpx;
		.myQuestion-2-i-3-l{
			display: flex;
			.myQuestion-2-i-3-l-1{
				border-radius: 20rpx 20rpx 0px 20rpx;
				height: 40rpx;
				line-height: 40rpx;
				color: #FFFFFF;
				background: linear-gradient(0deg, #0AC49C 0%, #34D5AA 100%);
				font-size: 22rpx;
				padding: 0 11rpx;
			}
			.myQuestion-2-i-3-l-1s{
				background: linear-gradient(0deg, #BEBEBE 0%, #AAAAAA 100%);
			}
			.myQuestion-2-i-3-l-t{
				font-size: 26rpx;
				color: #323232;
				margin-left: 15rpx;
				font-weight: bold;
			}
		}
		.myQuestion-2-i-3-r{
			font-size: 24rpx;
			color: #979797;
		}
	}
	.myQuestion-2-i-4{
		display: grid;
		grid-template-columns: repeat(4, 1fr);
		grid-row-gap: 20rpx;
		grid-column-gap: 20rpx;
		margin-top: 30rpx;
	}
}
</style>