courseComment.vue 3.9 KB
<template>
	<!-- 评论 -->
	<view class="course_comment">
		<view class="comment_content">
			<textarea v-model="content" placeholder="请输入评论内容,最多1000字" @input="entercomment" />

			<!-- 字数 -->
			<view class="word_num">{{content.length}}/1000</view>
			<view v-if="addpic">
				<!-- 添加图片 -->
				<view class="add_pic layer_star"  @click="uploadpic">
					<image src="../../static/tupian_icon@2x.png" mode="widthFix"></image>
					<view class="add_word">添加图片</view>
				</view>
				
			</view>
			
			<view class="picbox" v-else>
				<!-- 上传的图片 -->
				<view class="upload_pic" @click="uploadImg()">
					<image :src="image==''?img:image" mode="widthFix"></image>
				</view>
			</view>
		</view>
		
		
		
		<!-- 按钮 -->
		<view class="send_wrap" @click="send">
			<view class="send_box">发送</view>
		</view>
		
	</view>
</template>

<script>
	import app from "../../App.vue";
	export default {
		data() {
			return {
				content:"",
				img:"../../static/addpic.png",
				addpic:true,
				image:'',
				cimage:'',
				// 打卡记录id
				clock_log_id:'',
				//评论父级id
				comments_id:'',
				courseid:''
			}
		},
		methods: {
			// 输入评论内容
			entercomment(e){
				this.content=e.detail.value
			},
			uploadpic(){
				console.log(3874273487)
				this.addpic=false
			},
			// 上传图片
			
			uploadImg() {
			   let that = this;
			   uni.chooseImage({
			     count: 1,
			     sizeType: ['original', 'compressed'],
			     success: function (res) {
			       console.log(res.tempFilePaths[0])
			       app.upload('image', res.tempFilePaths[0],"post").then((res) => {
			         console.log('上传文件', res);
			         that.image=res.url
			          that.cimage=res.kurl
			       
							   
							   
			       }).catch((err) => {
			         console.log(err)
			       })
			     },
			     fail: function (res) { }
			   })
			 },
			 
			 //发送
			 send(){
				 let that = this;
				    var url = '/api/comments/commit';
				    var params = {
					  clock_log_id:that.clock_log_id,
				      comments_id: that.comments_id,
				     content:that.content,
					 images:that.image
				    }
				    app.post(url, params).then((res) => {
				      console.log(res);
						uni.showToast({
							title:'提交成功',
							icon:'none'
						})
				     setTimeout(function(){
						 uni.navigateTo({
						 	url:'/pages/course/courseDetail?id='+that.courseid
						 })
					 })
				    }).catch((err) => {
						
				    }) 
			 }
		},
		
		onLoad(options) {
			console.log(options)
			this.clock_log_id=options.id,
			this.courseid=options.courseid
		}
	}
</script>

<style lang="scss">
	page{
		background-color: #fafbfd;
	}
	.picbox{
		margin-top:85rpx;
	}
	.course_comment{
		padding: 36upx 32upx 150upx;
		// 信息
		.comment_content{
			position: relative;
			border:2upx solid rgba(189,196,206,1);
			padding: 26upx 28upx 50upx;
			background-color: #fff;
			textarea{
				width: 100%;
				
				
				
				box-sizing: border-box;
				height: 500upx;
			}
			// 添加图片
			.add_pic{
				position: absolute;
				left: 26upx;
				bottom: 14upx;
				image{
					width: 36upx;
					margin-right: 12upx;
				}
				.add_word{
					color: #3D444D;
					font-size: 24upx;
					border-bottom: 1px solid #000;
				}
			}
			// 字数
			.word_num{
				position: absolute;
				right: 26upx;
				top: 530upx;
				color: #3D444D;
				font-size: 24upx;
			}
		}
		// 上传的图片
		.upload_pic{
			width:200upx;
			height:200upx;
			font-size:0;
			
			
		}
		// 按钮
		.send_wrap{
			width: 100%;
			position: fixed;
			left: 0;
			padding-bottom: 36upx;
			bottom:0;
			left:0;
			display:flex;
			justify-content: center;
			background: #fff;
			.send_box{
				width:686upx;
				margin: 0 32upx;
				height: 96upx;
				text-align: center;
				line-height: 96upx;
				border-radius: 48upx;
				color: #fff;
				background-color: #EE8B27;
				font-size: 28upx;
				
			}
			
		}
		
	}
</style>