question.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518
  1. <template>
  2. <view class="content">
  3. <!-- 个人信息 -->
  4. <view class="blur-bg-2"></view>
  5. <view class="top-btn">
  6. <view class="back x-c" @click="$navBack()">
  7. <image src='/static/image/new/icon_back.svg'></image>
  8. 返回
  9. </view>
  10. <view class="title x-c">
  11. <image src='/static/image/new/img_title1.svg'></image>
  12. <text>问诊</text>
  13. <image src='/static/image/new/img_title2.svg'></image>
  14. </view>
  15. <view class="index x-c" @click="isShow=true">
  16. <image src='/static/image/new/icon_home.svg'></image>
  17. 首页
  18. </view>
  19. </view>
  20. <view class="userBox y-c" v-if="currentIndex === index" v-for="(item,index) in qw" :key="index">
  21. <view class="toptitle">
  22. <view class="tips">
  23. <view class="num x-c">{{index+1}}/{{qw.length}}</view>
  24. <view class="select x-c" v-if="index!=4">多选</view>
  25. </view>
  26. <view class="topic">{{item.name}}</view>
  27. </view>
  28. <view class="userInfo y-bc">
  29. <view class="item" v-for="(it,idx) in item.option" :key="idx" :class="{ 'active': item.selected.includes(idx) }" @click="selectOption(index, idx)">
  30. <view class="option-text">{{it.name}}</view>
  31. <image src='/static/image/new/icon_selected.svg' v-if="item.selected.includes(idx)"></image>
  32. </view>
  33. <view class="btn-box x-ac">
  34. <view class="last-btn" v-if="currentIndex>0" @click="lastItem(index)">上一题</view>
  35. <view class="next-btn" @click="nextItem(index)">{{index === qw.length - 1 ? '提交' : '下一题'}}</view>
  36. </view>
  37. </view>
  38. </view>
  39. <view v-if="isShow" class="mask">
  40. <view class="popup-container">
  41. <image class="bg" src='/static/image/new/bg_popup.svg'></image>
  42. <view class="title-t x-c">
  43. <image src='/static/image/new/img_title1.svg'></image>
  44. <text>提示</text>
  45. <image src='/static/image/new/img_title2.svg'></image>
  46. </view>
  47. <view class="title-r">确定要中断当前操作,返回首页吗~</view>
  48. <!-- <image style="width: 200px;height: 200px;margin-bottom: 20px;" :src="qUrl"></image> -->
  49. <view class="x-c">
  50. <view class="btn-l" @click="close">取消</view>
  51. <view class="btn-r" @click="goIndex">确认</view>
  52. </view>
  53. </view>
  54. </view>
  55. <CustomToast ref="toast"></CustomToast>
  56. </view>
  57. </template>
  58. <script>
  59. import {
  60. getUserInfoByUserId,
  61. getUserInfo,
  62. consultationCollect
  63. } from '@/api/user.js';
  64. import CustomToast from '@/components/CustomToast.vue';
  65. export default {
  66. components: { CustomToast },
  67. data() {
  68. return {
  69. isShow:false,
  70. currentIndex: 0, // 当前显示的题目索引
  71. qw:[
  72. {
  73. qid:1,
  74. name:"您平时是否有以下状况?",
  75. option:[
  76. {id:1,name:"高血压"},
  77. {id:2,name:"高血脂"},
  78. {id:3,name:"高血糖"},
  79. {id:4,name:"高尿酸"},
  80. {id:5,name:"无"},
  81. ],
  82. selected: [] // 存储选中的选项索引
  83. },
  84. {
  85. qid:2,
  86. name:"您是否有以下情况?",
  87. option:[
  88. {id:1,name:"手术史"},
  89. {id:2,name:"长期用药"},
  90. {id:3,name:"过敏史"},
  91. {id:4,name:"遗传疾病"},
  92. {id:5,name:"无"},
  93. ],
  94. selected: [] // 存储选中的选项索引
  95. },
  96. {
  97. qid:3,
  98. name:"您是否有以下不良生活习惯?",
  99. option:[
  100. {id:1,name:"吸烟"},
  101. {id:2,name:"喝酒"},
  102. {id:3,name:"熬夜"},
  103. {id:4,name:"精神压力过大"},
  104. {id:5,name:"无"},
  105. ],
  106. selected: [] // 存储选中的选项索引
  107. },
  108. {
  109. qid:4,
  110. name:"您是否有以下不良饮食习惯?",
  111. option:[
  112. {id:1,name:"偏咸饮食"},
  113. {id:2,name:"喜欢吃辣"},
  114. {id:3,name:"重甜食油腻"},
  115. {id:4,name:"贪食寒凉"},
  116. {id:5,name:"无"},
  117. ],
  118. selected: [] // 存储选中的选项索引
  119. },
  120. {
  121. qid:5,
  122. name:"您平时的运动情况是?",
  123. option:[
  124. {id:1,name:"每天规律运动,每次半小时以上"},
  125. {id:2,name:"每周运动5次以上,每次半小时以上"},
  126. {id:3,name:"每周运动3次以上,每次半小时以上"},
  127. {id:4,name:"每周运动1-2次,每次半小时以上"},
  128. {id:5,name:"基本不运动"},
  129. ],
  130. selected: [] // 存储选中的选项索引
  131. }
  132. ]
  133. }
  134. },
  135. onLoad(option) {
  136. },
  137. onShow() {
  138. },
  139. methods: {
  140. //首页
  141. goIndex(){
  142. this.isShow=false
  143. uni.reLaunch({
  144. url: '/pages/index/index',
  145. animationType: 'none',
  146. animationDuration: 2000
  147. })
  148. },
  149. close(){
  150. this.isShow=false
  151. },
  152. // 选中/取消选中选项
  153. selectOption(quesIndex, optIndex) {
  154. const question = this.qw[quesIndex];
  155. // 判断是否已选中:选中则取消,未选中则添加
  156. if (quesIndex === 4) {
  157. question.selected = [optIndex]; // 单选直接替换数组
  158. } else {
  159. if (question.selected.includes(optIndex)) {
  160. question.selected = question.selected.filter(idx => idx !== optIndex);
  161. } else {
  162. question.selected.push(optIndex);
  163. }
  164. }
  165. },
  166. // 上一题
  167. lastItem(index) {
  168. // 第一题禁用上一题
  169. if (index === 0) return;
  170. // 切换到上一题并滚动到顶部
  171. this.currentIndex = index - 1;
  172. },
  173. // 下一题/提交答案
  174. nextItem(index) {
  175. // 验证:未选中任何选项时提示
  176. if (!this.qw[index].selected.length) {
  177. this.$refs.toast.showToast({ title: '还没选择选项呢,选好再继续呀~'})
  178. return;
  179. }
  180. // 最后一题:提交答案
  181. if (index === this.qw.length - 1) {
  182. this.submitAnswers();
  183. return;
  184. }
  185. // 非最后一题:切换到下一题
  186. this.currentIndex = index + 1;
  187. },
  188. // 提交所有答案
  189. submitAnswers() {
  190. // 整理答案数据(示例格式)
  191. // questionIndex: idx + 1,
  192. // question: item.name,
  193. // selectedOptions: item.selected.map(i => item.option[i].name),
  194. // selectedIndexes: item.selected,
  195. const getSelectedStr = (item) => {
  196. // 边界处理:防止item/selected/option不存在导致报错
  197. if (!item || !Array.isArray(item.selected) || !item.option) return '';
  198. // 映射并过滤空值,避免无效逗号
  199. return item.selected.map(i => item.option[i]?.name || '').filter(Boolean).join(',');
  200. };
  201. const answers = {
  202. conditions: getSelectedStr(this.qw[0]) || '',
  203. situations: getSelectedStr(this.qw[1]) || '',
  204. liftHabits: getSelectedStr(this.qw[2]) || '',
  205. eatHabits: getSelectedStr(this.qw[3]) || '',
  206. exercise: getSelectedStr(this.qw[4]) || ''
  207. };
  208. var token = uni.getStorageSync('AppToken');
  209. console.log('token',token)
  210. console.log('提交的答案:', answers);
  211. // 模拟接口提交
  212. uni.showLoading({ title: '提交中...' });
  213. consultationCollect(answers).then(res => {
  214. if(res.code==200){
  215. setTimeout(() => {
  216. uni.hideLoading();
  217. uni.showToast({ title: '提交成功', icon: 'success' });
  218. // 提交成功后跳转(示例)
  219. uni.navigateTo({ url: '/pages/device/pulse/transition' });
  220. }, 1000);
  221. }else{
  222. this.$refs.toast.showToast({title: res.msg});
  223. }
  224. },rej => {});
  225. }
  226. }
  227. }
  228. </script>
  229. <style scoped lang="scss">
  230. page {
  231. background: #fff;
  232. font-size: 16px
  233. }
  234. /* 遮罩层样式 */
  235. .mask {
  236. position: fixed;
  237. top: 0;
  238. left: 0;
  239. right: 0;
  240. bottom: 0;
  241. background-color: rgba(0, 0, 0, 0.5);
  242. display: flex;
  243. justify-content: center;
  244. align-items: center;
  245. z-index: 999;
  246. animation: fadeIn 0.3s ease;
  247. }
  248. /* 弹窗容器样式 */
  249. .popup-container {
  250. //width: 50%;
  251. width: 620px;
  252. height: 352px;
  253. background: #FFFFFF;
  254. border-radius: 39px 39px 39px 39px;
  255. animation: scaleIn 0.3s ease;
  256. overflow: hidden;
  257. display: flex;
  258. flex-direction: column;
  259. align-items: center;
  260. justify-content: space-between;
  261. padding:43px;
  262. position: relative;
  263. .bg{
  264. width: 100%;
  265. height: 244px;
  266. position: absolute;
  267. top:0
  268. }
  269. .title-t {
  270. image{
  271. width: 153px;
  272. height: 25px;
  273. }
  274. text{
  275. font-family: PingFang SC, PingFang SC;
  276. font-weight: 500;
  277. font-size: 32px;
  278. color: #333333;
  279. margin: 0 10px;
  280. }
  281. }
  282. .title-r {
  283. font-family: PingFang SC, PingFang SC;
  284. font-weight: 400;
  285. font-size: 28px;
  286. color: #333333;
  287. }
  288. .btn-l{
  289. display: flex;
  290. align-items: center;
  291. justify-content: center;
  292. font-family: PingFang SC, PingFang SC;
  293. font-weight: 600;
  294. font-size: 28px;
  295. color: #37C3A0;
  296. width: 220px;
  297. height: 64px;
  298. border-radius: 121px 121px 121px 121px;
  299. border: 2px solid #37C3A0;
  300. margin-right: 40px;
  301. }
  302. .btn-r {
  303. display: flex;
  304. align-items: center;
  305. justify-content: center;
  306. width: 220px;
  307. height: 64px;
  308. background: #37C3A0;
  309. border-radius: 121px 121px 121px 121px;
  310. font-family: PingFang SC, PingFang SC;
  311. font-weight: 600;
  312. font-size: 28px;
  313. color: #FFFFFF;
  314. }
  315. }
  316. .content {
  317. width: 100%;
  318. height: 100%;
  319. background: #D8F6EF;
  320. padding: 28px;
  321. display: flex;
  322. flex-direction: column;
  323. .blur-bg-2 {
  324. width: 350px;
  325. height: 350px;
  326. background: #FFFDCC;
  327. // opacity: 0.47;
  328. filter: blur(200px);
  329. position: absolute;
  330. z-index: 1;
  331. top: 60px;
  332. right: calc(0px - 107px);
  333. pointer-events: none
  334. }
  335. }
  336. .top-btn {
  337. display: flex;
  338. align-items: center;
  339. justify-content: space-between;
  340. z-index:2;
  341. .back {
  342. width: 140px;
  343. height: 48px;
  344. background: rgba(255, 255, 255, 0.64);
  345. border-radius: 45px 45px 45px 45px;
  346. border: 2px solid #FFFFFF;
  347. font-family: PingFang SC, PingFang SC;
  348. font-weight: 500;
  349. font-size: 22px;
  350. color: #327E6F;
  351. image {
  352. margin-right: 4px;
  353. width: 24px;
  354. height: 24px;
  355. }
  356. }
  357. .title {
  358. font-family: PingFang SC, PingFang SC;
  359. font-weight: 600;
  360. font-size: 36px;
  361. color: #327E6F;
  362. line-height: 54px;
  363. text {
  364. margin: 0 14px;
  365. }
  366. image {
  367. width: 153px;
  368. height: 25px;
  369. }
  370. }
  371. .index {
  372. width: 140px;
  373. height: 48px;
  374. background: rgba(255, 255, 255, 0.64);
  375. border-radius: 55px 55px 55px 55px;
  376. border: 2px solid #FFFFFF;
  377. font-family: PingFang SC, PingFang SC;
  378. font-weight: 500;
  379. font-size: 22px;
  380. color: #327E6F;
  381. image {
  382. margin-right: 4px;
  383. width: 24px;
  384. height: 24px;
  385. }
  386. }
  387. }
  388. .userBox {
  389. flex: 1;
  390. margin-top: 28px;
  391. background: rgba(255, 255, 255, 0.7);
  392. border-radius: 24px 24px 24px 24px;
  393. padding: 27px 40px;
  394. z-index: 9;
  395. display: flex;
  396. flex-direction: column;
  397. align-items: center;
  398. .toptitle {
  399. width: 720px;
  400. display: flex;
  401. flex-direction: column;
  402. align-items: start;
  403. margin-top: 12px;
  404. .tips {
  405. display: flex;
  406. align-items: center;
  407. font-family: PingFang SC, PingFang SC;
  408. font-weight: 600;
  409. font-size: 24px;
  410. margin-bottom: 20px;
  411. .num{
  412. width: 80px;
  413. height: 36px;
  414. background: #37C3A0;
  415. border-radius: 55px 55px 55px 55px;
  416. color: #fff;
  417. margin-right:16px ;
  418. }
  419. .select{
  420. width: 80px;
  421. height: 36px;
  422. background: #FFFFFF;
  423. border-radius: 55px 55px 55px 55px;
  424. border: 2px solid #E3B419;
  425. color: #E9A615;
  426. }
  427. }
  428. .topic{
  429. font-family: PingFang SC, PingFang SC;
  430. font-weight: 500;
  431. font-size: 28px;
  432. color: #333333;
  433. }
  434. }
  435. .userInfo{
  436. .item{
  437. width: 720px;
  438. height: 80px;
  439. background: rgba(55,195,160,0.08);
  440. border-radius: 24px 24px 24px 24px;
  441. text-align: center;
  442. position: relative;
  443. margin-top: 32px;
  444. .option-text{
  445. font-family: PingFang SC, PingFang SC;
  446. font-weight: 400;
  447. font-size: 28px;
  448. line-height: 80px;
  449. color: #333333;
  450. }
  451. &.active{
  452. background: rgba(55,195,160,0.2);
  453. border: 2px solid #37C3A0;
  454. image{
  455. position: absolute;
  456. top:18px;
  457. right: 32px;
  458. width: 44px;
  459. height: 44px;
  460. }
  461. }
  462. }
  463. }
  464. .btn-box {
  465. margin-top: 50px;
  466. margin-bottom: 16px;
  467. display: flex;
  468. align-items: center;
  469. justify-content: center;
  470. .last-btn{
  471. display: flex;
  472. align-items: center;
  473. justify-content: center;
  474. width: 280px;
  475. height: 68px;
  476. border-radius: 121px 121px 121px 121px;
  477. border: 2px solid #37C3A0;
  478. font-family: PingFang SC, PingFang SC;
  479. font-weight: 600;
  480. font-size: 28px;
  481. color: #37C3A0;
  482. margin-right: 40px;
  483. }
  484. .next-btn{
  485. display: flex;
  486. align-items: center;
  487. justify-content: center;
  488. width: 280px;
  489. height: 68px;
  490. background: #37C3A0;
  491. border-radius: 121px 121px 121px 121px;
  492. font-family: PingFang SC, PingFang SC;
  493. font-weight: 600;
  494. font-size: 28px;
  495. color: #fff;
  496. }
  497. }
  498. }
  499. </style>