123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- // pages/reportDetail/reportDetail.js
- import { getReport } from '../../api/my'
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- reportid: '',
- name: 'ReportTotal', // 默认 小结 ReportTotal, 系统:用具体的中文名称
- systemName: ['检测小结','循环系统', '呼吸系统', '消化系统','泌尿与生殖系统', '血液系统', '内分泌系统', '营养与代谢', '神经系统', '免疫系统', '运动系统', '感官系统', '理化因素', '精神及心理'],
- leftNavActive: 0, // 0 小结 1 系统
- summaryList: [],
- systemList: [1,1,1,1,1,1,1,1,1,1]
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
- this.setData({
- name: 'ReportTotal',
- leftNavActive: 0,
- reportId: options.reportid
- })
- this.getReportFn()
- },
- // 获取具体的报告信息
- getReportFn () {
- var that = this
- var data = {
- reportId: this.data.reportId,
- name: this.data.name
- }
- wx.showLoading({
- title: '加载中...',
- mask: true
- })
- getReport(data).then(res => {
- wx.hideLoading()
- if (that.data.name == 'ReportTotal') {
- that.setData({
- summaryList: res.data || []
- })
- } else {
- that.handleRespose(res.data)
- }
- }).catch(e => {
- wx.hideLoading()
- wx.showModal({
- content: e,
- confirmColor: '#333',
- showCancel: false
- })
- })
- },
- // 处理系统返回的数据
- handleRespose (response) {
- console.log('response',response);
- var outKey = Object.keys(response)
- var result = []
- for (var index = 0; index < outKey.length; index++) {
- const element = outKey[index];
- const innetList = Object.keys(response[element])
- var tempArr = []
- for (var i = 0; i < innetList.length; i++) {
- const innerElement = innetList[i];
- tempArr.push({
- fatherName: element,
- name: innerElement,
- value: response[element][innerElement]
- })
- }
- result.push(
- {
- name: element,
- childNode: tempArr
- }
- )
- }
- this.handleSortFn(result)
- },
- // 排序函数
- handleSortFn (result) {
- var handleResult = [...result]
- for (var index = 0; index < handleResult.length; index++) {
- const element = handleResult[index];
- hanldSort(element.childNode)
- }
- function hanldSort (childNode) {
- childNode.sort(function(a,b){
- return b.value - a.value
- })
- }
- this.setData({
- systemList: handleResult
- })
- },
- /**
- * 用户点击左侧系统分类
- */
- async handleSwitchNav(e) {
- var that = this
- var navIndex = e.currentTarget.dataset.index
- var navName = that.data.systemName[navIndex]
- if (navIndex == 0) {
- that.setData({
- name: 'ReportTotal'
- })
- } else {
- that.setData({
- name: navName
- })
- }
- await that.getReportFn()
- that.setData({
- leftNavActive: navIndex
- })
- }
- })
|