reportDetail.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  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. toview: 'shuoming',
  16. response: []
  17. },
  18. {
  19. index: 1,
  20. viewName: '检测小结',
  21. reqName: 'ReportTotal',
  22. toview: 'xiaojie',
  23. response: []
  24. },
  25. {
  26. index: 2,
  27. viewName: '循环系统',
  28. reqName: '循环系统',
  29. toview: 'xunhuan',
  30. response: []
  31. },
  32. {
  33. index: 3,
  34. viewName: '呼吸系统',
  35. reqName: '呼吸系统',
  36. toview: 'huxi',
  37. response: []
  38. },
  39. {
  40. index: 4,
  41. viewName: '消化系统',
  42. reqName: '消化系统',
  43. toview: 'xiaohua',
  44. response: []
  45. },
  46. {
  47. index: 5,
  48. viewName: '泌尿系统',
  49. reqName: '泌尿与生殖系统',
  50. toview: 'miniao',
  51. response: []
  52. },
  53. {
  54. index: 6,
  55. viewName: '血液系统',
  56. reqName: '血液系统',
  57. toview: 'xuexie',
  58. response: []
  59. },
  60. {
  61. index: 7,
  62. viewName: '内分泌系统',
  63. reqName: '内分泌系统',
  64. toview: 'neifenmi',
  65. response: []
  66. },
  67. {
  68. index: 8,
  69. viewName: '营养代谢',
  70. reqName: '营养与代谢',
  71. toview: 'yinyangdaixie',
  72. response: []
  73. },
  74. {
  75. index: 9,
  76. viewName: '神经系统',
  77. reqName: '神经系统',
  78. toview: 'shenjin',
  79. response: []
  80. },
  81. {
  82. index: 10,
  83. viewName: '免疫系统',
  84. reqName: '免疫系统',
  85. toview: 'mianyi',
  86. response: []
  87. },
  88. {
  89. index: 11,
  90. viewName: '运动系统',
  91. reqName: '运动系统',
  92. toview: 'yundong',
  93. response: []
  94. },
  95. {
  96. index: 12,
  97. viewName: '感官系统',
  98. reqName: '感官系统',
  99. toview: 'ganguan',
  100. response: []
  101. },
  102. {
  103. index: 13,
  104. viewName: '理化因素',
  105. reqName: '理化因素',
  106. toview: 'lihuayinshu',
  107. response: []
  108. },
  109. {
  110. index: 14,
  111. viewName: '情绪压力',
  112. reqName: '精神及心理',
  113. toview: 'qinxuyali',
  114. response: []
  115. }
  116. ],
  117. systemNameList1Res:[],
  118. systemNameList2Res:[],
  119. systemNameList3Res:[],
  120. systemNameList4Res:[],
  121. systemNameList5Res:[],
  122. systemNameList6Res:[],
  123. systemNameList7Res:[],
  124. systemNameList8Res:[],
  125. systemNameList9Res:[],
  126. systemNameList10Res:[],
  127. systemNameList11Res:[],
  128. systemNameList12Res:[],
  129. systemNameList13Res:[],
  130. systemNameList14Res:[],
  131. leftNavActive: 0, // 0 小结 1 系统
  132. summaryList: [],
  133. systemList: [],
  134. realName: '',
  135. addTime: '',
  136. toView: 'shuoming',
  137. scrollIntoViewIndex: 0
  138. },
  139. onUnload() {
  140. this.setData({
  141. scrollIntoViewIndex: 0
  142. })
  143. },
  144. /**
  145. * 生命周期函数--监听页面加载
  146. */
  147. onLoad(options) {
  148. this.setData({
  149. reportId: options.reportid,
  150. leftNavActive: 0,
  151. name: '评估说明'
  152. })
  153. this.getAllReportInfo(options.reportid)
  154. //this.getReportUserInfoFn(options.reportid)
  155. },
  156. bindscroll () {
  157. this.returnTop()
  158. },
  159. returnTop () {
  160. const query = wx.createSelectorQuery()
  161. const that = this
  162. query.select("#shuoming").boundingClientRect()
  163. query.select("#xiaojie").boundingClientRect()
  164. query.select("#xunhuan").boundingClientRect()
  165. query.select("#huxi").boundingClientRect()
  166. query.select("#xiaohua").boundingClientRect()
  167. query.select("#miniao").boundingClientRect()
  168. query.select("#xuexie").boundingClientRect()
  169. query.select("#neifenmi").boundingClientRect()
  170. query.select("#yinyangdaixie").boundingClientRect()
  171. query.select("#shenjin").boundingClientRect()
  172. query.select("#mianyi").boundingClientRect()
  173. query.select("#yundong").boundingClientRect()
  174. query.select("#ganguan").boundingClientRect()
  175. query.select("#lihuayinshu").boundingClientRect()
  176. query.select("#qinxuyali").boundingClientRect()
  177. query.exec(function(res){
  178. that.setLeftNavActive(res)
  179. })
  180. },
  181. setLeftNavActive (TopArr) {
  182. let res = []
  183. TopArr.map((item, index) => {
  184. res.push({
  185. index: index,
  186. id: item.id,
  187. top: Math.abs(item.top)
  188. })
  189. })
  190. const fItem = res.find(item => {
  191. return item.top < 200
  192. })
  193. if (fItem && this.data.scrollIntoViewIndex != fItem.index) {
  194. this.setData({
  195. scrollIntoViewIndex: fItem.index,
  196. leftNavActive: fItem.index
  197. })
  198. }
  199. },
  200. // 获取所有节点的返回信息
  201. async getAllReportInfo (reportid) {
  202. const that = this
  203. wx.showLoading({
  204. title: '加载中...',
  205. mask: true
  206. })
  207. await this.getReportUserInfoFn(reportid)
  208. await this.getReportFn(this.data.systemNameList[1].reqName).then(response => {
  209. that.setData({
  210. systemNameList1Res: response || []
  211. })
  212. })
  213. await this.getReportFn(this.data.systemNameList[2].reqName).then(response => {
  214. const handleRespose = that.handleRespose(response)
  215. that.setData({
  216. systemNameList2Res: handleRespose
  217. })
  218. })
  219. await this.getReportFn(this.data.systemNameList[3].reqName).then(response => {
  220. const handleRespose = that.handleRespose(response)
  221. that.setData({
  222. systemNameList3Res: handleRespose
  223. })
  224. })
  225. await this.getReportFn(this.data.systemNameList[4].reqName).then(response => {
  226. const handleRespose = that.handleRespose(response)
  227. that.setData({
  228. systemNameList4Res: handleRespose
  229. })
  230. })
  231. await this.getReportFn(this.data.systemNameList[5].reqName).then(response => {
  232. const handleRespose = that.handleRespose(response)
  233. that.setData({
  234. systemNameList5Res: handleRespose
  235. })
  236. })
  237. await this.getReportFn(this.data.systemNameList[6].reqName).then(response => {
  238. const handleRespose = that.handleRespose(response)
  239. that.setData({
  240. systemNameList6Res: handleRespose
  241. })
  242. })
  243. await this.getReportFn(this.data.systemNameList[7].reqName).then(response => {
  244. const handleRespose = that.handleRespose(response)
  245. that.setData({
  246. systemNameList7Res: handleRespose
  247. })
  248. })
  249. await this.getReportFn(this.data.systemNameList[8].reqName).then(response => {
  250. const handleRespose = that.handleRespose(response)
  251. that.setData({
  252. systemNameList8Res: handleRespose
  253. })
  254. })
  255. await this.getReportFn(this.data.systemNameList[9].reqName).then(response => {
  256. const handleRespose = that.handleRespose(response)
  257. that.setData({
  258. systemNameList9Res: handleRespose
  259. })
  260. })
  261. await this.getReportFn(this.data.systemNameList[10].reqName).then(response => {
  262. const handleRespose = that.handleRespose(response)
  263. that.setData({
  264. systemNameList10Res: handleRespose
  265. })
  266. })
  267. await this.getReportFn(this.data.systemNameList[11].reqName).then(response => {
  268. const handleRespose = that.handleRespose(response)
  269. that.setData({
  270. systemNameList11Res: handleRespose
  271. })
  272. })
  273. await this.getReportFn(this.data.systemNameList[12].reqName).then(response => {
  274. const handleRespose = that.handleRespose(response)
  275. that.setData({
  276. systemNameList12Res: handleRespose
  277. })
  278. })
  279. await this.getReportFn(this.data.systemNameList[13].reqName).then(response => {
  280. const handleRespose = that.handleRespose(response)
  281. that.setData({
  282. systemNameList13Res: handleRespose
  283. })
  284. })
  285. await this.getReportFn(this.data.systemNameList[14].reqName).then(response => {
  286. that.setData({
  287. systemNameList14Res: response
  288. })
  289. })
  290. wx.hideLoading()
  291. },
  292. // 获取当前报告人的信息
  293. getReportUserInfoFn (reportid) {
  294. var that = this
  295. return new Promise((reslove,reject) => {
  296. getReportUserInfo({
  297. reportId: reportid
  298. }).then(res => {
  299. that.setData({
  300. addTime: res.data.addTime,
  301. realName: res.data.realName
  302. })
  303. reslove(res)
  304. })
  305. })
  306. },
  307. // 获取具体的报告信息
  308. getReportFn (name, index = 0) {
  309. var that = this
  310. var data = {
  311. reportId: this.data.reportId,
  312. name: name
  313. }
  314. return new Promise((resolve, reject) => {
  315. getReport(data).then(res => {
  316. /* if (name == 'ReportTotal' || name == '精神及心理') {
  317. that.setData({
  318. summaryList: res.data || []
  319. })
  320. } else {
  321. that.handleRespose(res.data, index)
  322. } */
  323. resolve(res.data)
  324. }).catch(e => {
  325. reject(e)
  326. wx.showModal({
  327. content: e,
  328. confirmColor: '#333',
  329. showCancel: false
  330. })
  331. })
  332. })
  333. },
  334. // 处理系统返回的数据
  335. handleRespose (response, index) {
  336. var outKey = Object.keys(response)
  337. var result = []
  338. for (var index = 0; index < outKey.length; index++) {
  339. const element = outKey[index];
  340. const innetList = Object.keys(response[element])
  341. var tempArr = []
  342. for (var i = 0; i < innetList.length; i++) {
  343. const innerElement = innetList[i];
  344. tempArr.push({
  345. fatherName: element,
  346. name: innerElement,
  347. value: response[element][innerElement]
  348. })
  349. }
  350. result.push(
  351. {
  352. name: element,
  353. childNode: tempArr
  354. }
  355. )
  356. }
  357. var handleResult = [...result]
  358. for (var index = 0; index < handleResult.length; index++) {
  359. const element = handleResult[index];
  360. hanldSort(element.childNode)
  361. }
  362. function hanldSort (childNode) {
  363. childNode.sort(function(a,b){
  364. return b.value - a.value
  365. })
  366. }
  367. return handleResult
  368. },
  369. // 排序函数
  370. handleSortFn (result) {
  371. var handleResult = [...result]
  372. for (var index = 0; index < handleResult.length; index++) {
  373. const element = handleResult[index];
  374. hanldSort(element.childNode)
  375. }
  376. function hanldSort (childNode) {
  377. childNode.sort(function(a,b){
  378. return b.value - a.value
  379. })
  380. }
  381. this.setData({
  382. systemList: handleResult
  383. })
  384. },
  385. /**
  386. * 用户点击左侧系统分类
  387. */
  388. handleSwitchNav(e) {
  389. var navIndex = e.currentTarget.dataset.index
  390. var toview = e.currentTarget.dataset.toview
  391. this.setData({
  392. leftNavActive: navIndex,
  393. toView: toview
  394. })
  395. }
  396. })