logDetail.vue 7.8 KB
<template>
	<view class="log_detail">

		<scroll-view scroll-y="true" style="height: 100vh;" :scroll-with-animation="true">
			<view class="header_box">
				<view class="header">
					<view class="avatar">{{getNameLastTwo(detail.studentName)}}</view>
					<view class="form_name">
						<view class="name">{{overflowHide(detail.studentName, 4)}}</view>
						<view class="week">
							<!-- <text>{{timeFormat(detail.logTime, 'yyyy年')}}</text> -->
							<!-- <text>{{getWeek(detail.logTime)}}</text> -->
							<text>{{getCreatedTime(detail)}}</text>
						</view>
					</view>
					<view class="status" :style="{color:'#909097', backgroundColor:'#EAEAEC'}"
						v-if="detail.status == 'read'">
						<text>已阅</text>
					</view>

					<view class="status" v-else @click="putLog">
						<text>未阅</text>
					</view>
				</view>
			</view>

			<view class="content">
				<view class="name_time">
					<view class="title">{{detail.title}}</view>
					<view class="time">创建时间:{{timeFormat(detail.createdTime)}}</view>
				</view>

				<view class="u-parse">
					<u-parse :content="detail.content"></u-parse>
				</view>

				<view v-if="commentList.length>0" class="reply">
					<view class="title">评论</view>
					<view v-for="(item,index) in commentList" :key="index">
						<view v-if="index!=0" class="divide_line_padding"></view>
						<view class="list">
							<view style="margin-top: 8rpx;" class="userInfo">
								<text> {{item.name?item.name:"佚名"}}</text>
								<text>({{userType[item.userType]}})</text>
							</view>
							<view class="replyTime" style="margin-top: 8rpx;">{{timeFormat(item.createdTime)}}</view>
							<view class="describe" style="margin-top: 8rpx;">{{item.content}}</view>
							<view v-if="false" class="" v-for="(item1,index) in item.replies">
								<view class="reply_bg">
									{{item1}}
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</scroll-view>



		<view class="nextPage">
			<u-icon name="arrow-down" size="36"></u-icon>
		</view>

		<view class="footer">
			<view class="divide_line"></view>
			<input class="uni-input" placeholder="这么精彩,不说点什么吗?" :value="reply" confirm-type="send" @confirm="goReply" />
		</view>
	</view>
</template>

