diff --git a/pages_order/components/reportCard.vue b/pages_order/components/reportCard.vue index 4b07997..4ac252c 100644 --- a/pages_order/components/reportCard.vue +++ b/pages_order/components/reportCard.vue @@ -4,17 +4,13 @@ - - - + - - 李星星 - + {{ data.realName || '' }} - 25岁 - + {{ data.age || '' }} + {{ data.sex || '' }} @@ -26,8 +22,20 @@ diff --git a/pages_order/report/compare/result.vue b/pages_order/report/compare/result.vue index 4b68bcd..806e530 100644 --- a/pages_order/report/compare/result.vue +++ b/pages_order/report/compare/result.vue @@ -3,7 +3,7 @@ - + BMI 指数 - {{ item.BMI || '-' }} + {{ item.bmi || '-' }} - + - + @@ -120,6 +120,7 @@ }, data() { return { + detail: {}, list: [], axis: ['饮食', '运动', '心理', '体质', '作息'] } @@ -137,6 +138,9 @@ const result = await this.$fetch('getReportDetail', { id }) const { + realName, + age, + sex, createTime, score, scoreDetail, @@ -146,6 +150,9 @@ const obj = { id, + realName, + age, + sex, createTime: this.$dayjs(createTime).format('YYYY-MM-DD'), score: parseInt(score), scoreDetail: JSON.parse(scoreDetail).map(item => ({ name: item.name, score: parseInt(item.score) })), @@ -166,6 +173,7 @@ console.log('results', results) this.list = results.map(item => item.value) + this.detail = this.list[0] console.log('list', this.list) }, }, diff --git a/pages_order/report/detail/cardHeader.vue b/pages_order/report/detail/cardHeader.vue index 1192158..525c4c2 100644 --- a/pages_order/report/detail/cardHeader.vue +++ b/pages_order/report/detail/cardHeader.vue @@ -5,8 +5,7 @@ BMI 指数 {{ BMI || '-' }} - - + diff --git a/pages_order/report/detail/index.vue b/pages_order/report/detail/index.vue index a385760..820d7d6 100644 --- a/pages_order/report/detail/index.vue +++ b/pages_order/report/detail/index.vue @@ -3,9 +3,9 @@ - + - + @@ -84,7 +84,7 @@ }, data() { return { - BMI: 0, + detail: {}, list: [], } }, @@ -92,15 +92,14 @@ const { id } = arg this.id = id this.fetchReportData(id) - // todo: delete - this.BMI = 16.5 }, methods: { async fetchReportData(id) { try { - const { json } = await this.$fetch('getReportDetail', { id }) + const { json, ...detail } = await this.$fetch('getReportDetail', { id }) + this.detail = detail this.list = JSON.parse(json).map((item, index) => { let url = `/pages_order/static/report/report-detail-${index + 1}.png` diff --git a/pages_order/report/nutritionProgram/index.vue b/pages_order/report/nutritionProgram/index.vue index f28fbc8..1a6d2a4 100644 --- a/pages_order/report/nutritionProgram/index.vue +++ b/pages_order/report/nutritionProgram/index.vue @@ -3,7 +3,7 @@ - + 营养师基于你生活习惯和营养目标推荐 量身定制的营养方案 @@ -73,6 +73,7 @@ data() { return { productId: '', + detail: {}, list: [], comment: 0, } @@ -107,7 +108,7 @@ async fetchReportData(id) { try { - const { productList } = await this.$fetch('getReportDetail', { id }) + const { productList, ...detail } = await this.$fetch('getReportDetail', { id }) const detectList = [] const nutrientList = [] @@ -146,6 +147,7 @@ }) + this.detail = detail this.list = [ { id: '001', diff --git a/pages_order/report/result/index.vue b/pages_order/report/result/index.vue index 7361145..2652fcb 100644 --- a/pages_order/report/result/index.vue +++ b/pages_order/report/result/index.vue @@ -48,12 +48,6 @@ resultSummary, tonicCard, }, - props: { - id: { - type: String | Number, - default: null, - } - }, data() { return { id: null, diff --git a/pages_order/report/result/resultSummary.vue b/pages_order/report/result/resultSummary.vue index 8c2227a..3c59d88 100644 --- a/pages_order/report/result/resultSummary.vue +++ b/pages_order/report/result/resultSummary.vue @@ -3,8 +3,8 @@ - - 战斗世界 + + {{ userInfo.name || '' }} 的健康测评 @@ -45,6 +45,8 @@ diff --git a/pages_order/report/test/answer.vue b/pages_order/report/test/answer.vue index ab549df..a6cf52f 100644 --- a/pages_order/report/test/answer.vue +++ b/pages_order/report/test/answer.vue @@ -2,77 +2,106 @@ - - - - + @@ -85,17 +114,23 @@ return { step: 0, current: 0, + tabs: [], value: null, noneFlag: false, answers: [], + // tags: [], questionsList: [], total: 0, } }, computed: { - ...mapState(['paperInfo']), + ...mapState(['paperInfo', 'paperTags']), + preIdx() { + let index = this.tabs.findIndex(index => index === this.current) + return index - 1 + }, showPreBtn() { - return this.current > 0 + return this.preIdx >= 0 }, progress() { return 100 * (this.current + 1) / this.total @@ -111,14 +146,16 @@ return false } - return ['input', 'input-group'].includes(this.currentQuestion?.component) + return ['select-box-multiple', 'select-multiple','input', 'input-group'].includes(this.currentQuestion?.component) }, }, onLoad(arg) { this.step = parseInt(arg.step) - this.current = parseInt(arg.current || 0) - + // this.current = parseInt(arg.current || 0) + console.log('paperTags', this.paperTags) this.fetchQuestionList() + this.switchQuestion(parseInt(arg.current || 0)) + this.value = this.answers[this.current] console.log('currentQuestion', this.currentQuestion) }, @@ -130,19 +167,20 @@ const { questionsList } = category this.questionsList = questionsList.map(item => { - const { id, text, type, options, required, content } = item + const { id, text, type, options, needTag, required, multiple: _multiple, content } = item let component = 'select' + const multiple = _multiple == 'Y' switch(type) { // 0-单选题 1-填空题 2-图片单选题 case '1': component = options?.length > 1 ? 'input-group' : 'input' break case '2': - component = 'select-box' + component = multiple ? 'select-box-multiple' : 'select-box' break default: - component = 'select' + component = multiple ? 'select-multiple' : 'select' break } @@ -152,7 +190,9 @@ type, component, options, + needTag: needTag ? JSON.parse(needTag).map(config => config.tags).filter(tags => tags.length) : null, required: required == 'Y', + multiple, desc: content, } }) @@ -161,19 +201,68 @@ this.answers = this.questionsList.map(item => { let val = null - if (item.component === 'input-group') { - val = new Array(item.options.length).fill(0).map(() => null) + switch (item.component) { + case 'select-box-multiple': + case 'select-multiple': + val = [] + break + case 'input-group': + val = new Array(item.options.length).fill(0).map(() => '') + break; + default: + val = null + break; } return val }) - this.value = this.answers[this.current] + // this.tags = this.paperTags[this.step] + // this.value = this.answers[this.current] console.log('questionsList', this.questionsList) console.log('answers', this.answers) }, + switchQuestion(current) { + let { needTag } = this.questionsList[current] + + if (!needTag) { + this.current = current + this.tabs.push(this.current) + return + } + + const selectTags = this.paperTags.flat(2) + console.log('selectTags', selectTags) + console.log('needTag', needTag) + + let valid = needTag.some(tags => { + return tags.every(tag => { + const { value, exclude } = tag + + let include = selectTags.includes(value) + + return exclude ? !include : include + }) + }) + console.log('valid', valid) + + if (valid) { + this.current = current + this.tabs.push(this.current) + return + } + + if (current + 1 < this.questionsList.length) { + current += 1 + this.switchQuestion(current) + return + } + + this.$utils.redirectTo(`/pages_order/report/test/step?step=${this.step + 1}`) + }, pre() { - this.current -= 1 + // this.current -= 1 + this.current = this.preIdx this.value = this.answers[this.current] this.noneFlag = false }, @@ -181,18 +270,19 @@ if (this.showSubmitBtn) { return } - this.current += 1 + // this.current += 1 + this.switchQuestion(this.current + 1) this.value = this.answers[this.current] this.noneFlag = false }, async fetchAnswer() { try { - const { id: questionsId, type, required, options } = this.currentQuestion + const { id: questionsId, type, required, multiple, options } = this.currentQuestion console.log('paperInfo', this.paperInfo) console.log('currentQuestion', this.currentQuestion) console.log('required', required, 'noneFlag', this.noneFlag, 'value', this.value) - if (required && !this.noneFlag && (!this.value || this.value?.every?.(val => !val))) { + if (required && !this.noneFlag && (!this.value || !this.value?.length || this.value?.every?.(val => !val))) { console.log('未答题') uni.showToast({ title: '请答题', @@ -214,8 +304,8 @@ return obj }, {}) answer = JSON.stringify(answer) - } else { - answer = this.value + } else if (multiple && Array.isArray(this.value)) { // 多选题 + answer = this.value.join(',') } let params = { @@ -228,6 +318,28 @@ this.answers[this.current] = this.value + let paperTags = [...this.paperTags] + if (type == 1) { + paperTags[this.step][this.current] = [] + } else { + let selectedIdArr = Array.isArray(this.value) ? this.value : [this.value] + console.log('selectedIdArr', selectedIdArr, 'options', options) + + paperTags[this.step][this.current] = selectedIdArr.reduce((arr, id) => { + const { settingTag } = options.find(item => item.id === id) || {} + + if (settingTag) { + const tags = settingTag?.split?.(',') + tags?.length && (arr = arr.concat(tags)) + } + + return arr + }, []) + + } + console.log('paperTags', paperTags) + this.$store.commit('setPaperTags', paperTags) + return true } catch (err) { console.log('answerPaper', err) @@ -242,7 +354,6 @@ } let succ = await this.fetchAnswer() - console.log('fetchAnswer', succ) if (!succ) { return @@ -254,9 +365,11 @@ }, 500) }) }, + async onSelectMulitple(id) { + this.value = this.value.includes(id) ? this.value.filter(item => item !== id) : this.value.concat(id) + }, async onConfirm() { let succ = await this.fetchAnswer() - console.log('fetchAnswer', succ) if (!succ) { return @@ -269,14 +382,22 @@ let val = null - if (this.currentQuestion.component === 'input-group') { - val = new Array(this.currentQuestion.options.length).fill(0).map(() => '') + switch (this.currentQuestion.component) { + case 'select-box-multiple': + case 'select-multiple': + val = [] + break + case 'input-group': + val = new Array(this.currentQuestion.options.length).fill(0).map(() => '') + break; + default: + val = null + break; } this.value = val let succ = await this.fetchAnswer() - console.log('fetchAnswer', succ) if (!succ) { return @@ -286,7 +407,6 @@ }, async onSubmit() { let succ = await this.fetchAnswer() - console.log('fetchAnswer', succ) if (!succ) { return diff --git a/pages_order/report/test/intro.vue b/pages_order/report/test/intro.vue index 2e349b2..1270826 100644 --- a/pages_order/report/test/intro.vue +++ b/pages_order/report/test/intro.vue @@ -60,7 +60,6 @@ ...mapState(['paperInfo']), }, onLoad(arg) { - console.log('onLoad', arg) const { id } = arg this.id = id @@ -88,6 +87,10 @@ const reportId = await this.$fetch('startPaper', { id: this.id }) this.detail.reportId = reportId this.$store.commit('setPaperInfo', this.detail) + const defaultPaperTags = this.detail.category.map(category => { + return category.questionsList.map(() => []) + }) + this.$store.commit('setPaperTags', defaultPaperTags) this.$utils.navigateTo('/pages_order/report/test/step?step=0') } catch (err) { diff --git a/store/store.js b/store/store.js index 3a37962..1baada0 100644 --- a/store/store.js +++ b/store/store.js @@ -16,6 +16,7 @@ const store = new Vuex.Store({ applyServiceProduct: [], // 售后服务商品 addressInfo: null, paperInfo: null, + paperTags: null, }, getters: { // 角色 true为水洗店 false为酒店 : 身份判断如果不需要,可以删除 @@ -135,6 +136,9 @@ const store = new Vuex.Store({ setPaperInfo(state, data) { state.paperInfo = data }, + setPaperTags(state, data) { + state.paperTags = data + }, }, actions: { async addCart(state, data) {