Files
learning-system-mobile/pages/plus/addQuestion.vue
2022-05-29 18:59:24 +08:00

215 lines
4.6 KiB
Vue

<template>
<!--添加文章-->
<view style="background-color: #fff;">
<u-toast ref="messager"></u-toast>
<!-- <page-title :showBack="true">提问题</page-title> -->
<view style="background-color: #fff;padding-top: 18rpx;">
<view class="bar-box">
<view class="bar-cancel" @click="toBack()">取消</view>
<!-- <view class="bar-center">提问题</view> -->
<view @click="goSubmit()" class="bar-go">提交</view>
</view>
<view class="content">
<view class="big-box-content">
<view class="row row-lin">
<u--input placeholder="请输入标题" placeholder-style="font-size:42upx;color:#c1c1c1;font-weight: normal;" maxlength="30" class="row-input" border="surround" v-model="qa.title" @change="change"></u--input>
</view>
<view class="row ">
<u--textarea class="row-input row-text" placeholder-style="font-size:42upx;color:#c1c1c1;font-weight: normal;" :height="300" count maxlength="500" v-model="qa.content" placeholder="请输入正文"></u--textarea>
</view>
<view class="row">
<u-upload uploadIcon="plus" :fileList="fileList" multiple @afterRead="afterRead" @delete="deletePic" name="coverImg" :maxCount="1">
</u-upload>
</view>
</view>
</view>
</view>
<!-- <view style="margin-top: 20px;">
<view>
<u-button type="primary" text="提交问题"></u-button>
</view>
</view> -->
</view>
</template>
<script>
import apiQa from '@/api/modules/qa.js'
import uploadUtil from '@/utils/upload.js'
export default {
data() {
return {
fileUrl:this.$config.fileUrl,
qa:{
id:'',
title:'',
content:'',
images:''
},
fileList: [],
}
},
methods: {
toBack(){
uni.navigateBack();
},
goSubmit() {
let images=[];
this.fileList.forEach(file=>{
images.push(file.path);
})
this.qa.images=images.join();
uni.showLoading({title:'提交中...'})
apiQa.save(this.qa).then(rs=>{
if(rs.status==200){
this.$refs.messager.show({message:'提交成功',type:'success'});
uni.redirectTo({
url:'/pages/resource/qaDetail?id='+rs.result.id
})
}else{
this.$refs.messager.show({message:rs.message,type:'error'});
setTimeout(function(){uni.hideLoading()},1000);
}
})
},
change(e) {
//console.log('change', e);
},
//删除图片
deletePic(event) {
this.fileList.splice(event.index, 1);
},
//新增图片
async afterRead(event) {
//当设置 mutiple 为 true 时, file 为数组格式,否则为对象格式
//console.log(event.file);
let $this=this;
event.file.forEach(img=>{
uploadUtil.uploadFile(img.url).then(rs=>{
//console.log(rs);
let item={
status: 'success',
message: '已上传',
path:rs.result.filePath,
url:rs.result.httpPath
}
this.fileList.push(item)
uni.hideLoading();
});
})
},
reverse() {
uni.navigateBack({
url: '/pages/plus/index'
})
}
}
}
</script>
<style lang="scss" scoped>
.sub-box{
padding: 20rpx;
.sub-success{
.sub-title{
font-size: 40rpx;
font-weight: 500;
line-height: 45rpx;
margin-bottom: 10rpx;
padding: 20rpx;
}
.sub-text{
font-size: 30rpx;
line-height: 30rpx;
margin-bottom: 20rpx;
padding: 20rpx;
}
.sub-bar{
display: flex;
justify-content: space-between;
padding: 20rpx;
border-bottom: 2rpx solid #ccc;
.bar-time{
font-size: 26rpx;
color: #ccc;
}
}
.bar-reply{
text-align: center;
padding: 30rpx;
.field-icon{
display: block;
width: 40rpx;
margin: 0 auto;
}
}
.bar-cor{
height: 20rpx;
background-color: #ebebeb;
}
.bar-bon{
text-align: center;
min-height: 600rpx;
margin-top: 35rpx;
.bon-icon{
display: inline-block;
}
.bon-text{
display: inline-block;
margin-right: 10rpx;
}
}
}
}
.bar-box{
display: flex;
margin: 18rpx;
justify-content: space-between;
// position: relative;
.bar-cancel{
font-size: 32upx;
color: #7F7F7F;
font-family: Source Han Sans CN;
line-height: 36rpx;
}
.bar-center{
font-size: 36upx;
font-weight: 600;
color: #0D0D0D;
}
.bar-go{
// position: absolute;
// right: 18rpx;
color: #588AFC;
font-size: 30rpx;
font-family: Source Han Sans CN;
font-weight: bold;
line-height: 36rpx;
}
}
.row {
margin-bottom: 10rpx;
.row-input{
border: none;
}
}
.row-lin{
// border-top: 1px solid #eee;
border-bottom: 1px solid #eee;
}
.btn {
padding: 0px;
}
</style>