reportDetail.js 2.9 KB

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