Commit 7f2f74e3 by 李伟康

问卷需求

1 parent c8d552ac
......@@ -35,20 +35,27 @@ Page({
if (!userInfo.nickName) return this.getNickNameAndHeadUrl()
try {
const data = await wx.p.api.questionnaireApi.getQuestionnaireDetail(options)
if (data.activityType == 3) {
// const a = await wx.p.api.equityApi.checkReceiveRed({
// equityFreeCardId: data.activityId,
// nickName: userInfo.nickName
// })
// console.log(a)
if (data.status == -1) {
return wx.showModal({
title: '温馨提示',
content: '问卷已结束。',
showCancel: false,
confirmText: '返回首页',
confirmColor: '#3772EC',
complete: (res) => {
if (res.confirm) wx.p.router.goHome()
}
})
}
console.log(data)
if (data) {
data.questions.map(e => {
if (e.type != 3) {
let option = e.option.split('\n')
if (e.type == 5) e.data = this.transformData(option)
else e.data = option
if (e.type == 5) {
const [, two, three] = option[0].split('/')
option.splice(0, 1)
e.data = this.transformData(option, three ? 3 : two ? 2 : 1)
} else e.data = option
}
e.answer = ''
e.userFormId = e.formId
......@@ -66,18 +73,17 @@ Page({
}
}
},
transformData(data, maxLength = 3) {
transformData(data, childrenDepth) {
const result = []
data.forEach(item => {
const levels = item.split('/')
let currentLevel = result
for (let i = 0; i < levels.length; i++) {
if (i == maxLength) break
for (let i = 0; i < childrenDepth; i++) {
const text = levels[i],
value = text,
existingOption = currentLevel.find((option) => option.text === text)
if (existingOption) {
if (i === levels.length - 1) {
if (i === childrenDepth - 1) {
continue
}
currentLevel = existingOption.children
......@@ -88,7 +94,7 @@ Page({
children: []
}
if (text && value) currentLevel.push(newOption)
if (i === levels.length - 1) {
if (i === childrenDepth - 1) {
delete newOption.children
}
currentLevel = newOption.children
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!