HealthQuestionnaireWizard.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. <!-- DEPRECATED: 已由 ComprehensiveSurvey.vue 替代,待确认无引用后清理(2026-10-16 标记) -->
  2. <template>
  3. <view class="wizard-wrap" :style="{ '--font-scale': fontScale }">
  4. <!-- 内部步骤指示器(4 步:基础体征/疾病史/饮食习惯/确认) -->
  5. <view class="wizard-steps">
  6. <view
  7. v-for="(s, i) in wizardSteps"
  8. :key="i"
  9. class="wizard-step"
  10. :class="{ 'wizard-step-active': currentStep === i + 1, 'wizard-step-done': currentStep > i + 1 }"
  11. @click="goToStep(i + 1)"
  12. >
  13. <text class="wizard-step-num">{{ i + 1 }}</text>
  14. <text class="wizard-step-label">{{ s }}</text>
  15. </view>
  16. </view>
  17. <!-- 步骤内容 -->
  18. <view class="wizard-body">
  19. <!-- Step 1: 基础体征 -->
  20. <view v-if="currentStep === 1">
  21. <basic-vitals-step
  22. ref="stepRef"
  23. :value="currentMemberForm"
  24. @input="onVitalsInput"
  25. />
  26. </view>
  27. <!-- Step 2: 疾病史与用药 -->
  28. <view v-if="currentStep === 2">
  29. <medical-history-step
  30. ref="stepRef"
  31. :value="currentMemberForm"
  32. @input="onMedicalInput"
  33. />
  34. </view>
  35. <!-- Step 3: 生活方式与肠道健康 -->
  36. <view v-if="currentStep === 3">
  37. <lifestyle-step
  38. ref="stepRef"
  39. :value="currentMemberForm"
  40. :profile="currentMemberProfile"
  41. @input="onLifestyleInput"
  42. />
  43. </view>
  44. <!-- Step 4: 饮食习惯 -->
  45. <view v-if="currentStep === 4">
  46. <diet-habits-step
  47. ref="stepRef"
  48. :value="currentMemberDiet"
  49. @input="onDietInput"
  50. @skip-no-preference="onDietSkipNoPreference"
  51. />
  52. </view>
  53. <!-- Step 5: 确认 -->
  54. <view v-if="currentStep === 5">
  55. <confirm-step
  56. ref="stepRef"
  57. :health-status="currentMemberForm"
  58. :diet-preferences="currentMemberDiet"
  59. :submitting="submitting"
  60. @submit="handleSubmit"
  61. @back="prev"
  62. />
  63. </view>
  64. </view>
  65. <!-- 底部导航:上一步 / 下一步(最后一步为保存并生成) -->
  66. <view class="wizard-footer" v-if="currentStep < 5">
  67. <button class="btn-prev" :disabled="currentStep === 1" @click="prev">
  68. <text>上一步</text>
  69. </button>
  70. <button class="btn-next" :disabled="validating" @click="next">
  71. <text>{{ validating ? '校验中...' : '下一步' }}</text>
  72. </button>
  73. </view>
  74. </view>
  75. </template>
  76. <script>
  77. import BasicVitalsStep from './BasicVitalsStep.vue'
  78. import MedicalHistoryStep from './MedicalHistoryStep.vue'
  79. import LifestyleStep from './LifestyleStep.vue'
  80. import DietHabitsStep from './DietHabitsStep.vue'
  81. import ConfirmStep from './ConfirmStep.vue'
  82. import fontScaleMixin from '@/mixins/font-scale.js'
  83. export default {
  84. mixins: [fontScaleMixin],
  85. name: 'HealthQuestionnaireWizard',
  86. components: {
  87. BasicVitalsStep,
  88. MedicalHistoryStep,
  89. LifestyleStep,
  90. DietHabitsStep,
  91. ConfirmStep
  92. },
  93. props: {
  94. // 成员表单快照:memberId → { form, lipidCholesterol, selectedDiseases, medRows }
  95. memberFormMap: {
  96. type: Object,
  97. default: function() { return {} }
  98. },
  99. // 成员饮食习惯快照:memberId → dietPreferences 对象
  100. dietMap: {
  101. type: Object,
  102. default: function() { return {} }
  103. },
  104. // 成员基本信息:memberId → { gender, age }(问卷按 profile 动态调整问题)
  105. memberProfileMap: {
  106. type: Object,
  107. default: function() { return {} }
  108. },
  109. // 当前填写成员
  110. activeFormMemberId: {
  111. type: String,
  112. default: ''
  113. },
  114. // 提交中(由父组件 loading 驱动,失败后按钮可恢复)
  115. submitting: {
  116. type: Boolean,
  117. default: false
  118. }
  119. },
  120. data() {
  121. return {
  122. currentStep: 1,
  123. validating: false
  124. }
  125. },
  126. computed: {
  127. wizardSteps: function() {
  128. return ['基础体征', '疾病史', '生活方式', '饮食习惯', '确认']
  129. },
  130. // 当前成员的健康表单(来自父组件快照)
  131. currentMemberForm: function() {
  132. var map = this.memberFormMap || {}
  133. var key = this.activeFormMemberId || '__account'
  134. var snapshot = map[key] || {}
  135. return {
  136. heightCm: snapshot.form && snapshot.form.heightCm || '',
  137. weightKg: snapshot.form && snapshot.form.weightKg || '',
  138. bloodPressure: snapshot.form && snapshot.form.bloodPressure || '',
  139. bloodGlucose: snapshot.form && snapshot.form.bloodGlucose || '',
  140. notes: snapshot.form && snapshot.form.notes || '',
  141. lipidCholesterol: snapshot.lipidCholesterol || '',
  142. selectedDiseases: snapshot.selectedDiseases || [],
  143. medRows: snapshot.medRows || [],
  144. noMedication: !!snapshot.noMedication,
  145. mood: snapshot.lifestyle && snapshot.lifestyle.mood || '',
  146. sleepDuration: snapshot.lifestyle && snapshot.lifestyle.sleepDuration || '',
  147. bedtime: snapshot.lifestyle && snapshot.lifestyle.bedtime || '',
  148. bowelFrequency: snapshot.lifestyle && snapshot.lifestyle.bowelFrequency || '',
  149. bowelForm: snapshot.lifestyle && snapshot.lifestyle.bowelForm || '',
  150. antibioticHistory: snapshot.lifestyle && snapshot.lifestyle.antibioticHistory || '',
  151. allergySymptoms: snapshot.lifestyle && Array.isArray(snapshot.lifestyle.allergySymptoms) ? snapshot.lifestyle.allergySymptoms : [],
  152. menstrualCycle: snapshot.lifestyle && snapshot.lifestyle.menstrualCycle || '',
  153. specialPeriod: snapshot.lifestyle && snapshot.lifestyle.specialPeriod || '',
  154. growthDevelopment: snapshot.lifestyle && snapshot.lifestyle.growthDevelopment || '',
  155. pickyEating: snapshot.lifestyle && snapshot.lifestyle.pickyEating || '',
  156. osteoporosisRisk: snapshot.lifestyle && snapshot.lifestyle.osteoporosisRisk || '',
  157. fallRisk: snapshot.lifestyle && snapshot.lifestyle.fallRisk || '',
  158. screenTime: snapshot.lifestyle && snapshot.lifestyle.screenTime || '',
  159. teenMood: snapshot.lifestyle && snapshot.lifestyle.teenMood || ''
  160. }
  161. },
  162. // 当前成员的饮食习惯
  163. currentMemberDiet: function() {
  164. var map = this.dietMap || {}
  165. var key = this.activeFormMemberId || '__account'
  166. return map[key] || {}
  167. },
  168. // 当前成员的基本信息(性别/年龄),供 LifestyleStep 动态渲染
  169. currentMemberProfile: function() {
  170. var map = this.memberProfileMap || {}
  171. var key = this.activeFormMemberId || '__account'
  172. return map[key] || {}
  173. }
  174. },
  175. watch: {
  176. // 切换填写成员时回到第 1 步(各成员数据快照已保留,不影响已填内容)
  177. activeFormMemberId: function() {
  178. this.currentStep = 1
  179. }
  180. },
  181. methods: {
  182. // —— 步骤导航 ——
  183. goToStep: function(n) {
  184. if (n < 1 || n > 5) return
  185. if (n <= this.currentStep) {
  186. this.currentStep = n
  187. return
  188. }
  189. for (var s = this.currentStep; s < n; s++) {
  190. if (!this.validateStep(s)) return
  191. }
  192. this.currentStep = n
  193. },
  194. prev: function() {
  195. if (this.currentStep > 1) {
  196. this.currentStep -= 1
  197. }
  198. },
  199. next: function() {
  200. var pass = this.validateStep(this.currentStep)
  201. if (!pass) return
  202. if (this.currentStep < 5) {
  203. this.currentStep += 1
  204. }
  205. },
  206. validateStep: function(step) {
  207. var validatorMap = {
  208. 1: this.validateVitals,
  209. 2: this.validateMedical,
  210. 3: this.validateLifestyle,
  211. 4: this.validateDiet
  212. }
  213. var fn = validatorMap[step]
  214. if (fn) {
  215. var msg = fn.call(this)
  216. if (msg) {
  217. uni.showToast({ title: msg, icon: 'none' })
  218. return false
  219. }
  220. }
  221. return true
  222. },
  223. // Step1: 体征数值合法性
  224. validateVitals: function() {
  225. var form = this.currentMemberForm
  226. var height = String(form.heightCm || '').trim()
  227. var weight = String(form.weightKg || '').trim()
  228. var bp = String(form.bloodPressure || '').trim()
  229. var glucose = String(form.bloodGlucose || '').trim()
  230. if (height && !/^\d{2,3}(\.\d+)?$/.test(height)) {
  231. return '身高格式不正确'
  232. }
  233. if (weight && !/^\d{1,3}(\.\d+)?$/.test(weight)) {
  234. return '体重格式不正确'
  235. }
  236. if (bp && !/^\d{2,3}\/\d{2,3}$/.test(bp)) {
  237. return '血压格式应为 120/80'
  238. }
  239. if (glucose && !/^\d{1,2}(\.\d+)?$/.test(glucose)) {
  240. return '血糖格式不正确'
  241. }
  242. return ''
  243. },
  244. // Step2: 疾病史至少填写一项,或已标记"无长期用药"
  245. validateMedical: function() {
  246. var snapshot = this.currentMemberForm
  247. if (snapshot.noMedication) return ''
  248. var diseases = snapshot.selectedDiseases || []
  249. var meds = snapshot.medRows || []
  250. var hasMed = meds.some(function(m) { return m && m.name && String(m.name).trim() })
  251. if (diseases.length === 0 && !hasMed) {
  252. return '请至少填写一项疾病史或药物,如无请勾选"无长期用药"'
  253. }
  254. return ''
  255. },
  256. // Step3: 生活方式 — 心情/睡眠/排便/抗生素/过敏,所有字段可选,无强制校验
  257. validateLifestyle: function() {
  258. return ''
  259. },
  260. // Step4: 饮食习惯至少填写一项(忌口/偏好/必吃/菜系/烹饪/辣度/宗教饮食/目标/饮食结构任一)
  261. validateDiet: function() {
  262. var diet = this.currentMemberDiet || {}
  263. if (diet.noPreference) return ''
  264. var arrays = [diet.allergies, diet.absoluteAvoid, diet.mustEat, diet.flavorPref, diet.cuisinePref, diet.cookingMethods, diet.healthGoals]
  265. var hasAny = arrays.some(function(a) { return a && a.length > 0 })
  266. if (diet.vegetableFruit || diet.dairy || diet.sugaryDrinks) hasAny = true
  267. if (!hasAny && !(diet.spiceLevel && Number(diet.spiceLevel) > 0) && !(diet.religiousDiet && diet.religiousDiet !== 'none')) {
  268. return '请至少选择一项饮食习惯偏好或填写饮食结构'
  269. }
  270. return ''
  271. },
  272. onVitalsInput: function(payload) {
  273. this.$emit('update-vitals', payload)
  274. },
  275. onMedicalInput: function(payload) {
  276. this.$emit('update-medical', payload)
  277. },
  278. onLifestyleInput: function(payload) {
  279. this.$emit('update-lifestyle', payload)
  280. },
  281. onDietInput: function(payload) {
  282. this.$emit('update-diet', payload)
  283. },
  284. // 第4步「无特殊偏好」:跳过校验直接进入确认步
  285. onDietSkipNoPreference: function() {
  286. this.currentStep = 5
  287. },
  288. // —— 确认步骤提交:聚合所有成员数据后交给父组件统一保存+生成 ——
  289. handleSubmit: function() {
  290. var self = this
  291. this.$emit('submit', {
  292. memberFormMap: self.memberFormMap,
  293. dietMap: self.dietMap,
  294. activeFormMemberId: self.activeFormMemberId
  295. })
  296. }
  297. }
  298. }
  299. </script>
  300. <style scoped lang="scss">
  301. .wizard-wrap {
  302. display: flex;
  303. flex-direction: column;
  304. min-height: 600rpx;
  305. }
  306. .wizard-steps {
  307. display: flex;
  308. justify-content: space-between;
  309. padding: 20rpx 10rpx 10rpx;
  310. background: $app-surface;
  311. }
  312. .wizard-step {
  313. display: flex;
  314. flex-direction: column;
  315. align-items: center;
  316. flex: 1;
  317. }
  318. .wizard-step-num {
  319. width: 44rpx;
  320. height: 44rpx;
  321. border-radius: 24rpx;
  322. background: $facade-hairline;
  323. color: $facade-text-muted;
  324. font-size: calc(24rpx * var(--font-scale, 1));
  325. font-weight: bold;
  326. display: flex;
  327. align-items: center;
  328. justify-content: center;
  329. }
  330. .wizard-step-active .wizard-step-num {
  331. background: $brand-primary;
  332. color: $app-surface;
  333. }
  334. .wizard-step-done .wizard-step-num {
  335. background: $mat-green;
  336. color: $app-surface;
  337. }
  338. .wizard-step-label {
  339. font-size: calc(20rpx * var(--font-scale, 1));
  340. color: $facade-text-muted;
  341. white-space: nowrap;
  342. margin-top: 6rpx;
  343. }
  344. .wizard-step-active .wizard-step-label,
  345. .wizard-step-done .wizard-step-label {
  346. color: $facade-text-strong;
  347. font-weight: 500;
  348. }
  349. .wizard-body {
  350. flex: 1;
  351. padding: 10rpx 20rpx;
  352. }
  353. .wizard-footer {
  354. display: flex;
  355. padding: 20rpx 20rpx $uni-space-lg;
  356. }
  357. .btn-prev,
  358. .btn-next {
  359. flex: 1;
  360. margin: 0 10rpx;
  361. border-radius: 999rpx;
  362. font-size: calc(30rpx * var(--font-scale, 1));
  363. font-weight: 600;
  364. }
  365. .btn-prev {
  366. background: $facade-fill-slate;
  367. color: $facade-text-slate-700;
  368. }
  369. .btn-next {
  370. background: linear-gradient(135deg, $brand-primary, $brand-primary-light);
  371. color: $app-surface;
  372. }
  373. </style>