reportDetail.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. // pages/reportDetail/reportDetail.js
  2. import { getReport } 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. addTime: options.addTime,
  24. realName: options.realName
  25. })
  26. },
  27. // 获取具体的报告信息
  28. getReportFn () {
  29. var that = this
  30. var data = {
  31. reportId: this.data.reportId,
  32. name: this.data.name
  33. }
  34. wx.showLoading({
  35. title: '加载中...',
  36. mask: true
  37. })
  38. getReport(data).then(res => {
  39. wx.hideLoading()
  40. if (that.data.name == 'ReportTotal' || that.data.name == '精神及心理') {
  41. console.log(that.data.name == '精神及心理');
  42. that.setData({
  43. summaryList: res.data || []
  44. })
  45. console.log(that.data.summaryList);
  46. } else {
  47. that.handleRespose(res.data)
  48. }
  49. }).catch(e => {
  50. wx.hideLoading()
  51. wx.showModal({
  52. content: e,
  53. confirmColor: '#333',
  54. showCancel: false
  55. })
  56. })
  57. },
  58. // 处理系统返回的数据
  59. handleRespose (response) {
  60. var outKey = Object.keys(response)
  61. var result = []
  62. for (var index = 0; index < outKey.length; index++) {
  63. const element = outKey[index];
  64. const innetList = Object.keys(response[element])
  65. var tempArr = []
  66. for (var i = 0; i < innetList.length; i++) {
  67. const innerElement = innetList[i];
  68. tempArr.push({
  69. fatherName: element,
  70. name: innerElement,
  71. value: response[element][innerElement]
  72. })
  73. }
  74. result.push(
  75. {
  76. name: element,
  77. childNode: tempArr
  78. }
  79. )
  80. }
  81. this.handleSortFn(result)
  82. },
  83. // 排序函数
  84. handleSortFn (result) {
  85. var handleResult = [...result]
  86. for (var index = 0; index < handleResult.length; index++) {
  87. const element = handleResult[index];
  88. hanldSort(element.childNode)
  89. }
  90. function hanldSort (childNode) {
  91. childNode.sort(function(a,b){
  92. return b.value - a.value
  93. })
  94. }
  95. this.setData({
  96. systemList: handleResult
  97. })
  98. },
  99. /**
  100. * 用户点击左侧系统分类
  101. */
  102. async handleSwitchNav(e) {
  103. var that = this
  104. var navIndex = e.currentTarget.dataset.index
  105. var navName = that.data.systemName[navIndex]
  106. if (navIndex == 0) {
  107. that.setData({
  108. name: navName
  109. })
  110. } else {
  111. if (navIndex == 1) {
  112. that.setData({
  113. name: 'ReportTotal'
  114. })
  115. } else {
  116. that.setData({
  117. name: navName
  118. })
  119. }
  120. await that.getReportFn()
  121. }
  122. that.setData({
  123. leftNavActive: navIndex
  124. })
  125. }
  126. })