<script>
	import {
		mapGetters,
		mapState,
		mapActions
	} from 'vuex'

	import {
		getLogDetailApi,
		putLogReviewApi,
		getLogReplyListApi,
		postLogReplyApi,
	} from '@/config/api.js';
	export default {
		data() {
			return {
				id: "",
				formLogId: "",
				show: false,
				reply: '',
				content: "",
				style: {
					// 字符串的形式
					p: 'color: red;font-size:32rpx',
					span: 'font-size: 30rpx'
				},
				detail: {},
				userType: {
					"student": "学生",
					"teacher": "学校",
					"company": "企业"
				},
				commentList: [],
			}
		},

		onLoad(option) {

			this.id = option.id;
			getLogDetailApi(option.id).then(data => {
				if (data) {
					this.detail = data
				}
			})

			this.getCommentList()

		},

		methods: {
			getCreatedTime(e) {
				console.log(e)
				let time = this.$u.timeFormat(e.logTime / 1000, 'yyyy/mm/dd');
				if (e.category == "weekly") {
					time = new Date(e.logTime).getFullYear() + "年第" + (this.getWeek(e.logTime) + 1) + "周";
				} else if (e.category == "monthly") {
					time = this.$u.timeFormat(e.logTime / 1000, 'yyyy年mm月');
				}
				return time
			},

			getWeek(dt) {
				if (dt > 0) {
					let d1 = new Date(dt);
					let d2 = new Date(dt);
					d2.setMonth(0);
					d2.setDate(1);
					let rq = d1 - d2;
					let days = Math.ceil(rq / (24 * 60 * 60 * 1000));
					let num = Math.ceil(days / 7);
					return num;
				} else {
					return '';
				}
			},

			getNameLastTwo(value) {

				if (value && value.length > 3) {
					return value.substring(value.length - 3)
				} else {
					return value;
				}
			},

			overflowHide(value, num = 4) {
				if (value && value.length > num) {
					return `${value.slice(0, num)}...`
				} else {
					return value;
				}
			},

			timeFormat(timestamp, format = 'yyyy-mm-dd') {
				return timestamp > 0 ? uni.$u.timeFormat(timestamp, format) : '--'
			},

			putLog() {
				putLogReviewApi({
					ids: [this.id]
				}).then(data => {
					if (data) {
						getLogDetailApi(this.id).then(result => {
							if (result) {
								this.detail = result
							}
						})
					}
				})
			},

			getCommentList() {
				getLogReplyListApi({
					formLogId: this.id
				}).then(data => {
					if (data) {
						this.commentList = data.records;
					}
				})
			},

			goReply(e) { //回复评论
				console.log(e)
				this.reply = e.target.value
				postLogReplyApi({
					formLogId: this.id,
					content: e.target.value
				}).then(data => {
					this.reply = ''
					this.getCommentList()
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.log_detail {
		width: 100%;
		min-height: 100%;
		height: auto;
		background-color: #F7F7F7;

		.nextPage {
			position: fixed;
			bottom: 20vh;
			right: 30rpx;
			background-color: #FFFFFF;
			padding: 12rpx;
			border-radius: 8rpx;
		}

		.header_box {
			background-color: #FFFFFF;

			.header {
				display: flex;
				flex-flow: row nowrap;
				align-items: center;
				padding: 52rpx 0;
				margin: 0 30rpx;
				position: relative;
				border-bottom: 2rpx solid #E2E2E8;
				background-color: #FFFFFF;

				.avatar {
					width: 94rpx;
					height: 94rpx;
					border-radius: 4rpx;
					background-color: #06B079;
					font-size: 24rpx;
					line-height: 94rpx;
					color: #FFFFFF;
					text-align: center;
				}

				.form_name {
					.name {
						font-size: 32rpx;
						line-height: 44rpx;
						color: #202131;
						font-weight: 500;
						margin: 0 20rpx;
					}

					.week {
						padding: 8rpx 0 0 0;
						font-size: 24rpx;
						line-height: 32rpx;
						color: #909097;

						text {
							padding: 8rpx 0 0 20rpx;
						}
					}
				}

				.status {
					font-size: 24rpx;
					line-height: 34rpx;
					color: #FFFFFF;
					width: 112rpx;
					height: 48rpx;
					line-height: 48rpx;
					text-align: center;
					border-radius: 200rpx;
					background-color: #06B079;
					position: absolute;
					top: 74rpx;
					right: 0;
				}
			}
		}

		.content {

			padding: 16rpx 0 150rpx;

			.name_time {
				background-color: #FFFFFF;
				padding: 26rpx 30rpx;

				.title {
					font-size: 36rpx;
					line-height: 50rpx;
					color: #06B079;
				}

				.time {
					padding: 6rpx 0 0 0;
					font-size: 24rpx;
					line-height: 32rpx;
					color: #909097;
					padding: 0 0 26rpx 0;
				}
			}

			.u-parse {
				background-color: #FFFFFF;
				padding: 0 30rpx 50rpx;
				font-size: 28rpx;
				line-height: 36rpx;
				color: #4A4A53;
			}

			.reply {
				background-color: #fff;
				padding: 50rpx 30rpx 150rpx;
				margin: 16rpx 0 0 0;

				.title {
					font-size: 34rpx;
					line-height: 48rpx;
					color: #202131;
				}

				.list {
					padding: 32rpx;
					border-bottom: 2rpx solid #E2E2E8;

					.userInfo {
						color: rgba(0, 0, 0, 0.4500);
						font-size: 28rpx;
						line-height: 40rpx;
					}

					.replyTime {
						color: rgba(0, 0, 0, 0.4500);
						font-size: 26rpx;
						line-height: 36rpx;
					}


				}

				.reply_bg {
					background: rgba(0, 0, 0, 0.03);
					border-radius: 8rpx;
					padding: 20rpx 32rpx;
					margin-top: 16rpx;
				}
			}
		}

	}

	.footer {
		width: 100%;
		height: 130rpx;
		background: #fff;
		position: fixed;
		bottom: 0;
		left: 0;
		z-index: 99;

		.uni-input {
			height: 96rpx;
			background: rgba(0, 0, 0, 0.04);
			border-radius: 8rpx;
			margin: 10rpx 32rpx 32rpx 32rpx;
			padding: 0 20rpx;
		}
	}
</style>