Commit 7f2f74e3 by 李伟康

问卷需求

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