reportDetail.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. // pages/reportDetail/reportDetail.js
  2. import { getReport, getReportUserInfo } from '../../api/my'
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. reportid: '',
  9. name: '评估说明', // 默认展示: 评估说明 小结 ReportTotal, 系统:用具体的中文名称
  10. systemName: ['评估说明','检测小结','循环系统', '呼吸系统', '消化系统','泌尿系统', '血液系统', '内分泌系统', '营养代谢', '神经系统', '免疫系统', '运动系统', '感官系统', '理化因素', '情绪压力'],
  11. leftNavActive: 0, // 0 小结 1 系统
  12. summaryList: [],
  13. systemList: [],
  14. realName: '',
  15. addTime: ''
  16. },
  17. /**
  18. * 生命周期函数--监听页面加载
  19. */
  20. onLoad(options) {
  21. this.setData({
  22. reportId: options.reportid
  23. })
  24. this.getReportUserInfoFn(options.reportid)
  25. },
  26. // 获取当前报告人的信息
  27. getReportUserInfoFn (reportid) {
  28. var that = this
  29. getReportUserInfo({
  30. reportId: reportid
  31. }).then(res => {
  32. that.setData({
  33. addTime: res.data.addTime,
  34. realName: res.data.realName
  35. })
  36. })
  37. },
  38. // 获取具体的报告信息
  39. getReportFn () {
  40. var that = this
  41. var data = {
  42. reportId: this.data.reportId,
  43. name: this.data.name
  44. }
  45. wx.showLoading({
  46. title: '加载中...',
  47. mask: true
  48. })
  49. getReport(data).then(res => {
  50. wx.hideLoading()
  51. if (that.data.name == 'ReportTotal' || that.data.name == '精神及心理') {
  52. that.setData({
  53. summaryList: res.data || []
  54. })
  55. } else {
  56. that.handleRespose(res.data)
  57. }
  58. }).catch(e => {
  59. wx.hideLoading()
  60. wx.showModal({
  61. content: e,
  62. confirmColor: '#333',
  63. showCancel: false
  64. })
  65. })
  66. },
  67. // 处理系统返回的数据
  68. handleRespose (response) {
  69. var outKey = Object.keys(response)
  70. var result = []
  71. for (var index = 0; index < outKey.length; index++) {
  72. const element = outKey[index];
  73. const innetList = Object.keys(response[element])
  74. var tempArr = []
  75. for (var i = 0; i < innetList.length; i++) {
  76. const innerElement = innetList[i];
  77. tempArr.push({
  78. fatherName: element,
  79. name: innerElement,
  80. value: response[element][innerElement]
  81. })
  82. }
  83. result.push(
  84. {
  85. name: element,
  86. childNode: tempArr
  87. }
  88. )
  89. }
  90. this.handleSortFn(result)
  91. },
  92. // 排序函数
  93. handleSortFn (result) {
  94. var handleResult = [...result]
  95. for (var index = 0; index < handleResult.length; index++) {
  96. const element = handleResult[index];
  97. hanldSort(element.childNode)
  98. }
  99. function hanldSort (childNode) {
  100. childNode.sort(function(a,b){
  101. return b.value - a.value
  102. })
  103. }
  104. this.setData({
  105. systemList: handleResult
  106. })
  107. },
  108. /**
  109. * 用户点击左侧系统分类
  110. */
  111. async handleSwitchNav(e) {
  112. var that = this
  113. var navIndex = e.currentTarget.dataset.index
  114. var navName = that.data.systemName[navIndex]
  115. if (navIndex == 0) {
  116. that.setData({
  117. name: navName
  118. })
  119. } else {
  120. if (navIndex == 1) {
  121. that.setData({
  122. name: 'ReportTotal'
  123. })
  124. } else {
  125. if (navName == '情绪压力') {
  126. navName = '精神及心理'
  127. }
  128. if (navName == '泌尿系统') {
  129. navName = '泌尿与生殖系统'
  130. }
  131. if (navName == '营养代谢') {
  132. navName = '营养与代谢'
  133. }
  134. that.setData({
  135. name: navName
  136. })
  137. }
  138. await that.getReportFn()
  139. }
  140. that.setData({
  141. leftNavActive: navIndex
  142. })
  143. }
  144. })