reportDetail.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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. systemNameList: [
  11. {
  12. index: 0,
  13. viewName: '评估说明',
  14. reqName: '评估说明'
  15. },
  16. {
  17. index: 1,
  18. viewName: '检测小结',
  19. reqName: 'ReportTotal'
  20. },
  21. {
  22. index: 2,
  23. viewName: '循环系统',
  24. reqName: '循环系统'
  25. },
  26. {
  27. index: 3,
  28. viewName: '呼吸系统',
  29. reqName: '呼吸系统'
  30. },
  31. {
  32. index: 4,
  33. viewName: '消化系统',
  34. reqName: '消化系统'
  35. },
  36. {
  37. index: 5,
  38. viewName: '泌尿系统',
  39. reqName: '泌尿与生殖系统'
  40. },
  41. {
  42. index: 6,
  43. viewName: '血液系统',
  44. reqName: '血液系统'
  45. },
  46. {
  47. index: 7,
  48. viewName: '内分泌系统',
  49. reqName: '内分泌系统'
  50. },
  51. {
  52. index: 8,
  53. viewName: '营养代谢',
  54. reqName: '营养与代谢'
  55. },
  56. {
  57. index: 9,
  58. viewName: '神经系统',
  59. reqName: '神经系统'
  60. },
  61. {
  62. index: 10,
  63. viewName: '免疫系统',
  64. reqName: '免疫系统'
  65. },
  66. {
  67. index: 11,
  68. viewName: '运动系统',
  69. reqName: '运动系统'
  70. },
  71. {
  72. index: 12,
  73. viewName: '感官系统',
  74. reqName: '感官系统'
  75. },
  76. {
  77. index: 13,
  78. viewName: '理化因素',
  79. reqName: '理化因素'
  80. },
  81. {
  82. index: 14,
  83. viewName: '情绪压力',
  84. reqName: '精神及心理'
  85. }
  86. ],
  87. leftNavActive: 0, // 0 小结 1 系统
  88. summaryList: [],
  89. systemList: [],
  90. realName: '',
  91. addTime: ''
  92. },
  93. /**
  94. * 生命周期函数--监听页面加载
  95. */
  96. onLoad(options) {
  97. this.setData({
  98. reportId: options.reportid,
  99. leftNavActive: 0,
  100. name: '评估说明'
  101. })
  102. this.getReportUserInfoFn(options.reportid)
  103. },
  104. // 获取当前报告人的信息
  105. getReportUserInfoFn (reportid) {
  106. var that = this
  107. getReportUserInfo({
  108. reportId: reportid
  109. }).then(res => {
  110. that.setData({
  111. addTime: res.data.addTime,
  112. realName: res.data.realName
  113. })
  114. })
  115. },
  116. // 获取具体的报告信息
  117. getReportFn () {
  118. var that = this
  119. var data = {
  120. reportId: this.data.reportId,
  121. name: this.data.name
  122. }
  123. wx.showLoading({
  124. title: '加载中...',
  125. mask: true
  126. })
  127. getReport(data).then(res => {
  128. wx.hideLoading()
  129. if (that.data.name == 'ReportTotal' || that.data.name == '精神及心理') {
  130. that.setData({
  131. summaryList: res.data || []
  132. })
  133. } else {
  134. that.handleRespose(res.data)
  135. }
  136. }).catch(e => {
  137. wx.hideLoading()
  138. wx.showModal({
  139. content: e,
  140. confirmColor: '#333',
  141. showCancel: false
  142. })
  143. })
  144. },
  145. // 处理系统返回的数据
  146. handleRespose (response) {
  147. var outKey = Object.keys(response)
  148. var result = []
  149. for (var index = 0; index < outKey.length; index++) {
  150. const element = outKey[index];
  151. const innetList = Object.keys(response[element])
  152. var tempArr = []
  153. for (var i = 0; i < innetList.length; i++) {
  154. const innerElement = innetList[i];
  155. tempArr.push({
  156. fatherName: element,
  157. name: innerElement,
  158. value: response[element][innerElement]
  159. })
  160. }
  161. result.push(
  162. {
  163. name: element,
  164. childNode: tempArr
  165. }
  166. )
  167. }
  168. this.handleSortFn(result)
  169. },
  170. // 排序函数
  171. handleSortFn (result) {
  172. var handleResult = [...result]
  173. for (var index = 0; index < handleResult.length; index++) {
  174. const element = handleResult[index];
  175. hanldSort(element.childNode)
  176. }
  177. function hanldSort (childNode) {
  178. childNode.sort(function(a,b){
  179. return b.value - a.value
  180. })
  181. }
  182. this.setData({
  183. systemList: handleResult
  184. })
  185. },
  186. /**
  187. * 用户点击左侧系统分类
  188. */
  189. handleSwitchNav(e) {
  190. var navIndex = e.currentTarget.dataset.index
  191. var reqName = e.currentTarget.dataset.reqname
  192. this.setData({
  193. name: reqName,
  194. leftNavActive: navIndex
  195. })
  196. this.getReportFn()
  197. }
  198. })