微信公众号前端模版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

443 lines
19 KiB

<!-- 问题切换版 -->
<template>
<div class="question">
<div class="head">
<van-progress :percentage="questions.length === 0 ? 0 : ((index+1)/questions.length)*100"
:pivot-text="(index+1).toString()"
color="#72b937"
stroke-width="7px"
class="head-progress">
</van-progress>
<div class="head-progress-num">{{ questions.length }}</div>
</div>
<transition mode="out-in">
<div class="card"
v-show="show">
<!-- 题号 -->
<div class="card__head">
<div class="card__head-icon">Q{{ index+1 }}</div>
<div>
<div class="card__head-title">{{ curQuestion.question }}</div>
<div v-if="curQuestion.type === 'input'">
<input v-model="curQuestion.answer"
class="line-input"
max-length="18">
</div>
</div>
</div>
<van-radio-group v-model="curQuestion.answer"
checked-color="#72b937"
v-if="!curQuestion.type">
<van-radio v-if="curQuestion.a"
name="A">A.{{ curQuestion.a }}</van-radio>
<van-radio v-if="curQuestion.b"
name="B">B.{{ curQuestion.b }}</van-radio>
<van-radio v-if="curQuestion.c"
name="C">C.{{ curQuestion.c }}</van-radio>
<van-radio v-if="curQuestion.d"
name="D">D.{{ curQuestion.d }}</van-radio>
<van-radio v-if="curQuestion.e"
name="E">E.{{ curQuestion.e }}</van-radio>
<van-radio v-if="curQuestion.f"
name="F">F.{{ curQuestion.f }}</van-radio>
<van-radio v-if="curQuestion.g"
name="G">G.{{ curQuestion.g }}</van-radio>
</van-radio-group>
<div v-else-if="curQuestion.type === 'text'">
<textarea class="text"
v-model="curQuestion.answer"
rows="6"
maxlength="300"></textarea>
</div>
</div>
</transition>
<div class="footer">
<van-button type="warning"
v-if="index!== 0"
class="footer-btn-prev"
@click="prev">上一题</van-button>
<van-button type="primary"
@click="next"
class="footer-btn-next">{{ nextBtn }}</van-button>
</div>
</div>
</template>
<script>
export default {
name: 'question-list-change',
props: {
params: Object
},
data: function () {
return {
show: true,
index: 0,
curQuestion: {},
questions: [],
}
},
methods: {
submit: function () {
for (var i = 0; i < this.questions.length; i++) {
if (!this.questions[i].answer && this.questions[i].isRequired) {
vant.Toast.fail('请勾选或输入第' + (i + 1) + '的答案')
return
}
}
_that = this
this.show = false
setTimeout(function () {
_that.$emit('change-component', 'end')
_that.api_submit()
}, 200)
},
api_submit: function () {
vant.Toast.loading({ message: '提交中...', forbidClick: true, duration: 20000 })
var o = []
console.log("${openId}")
this.questions.forEach(function (item) {
o.push({ openId: "${openId}", questionId: item.id, answer: item.answer })
})
that = this
$.post('http://ynxbdkj.natapp1.cc/question/answer?command=add_answers', { answers: JSON.stringify(o) },
function (resp) {
console.log(resp)
if (resp.code === 200) {
var ids = JSON.parse(localStorage.getItem("ynxbd_questionnaire"))
if (!ids) ids = []
ids.push({ id: that.params.id })
localStorage.setItem('ynxbd_questionnaire', JSON.stringify(ids))
vant.Toast.success('提交成功')
} else {
vant.Toast.fail(resp.message)
}
}
)
},
api_getQuestion: function () {
_that = this
vant.Toast.loading({ message: '加载中...', forbidClick: true, duration: 0 })
$.get("http://ynxbdkj.natapp1.cc/question/question?command=query_by_qid&id=" + _that.params.id,
function (resp) {
console.log(resp)
if (resp.code === 200) {
resp.data.forEach(function (item) {
item.answer = ''
item.answers = []
if (item.a) item.answers.push({ text: 'A. ' + item.a, value: 'A' })
if (item.b) item.answers.push({ text: 'B. ' + item.b, value: 'B' })
if (item.c) item.answers.push({ text: 'C. ' + item.c, value: 'C' })
if (item.d) item.answers.push({ text: 'D. ' + item.d, value: 'D' })
if (item.e) item.answers.push({ text: 'E. ' + item.e, value: 'E' })
if (item.f) item.answers.push({ text: 'F. ' + item.f, value: 'F' })
if (item.g) item.answers.push({ text: 'G. ' + item.g, value: 'G' })
})
_that.questions = resp.data
vant.Toast.clear()
} else {
vant.Toast.fail(resp.message)
}
}
)
}
},
created: function () {
this.api_getQuestion()
}
}
</script>
<style scoped>
.question-list-change {
width: 100%;
}
body {
background-color: #6fb734;
}
#app {
align-items: center;
width: 100%;
max-width: 1000px;
}
.card {
width: 90%;
height: 300px;
}
.van-radio__icon {
font-size: 18px;
}
.van-radio {
margin-top: 22px;
margin-left: 10px;
}
.head {
display: flex;
justify-content: space-between;
align-items: center;
width: 90%;
border: none;
}
.head-progress {
margin: 20px 0;
width: 88%;
}
.head-progress-num {
width: 10%;
text-align: center;
color: #8ac55a;
font-size: 16px;
}
.card__head {
display: flex;
}
.card__head-title {
margin-top: 8px;
}
.card__head-icon {
width: 36px;
height: 36px;
padding: 1px;
line-height: 36px;
font-weight: bold;
border-radius: 50%;
background-color: #72b937;
font-size: 15px;
text-align: center;
color: #ffffff;
margin-right: 10px;
flex-shrink: 0;
}
.footer {
position: absolute;
bottom: 60px;
width: 90vw;
display: flex;
justify-content: center;
}
.footer-btn-prev {
padding: 0 26px;
}
.footer-btn-save,
.footer-btn-next {
margin-left: 20px;
padding: 0 26px;
background-color: #72b937;
}
.end__box {
width: 100%;
height: 100%;
background-color: #72b937;
}
.end-title__box {
text-align: center;
background-color: #ffffff;
height: 80vw;
width: 100vw;
border-radius: 0 0 50% 50%;
position: absolute;
top: -40vw;
}
.end-title {
font-size: 24px;
color: #41583c;
font-weight: bold;
margin-top: 50vw;
}
.end-img {
width: 80%;
max-width: 500px;
position: absolute;
bottom: 10px;
right: 10px;
}
.text {
width: 100%;
margin-top: 22px;
border: 1px solid #72b937;
box-sizing: border-box;
font-size: 14px;
opacity: 0.88;
}
.line-input__box {
position: relative;
}
.line-input-label {
position: absolute;
left: 46px;
top: 18px;
z-index: 2;
}
.line-input {
outline: none;
border: none;
border-bottom: 1px solid #6fb734;
text-align: center;
display: inline-block;
font-size: 14px;
margin-top: 10px;
width: 100%;
padding: 10px;
box-sizing: border-box;
}
.back-img {
position: absolute;
left: 0;
bottom: 180px;
height: 70%;
opacity: 0.99;
}
.btn__box {
display: flex;
flex-direction: column;
justify-content: center;
height: 100%;
margin-bottom: 10px;
}
.questionnaire {
position: relative;
height: 100%;
width: 100%;
max-width: 1000px;
display: flex;
justify-content: center;
align-items: center;
}
.questionnaire-btn__box {
display: flex;
flex-direction: column;
height: 60vh;
overflow-x: hidden;
overflow-y: auto;
padding: 0 20px 20px 20px;
border-bottom: 1px dashed #ffffff;
}
.question-btn {
font-size: 16px;
color: #606266;
background-color: #fff;
border: 1px solid #ebedf0;
box-sizing: border-box;
position: relative;
display: inline-block;
text-align: center;
border-radius: 400px;
cursor: pointer;
margin-top: 20px;
padding: 6px 12px;
box-shadow: 8px 8px 12px 0 rgba(0, 0, 0, 0.3);
transition: all linear 0.6s;
flex-shrink: 0;
border-left: 1px solid #dcdfe6;
border-top: 1px solid #dcdfe6;
}
.question-btn:active {
background-color: #e5e5e5;
}
.title {
position: absolute;
top: 20px;
font-size: 22px;
font-weight: bold;
color: #606266;
text-align: center;
width: 100%;
left: 0;
}
/* 全部列出 */
.question-all__box {
display: flex;
flex-direction: column;
align-items: center;
width: 100%;
}
.question-all__card {
flex-shrink: 1;
margin-bottom: 40px;
box-sizing: border-box;
padding: 10px 20px;
}
.question-item {
display: flex;
align-items: center;
position: relative;
}
.dropdown__box {
position: relative;
}
.dropdown-label {
position: absolute;
left: 46px;
top: 10px;
z-index: 2;
}
.van-dropdown-menu__item {
max-width: 360px;
}
.van-dropdown-item--down {
max-width: 1000px;
}
.question-back {
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAoAAAAPAAQMAAACfLFq4AAAABlBMVEXy/+b////E8/6nAAAa6UlEQVR4Xu3dzYokO3YH8H+MmqtruC7d5TW0S+03uN6VoaY1u3kN+w3auxoot6Jc4NwYemtg4L6GgYFRkYY2YNyPMEoKqJ1HTQOjZjQ67oz8UGZUfClSxo2dAQ1dFPkjs3TixFFIGQc05YjQNPGYBjpAFgUNAF4SrAGAFQTRHLoYGDegLAaGDSiKgX4D8tIgKwa6DViVBlEQJFcWrDYjrXPApwHQNsORCS5HQQ+VA96NgiEPRLcV2B6MWWD8QXeDwDwwXKs+EGoO6N/KXhDg+aAjMQCyfHBFiwEQyAaXtBxKNIDKBBe0GgYhssAoyI2A+FkOGOST1yMgckC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Blg8YDANzWqQE6EXQNeLv9cA7sEKxmgK8a8BJEHe3mWD5oGw9ieEkyH+T3pUC3AdmyFOg3YPWHUmDYgNClQVUK9KVBtwV1aZCKg6XDpmeCmg/+pqd9m5gLXnZ3uYo8lcwqB4xiA4rep0dYsCyQ1x09fqEO255anQEGZp+DDoywVaKgIDNAD/f8RKmBCJ3WiBYZoMPNs9wQAVxDpy3mjxmgxXUDtkPz29QD1KuPWeDls7h2uAT+fAu8Iye9zgFF3Y5ry9IcnyQ54dV00IGZNmhkiuaoyIqPMmeUK9s+UWpN+6gJmqx4/Gk6GADXtdPCqC2oAsT7D9PBiCZuZPs+k5UbwEv3I3v3fjpIwOtWXAd+8KSoj++WvpKPGaCBaMV1Y4Ut+On9u3ClPmWAFrxuxbU8SF9Pj5Ki+pwBOjBzDDq1BtkWdIqCn
width: 100%;
height: 100vh;
position: fixed;
max-width: 1000px;
}
.van-hairline--top-bottom::after,
.van-hairline-unset--top-bottom::after {
border: none;
}
</style>