移动端V1.0
This commit is contained in:
296
pages/questionnaire/fillIn.vue
Normal file
296
pages/questionnaire/fillIn.vue
Normal file
@@ -0,0 +1,296 @@
|
||||
<template>
|
||||
<view class="questionnaire-detail">
|
||||
<view class="title">
|
||||
{{questionnaireDetail.title}}
|
||||
</view>
|
||||
<view class="list">
|
||||
<view class="item" v-for="(question,qIdx) in questionnaireDetail.questions" :key="question.index">
|
||||
<view class="title">
|
||||
{{question.index}}、{{question.name}}
|
||||
<text v-if="question.type == 1">(单选)</text>
|
||||
<text v-if="question.type == 2">(多选)</text>
|
||||
</view>
|
||||
<view class="options" v-if="question.type != 0">
|
||||
<view class="option" v-for="(option,oIdx) in question.options" :key="oIdx"
|
||||
@tap="selectOption(qIdx,oIdx)">
|
||||
<!-- 选项序号 -->
|
||||
<view :class="{active:option.isSelected,option_number:true}">
|
||||
{{getLetter(oIdx)}}
|
||||
</view>
|
||||
<!-- 选项内容 -->
|
||||
<view class="option_text">
|
||||
{{option.content}}
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view v-else>
|
||||
<textarea maxlength="300" @input="textAreaInput"
|
||||
v-model="questionnaireDetail['q_' + qIdx + '_text']" placeholder="请输入内容"
|
||||
placeholder-class="textarea-placeholder"></textarea>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="btns" v-if="navIndex==0">
|
||||
<button @tap="resetAnswer">重置</button>
|
||||
<button @tap="submitForm" :disabled="isSubmitting">提交</button>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import {
|
||||
getQuestionnaire,
|
||||
addAnswer,
|
||||
updateAnswer
|
||||
} from '@/api/questionnaire/questionnaire.js';
|
||||
import {
|
||||
toBackPage
|
||||
} from "@/utils/toBack.js"
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
isSubmitting: false, //表单提交标志位
|
||||
questionnaireDetail: {},
|
||||
questionnaireId: "", //问卷id
|
||||
targetId: "", //目标id
|
||||
navIndex:""
|
||||
}
|
||||
},
|
||||
onLoad(option) {
|
||||
this.targetId = option.teacherId;
|
||||
this.questionnaireId = option.id;
|
||||
this.navIndex=option.navIndex;
|
||||
this.getquestionnaireDetail();
|
||||
if(this.navIndex==1){
|
||||
uni.setNavigationBarTitle({
|
||||
title:"问卷详情"
|
||||
})
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
getquestionnaireDetail() {
|
||||
getQuestionnaire({
|
||||
questionnaireId: this.questionnaireId,
|
||||
targetId: this.targetId
|
||||
}).then(res => {
|
||||
if (res.code == 200 && res.data) {
|
||||
let data = {};
|
||||
Object.assign(data, {
|
||||
questions: JSON.parse(res.data.questions),
|
||||
title: res.data.title,
|
||||
id: res.data.id
|
||||
});
|
||||
this.questionnaireDetail = data;
|
||||
console.log(data);
|
||||
this.transPaperDefault();
|
||||
}
|
||||
})
|
||||
},
|
||||
/**
|
||||
* questionIndxe: 题目的index
|
||||
* optionIndex:题目选项的index
|
||||
*/
|
||||
selectOption(questionIndxe, optionIndex) {
|
||||
// 获取题目
|
||||
let questions = this.questionnaireDetail.questions[questionIndxe];
|
||||
|
||||
if (questions.type == 1) {
|
||||
//单选题
|
||||
let isSelected = this.questionnaireDetail.questions[questionIndxe].options[optionIndex].isSelected;
|
||||
if (isSelected) {
|
||||
this.questionnaireDetail.questions[questionIndxe].options[optionIndex].isSelected = 0;
|
||||
} else {
|
||||
this.questionnaireDetail.questions[questionIndxe].options[optionIndex].isSelected = 1;
|
||||
}
|
||||
for (let i = 0; i < this.questionnaireDetail.questions[questionIndxe].options.length; i++) {
|
||||
if (i != optionIndex) {
|
||||
|
||||
if (this.questionnaireDetail.questions[questionIndxe].options[optionIndex].isSelected) {
|
||||
this.questionnaireDetail.questions[questionIndxe].options[i].isSelected = 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
this.$forceUpdate();
|
||||
return;
|
||||
}
|
||||
if (questions.type == 2) {
|
||||
let isSelected = this.questionnaireDetail.questions[questionIndxe].options[optionIndex].isSelected;
|
||||
//多选题
|
||||
if (isSelected) {
|
||||
this.questionnaireDetail.questions[questionIndxe].options[optionIndex].isSelected = 0;
|
||||
} else {
|
||||
this.questionnaireDetail.questions[questionIndxe].options[optionIndex].isSelected = 1;
|
||||
}
|
||||
this.$forceUpdate();
|
||||
return;
|
||||
}
|
||||
},
|
||||
//获取大写字母
|
||||
getLetter(index) {
|
||||
return String.fromCharCode(65 + index);
|
||||
},
|
||||
textAreaInput() {
|
||||
this.$forceUpdate();
|
||||
},
|
||||
//辅助重置文本输入框
|
||||
deleteKey() {
|
||||
let needAttr = ['questions', 'title', 'id'];
|
||||
let keys = Object.keys(this.questionnaireDetail);
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
if (!needAttr.includes(keys[i])) {
|
||||
//不包含则删除掉
|
||||
delete this.questionnaireDetail[keys[i]]
|
||||
}
|
||||
}
|
||||
},
|
||||
//重置
|
||||
resetAnswer() {
|
||||
this.deleteKey();
|
||||
for (let i = 0; i < this.questionnaireDetail.questions.length; i++) {
|
||||
let questions = this.questionnaireDetail.questions[i];
|
||||
|
||||
if (questions.type == 1 || questions.type == 2) {
|
||||
//是选择题全部设置为未选择
|
||||
for (let j = 0; j < this.questionnaireDetail.questions[i].options.length; j++) {
|
||||
this.questionnaireDetail.questions[i].options[j].isSelected = 0;
|
||||
}
|
||||
} else {
|
||||
this.questionnaireDetail.questions[i].text = 0;
|
||||
}
|
||||
}
|
||||
this.$forceUpdate();
|
||||
},
|
||||
//把q_xx_text 重新设置回题目中
|
||||
transPaper() {
|
||||
for (let i = 0; i < this.questionnaireDetail.questions.length; i++) {
|
||||
let type = this.questionnaireDetail.questions[i].type;
|
||||
if (type == 0) {
|
||||
this.questionnaireDetail.questions[i].text = this.questionnaireDetail['q_' + i + '_text'];
|
||||
}
|
||||
}
|
||||
},
|
||||
transPaperDefault() {
|
||||
for (let i = 0; i < this.questionnaireDetail.questions.length; i++) {
|
||||
let type = this.questionnaireDetail.questions[i].type;
|
||||
if (type == 0) {
|
||||
this.questionnaireDetail['q_' + i + '_text'] = this.questionnaireDetail.questions[i].text;
|
||||
|
||||
}
|
||||
}
|
||||
},
|
||||
submitForm() {
|
||||
this.transPaper();
|
||||
let data = {};
|
||||
Object.assign(data, {
|
||||
questions: JSON.stringify(this.questionnaireDetail.questions),
|
||||
title: this.questionnaireDetail.title,
|
||||
id: this.questionnaireDetail.id,
|
||||
score: this.questionnaireDetail.score,
|
||||
status: '1'
|
||||
})
|
||||
this.isSubmitting = true; // 设置为正在提交
|
||||
console.log('表单数据',data)
|
||||
updateAnswer(data).then(res => {
|
||||
if (res.code == 200) {
|
||||
uni.showToast({
|
||||
title: "提交成功"
|
||||
})
|
||||
toBackPage(1000, () => {
|
||||
this.isSubmitting = false;
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.questionnaire-detail {
|
||||
padding: 30rpx 30rpx 95rpx;
|
||||
|
||||
&>.title {
|
||||
font-weight: bold;
|
||||
font-size: 40rpx;
|
||||
text-align: center;
|
||||
margin-bottom: 35rpx;
|
||||
}
|
||||
|
||||
.list {
|
||||
.item {
|
||||
.title {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
/* 选项 */
|
||||
.option {
|
||||
display: flex;
|
||||
justify-content: start;
|
||||
gap: 10px;
|
||||
margin: 16px 0;
|
||||
|
||||
.option_number {
|
||||
text-align: center;
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
border-radius: 50%;
|
||||
border: 1px solid #E1EAF4;
|
||||
line-height: 22px;
|
||||
font-size: 14px;
|
||||
color: #646873;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.active {
|
||||
background-color: #409EFF;
|
||||
border: 1px solid #409EFF;
|
||||
color: #fff;
|
||||
}
|
||||
}
|
||||
|
||||
textarea {
|
||||
border: 1px solid #d3d3d3;
|
||||
margin: 40rpx 0;
|
||||
width: 100%;
|
||||
border-radius: 16rpx;
|
||||
padding: 20rpx;
|
||||
color: #202020;
|
||||
opacity: 0.7;
|
||||
height: 80px;
|
||||
|
||||
.textarea-placeholder {
|
||||
color: #202020;
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.btns {
|
||||
padding: 10px;
|
||||
display: flex;
|
||||
background: white;
|
||||
position: fixed;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
z-index: 999;
|
||||
|
||||
button {
|
||||
flex: 1;
|
||||
background-color: #1890FF;
|
||||
color: white;
|
||||
|
||||
&:first-child {
|
||||
margin-right: 10px;
|
||||
background-color: white;
|
||||
border: 1px solid #1890FF;
|
||||
color: #1890FF;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
</style>
|
367
pages/questionnaire/index.vue
Normal file
367
pages/questionnaire/index.vue
Normal file
@@ -0,0 +1,367 @@
|
||||
<template>
|
||||
<view class="questionnaire">
|
||||
<Nav :navs="navs" @change="navChange" />
|
||||
<view class="release-list" v-if="navIndex==0">
|
||||
<view class="search">
|
||||
<uni-search-bar radius="5" placeholder="请输入辅导员名称" bgColor="#ffffff" clearButton="auto"
|
||||
cancelButton="none" v-model="queryParams.teacherName" @confirm="onSearch" @clear="onClear" />
|
||||
</view>
|
||||
<scroll-view scroll-y="true" @scrolltolower="questionnaireListScrolltoLower">
|
||||
<view class="list" v-if="questionnaireList.length>0">
|
||||
<view class="item" v-for="(item,index) in questionnaireList" :key="index">
|
||||
<view class="top">
|
||||
标题:{{item.title}}
|
||||
<uni-icons type="right" size="18" color="#202020"></uni-icons>
|
||||
<view class="fill" @tap="toFill(item)">
|
||||
<uni-icons type="compose" color="#1890FF" size="18"></uni-icons>
|
||||
<text>填写</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="content">
|
||||
<view>辅导员:{{item.teacherName}}</view>
|
||||
<!-- <view class="level">状态:
|
||||
<text :class="item.status==1?'underway':'finish'">{{item.status==1?'进行中':"已结束"}}</text>
|
||||
</view> -->
|
||||
<view class="level">是否填写:
|
||||
<text :class="item.completed==1?'underway':'finish'">{{item.completed==1?'已填写':"未填写"}}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="empty" v-else>
|
||||
<image src="../../static/empty.png" mode="widthFix"></image>
|
||||
暂时没有数据
|
||||
</view>
|
||||
<view class="loading-more-top" v-if="topLoading">
|
||||
<uni-load-more style="padding-top: 90px;" status="loading" />
|
||||
</view>
|
||||
<view class="loading-more" v-if="loading">
|
||||
<uni-load-more status="loading" />
|
||||
</view>
|
||||
<view class="no-more" v-if="!loading&&questionnaireList.length!=0">
|
||||
到底啦~~
|
||||
</view>
|
||||
</scroll-view>
|
||||
</view>
|
||||
<view class="answer-list" v-if="navIndex==1">
|
||||
<view class="search">
|
||||
<uni-search-bar radius="5" placeholder="请输入目标对象名称" bgColor="#ffffff" clearButton="auto"
|
||||
cancelButton="none"/>
|
||||
</view>
|
||||
<scroll-view scroll-y="true" @scrolltolower="answerListScrolltoLower">
|
||||
<view class="list" v-if="answerList.length>0">
|
||||
<view class="item" @tap="toDetail(item)" v-for="(item,index) in answerList" :key="index">
|
||||
<view class="top">
|
||||
标题:{{item.title}}
|
||||
<uni-icons type="right" size="18" color="#202020"></uni-icons>
|
||||
</view>
|
||||
<view class="content">
|
||||
<view>目标对象:{{item.targetName}}</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="empty" v-else>
|
||||
<image src="../../static/empty.png" mode="widthFix"></image>
|
||||
暂时没有数据
|
||||
</view>
|
||||
<view class="loading-more-top" v-if="topLoading">
|
||||
<uni-load-more style="padding-top: 90px;" status="loading" />
|
||||
</view>
|
||||
<view class="loading-more" v-if="loading">
|
||||
<uni-load-more status="loading" />
|
||||
</view>
|
||||
<view class="no-more" v-if="!loading&&answerList.length!=0">
|
||||
到底啦~~
|
||||
</view>
|
||||
</scroll-view>
|
||||
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import Nav from "@/components/navs/navs.vue";
|
||||
import {
|
||||
questionnaireList,
|
||||
answerList
|
||||
} from '@/api/questionnaire/questionnaire.js';
|
||||
export default {
|
||||
components: {
|
||||
Nav
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
loading: false,
|
||||
topLoading: true,
|
||||
navIndex: 0,
|
||||
searchTxt: "", //搜索字段
|
||||
questionnaireList: [],
|
||||
answerList: [],
|
||||
navs: [{
|
||||
text: "问卷调查",
|
||||
val: 0
|
||||
},
|
||||
{
|
||||
text: "填写记录",
|
||||
val: 1
|
||||
}
|
||||
],
|
||||
queryParams: {
|
||||
pageNum: 1,
|
||||
pageSize: 10,
|
||||
teacherName: ""
|
||||
}
|
||||
}
|
||||
},
|
||||
onLoad() {
|
||||
this.getQuestionnaireList();
|
||||
},
|
||||
methods: {
|
||||
navChange(index) {
|
||||
this.navIndex = index;
|
||||
this.queryParams.pageNum = 1;
|
||||
if (index == 1) {
|
||||
this.getAnswerList();
|
||||
} else {
|
||||
this.getQuestionnaireList();
|
||||
}
|
||||
},
|
||||
questionnaireListScrolltoLower() {
|
||||
if (this.queryParams.pageNum < this.totalPages) {
|
||||
this.queryParams.pageNum++;
|
||||
this.loading = true;
|
||||
setTimeout(() => {
|
||||
this.getQuestionnaireList()
|
||||
}, 1000)
|
||||
} else {
|
||||
|
||||
}
|
||||
},
|
||||
answerListScrolltoLower() {
|
||||
if (this.queryParams.pageNum < this.totalPages) {
|
||||
this.queryParams.pageNum++;
|
||||
this.loading = true;
|
||||
setTimeout(() => {
|
||||
this.getAnswerList()
|
||||
}, 1000)
|
||||
}
|
||||
},
|
||||
getQuestionnaireList() {
|
||||
questionnaireList(this.queryParams).then(res => {
|
||||
if (res.code == 200) {
|
||||
this.loading = false;
|
||||
if (this.queryParams.pageNum == 1) {
|
||||
this.questionnaireList = res.rows;
|
||||
} else {
|
||||
this.questionnaireList = this.questionnaireList.concat(res.rows); // 否则追加新数据到列表中
|
||||
}
|
||||
this.totalPages = Math.ceil(res.total / this.queryParams.pageSize);
|
||||
this.topLoading = false;
|
||||
}
|
||||
})
|
||||
},
|
||||
getAnswerList() {
|
||||
answerList(this.queryParams).then(res => {
|
||||
if (res.code == 200) {
|
||||
this.loading = false;
|
||||
if (this.queryParams.pageNum == 1) {
|
||||
this.answerList = res.rows;
|
||||
} else {
|
||||
this.answerList = this.answerList.concat(res.rows); // 否则追加新数据到列表中
|
||||
}
|
||||
this.totalPages = Math.ceil(res.total / this.queryParams.pageSize);
|
||||
this.topLoading = false;
|
||||
}
|
||||
|
||||
})
|
||||
},
|
||||
toFill(item) {
|
||||
uni.navigateTo({
|
||||
url: `./fillIn?id=${item.id}&teacherId=${item.teacherId}&navIndex=0`
|
||||
})
|
||||
},
|
||||
toDetail(item){
|
||||
uni.navigateTo({
|
||||
url: `./fillIn?id=${item.questionnaireId}&teacherId=${item.targetId}&navIndex=1`
|
||||
})
|
||||
},
|
||||
onSearch() {
|
||||
this.queryParams.pageNum = 1;
|
||||
this.getQuestionnaireList();
|
||||
},
|
||||
onClear() {
|
||||
this.queryParams.teacherName = "";
|
||||
this.getQuestionnaireList();
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.questionnaire {
|
||||
background-color: #F5F5F7;
|
||||
height: calc(100vh - 44px);
|
||||
overflow: hidden;
|
||||
box-sizing: border-box;
|
||||
padding: 0 40rpx;
|
||||
padding-top: 60px;
|
||||
/deep/ .navs {
|
||||
text {
|
||||
padding-bottom: 8px;
|
||||
}
|
||||
}
|
||||
|
||||
.empty {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
padding-top: 200rpx;
|
||||
color: #9E9E9E;
|
||||
font-size: 36rpx;
|
||||
|
||||
image {
|
||||
width: 250rpx;
|
||||
margin-bottom: 50rpx;
|
||||
}
|
||||
}
|
||||
.search {
|
||||
box-shadow: 0 0 5px #e6e6e6;
|
||||
position: fixed;
|
||||
top: 100px;
|
||||
z-index: 999;
|
||||
left: 40rpx;
|
||||
right: 40rpx;
|
||||
|
||||
.uni-searchbar {
|
||||
padding: 0;
|
||||
}
|
||||
}
|
||||
scroll-view {
|
||||
padding-top:45px;
|
||||
height: 84vh;
|
||||
.no-more {
|
||||
text-align: center;
|
||||
color: gray;
|
||||
padding-bottom: 10px;
|
||||
}
|
||||
|
||||
.list {
|
||||
.item {
|
||||
background-color: white;
|
||||
margin-bottom: 40rpx;
|
||||
padding: 40rpx;
|
||||
border-radius: 16rpx;
|
||||
position: relative;
|
||||
|
||||
.top {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
border-bottom: 1px solid #F5F5F7;
|
||||
padding-bottom: 20rpx;
|
||||
|
||||
.uni-icons {
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
.fill {
|
||||
position: absolute;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
display: flex;
|
||||
color: #1890FF;
|
||||
border: 1px solid #A3D3FF;
|
||||
background-color: #E8F4FF;
|
||||
padding: 5px 15px;
|
||||
border-radius: 16rpx 0 16rpx 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
.content {
|
||||
padding-top: 20rpx;
|
||||
|
||||
.level {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin-top:15px;
|
||||
text{
|
||||
padding:0;
|
||||
display: inline-block;
|
||||
width:50px;
|
||||
height:20px;
|
||||
text-align: center;
|
||||
line-height: 20px;
|
||||
margin-left: 5px;
|
||||
border-radius: 8rpx;
|
||||
}
|
||||
.underway{
|
||||
background-color: #E7FAF0;
|
||||
color: #71E2A3;
|
||||
border: 1px solid #D0F5E0;
|
||||
}
|
||||
.finish{
|
||||
background-color: #F5F5F7;
|
||||
color: #A7A8AC;
|
||||
border: 1px solid #A7A8AC;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
&>view:not(:last-child) {
|
||||
margin-bottom: 15rpx;
|
||||
|
||||
.progress {
|
||||
color: #1890FF;
|
||||
}
|
||||
}
|
||||
|
||||
.status {
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
right: 0;
|
||||
color: white;
|
||||
|
||||
.status-text {
|
||||
position: absolute;
|
||||
bottom: 15px;
|
||||
right: 8%;
|
||||
font-size: 35rpx;
|
||||
}
|
||||
|
||||
.triangle-right {
|
||||
width: 0;
|
||||
height: 0;
|
||||
/* 上边框设置为透明 */
|
||||
border-left: 120px solid transparent;
|
||||
}
|
||||
|
||||
&.submit {
|
||||
color: #202020;
|
||||
|
||||
.triangle-right {
|
||||
/* 左边框设置为与文本相同的颜色 */
|
||||
border-bottom: 100px solid #D7D7D7;
|
||||
}
|
||||
}
|
||||
|
||||
&.agree {
|
||||
.triangle-right {
|
||||
/* 左边框设置为与文本相同的颜色 */
|
||||
border-bottom: 100px solid #2FB15B;
|
||||
}
|
||||
}
|
||||
|
||||
&.refuse {
|
||||
.triangle-right {
|
||||
/* 左边框设置为与文本相同的颜色 */
|
||||
border-bottom: 100px solid #FF759F;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
</style>
|
Reference in New Issue
Block a user