reportDetail.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  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.showNavigationBarLoading()
  204. await this.getReportUserInfoFn(reportid)
  205. await this.getReportFn(this.data.systemNameList[1].reqName).then(response => {
  206. that.setData({
  207. systemNameList1Res: response || []
  208. })
  209. })
  210. await this.getReportFn(this.data.systemNameList[2].reqName).then(response => {
  211. const handleRespose = that.handleRespose(response)
  212. that.setData({
  213. systemNameList2Res: handleRespose
  214. })
  215. })
  216. await this.getReportFn(this.data.systemNameList[3].reqName).then(response => {
  217. const handleRespose = that.handleRespose(response)
  218. that.setData({
  219. systemNameList3Res: handleRespose
  220. })
  221. })
  222. await this.getReportFn(this.data.systemNameList[4].reqName).then(response => {
  223. const handleRespose = that.handleRespose(response)
  224. that.setData({
  225. systemNameList4Res: handleRespose
  226. })
  227. })
  228. await this.getReportFn(this.data.systemNameList[5].reqName).then(response => {
  229. const handleRespose = that.handleRespose(response)
  230. that.setData({
  231. systemNameList5Res: handleRespose
  232. })
  233. })
  234. await this.getReportFn(this.data.systemNameList[6].reqName).then(response => {
  235. const handleRespose = that.handleRespose(response)
  236. that.setData({
  237. systemNameList6Res: handleRespose
  238. })
  239. })
  240. await this.getReportFn(this.data.systemNameList[7].reqName).then(response => {
  241. const handleRespose = that.handleRespose(response)
  242. that.setData({
  243. systemNameList7Res: handleRespose
  244. })
  245. })
  246. await this.getReportFn(this.data.systemNameList[8].reqName).then(response => {
  247. const handleRespose = that.handleRespose(response)
  248. that.setData({
  249. systemNameList8Res: handleRespose
  250. })
  251. })
  252. await this.getReportFn(this.data.systemNameList[9].reqName).then(response => {
  253. const handleRespose = that.handleRespose(response)
  254. that.setData({
  255. systemNameList9Res: handleRespose
  256. })
  257. })
  258. await this.getReportFn(this.data.systemNameList[10].reqName).then(response => {
  259. const handleRespose = that.handleRespose(response)
  260. that.setData({
  261. systemNameList10Res: handleRespose
  262. })
  263. })
  264. await this.getReportFn(this.data.systemNameList[11].reqName).then(response => {
  265. const handleRespose = that.handleRespose(response)
  266. that.setData({
  267. systemNameList11Res: handleRespose
  268. })
  269. })
  270. await this.getReportFn(this.data.systemNameList[12].reqName).then(response => {
  271. const handleRespose = that.handleRespose(response)
  272. that.setData({
  273. systemNameList12Res: handleRespose
  274. })
  275. })
  276. await this.getReportFn(this.data.systemNameList[13].reqName).then(response => {
  277. const handleRespose = that.handleRespose(response)
  278. that.setData({
  279. systemNameList13Res: handleRespose
  280. })
  281. })
  282. await this.getReportFn(this.data.systemNameList[14].reqName).then(response => {
  283. that.setData({
  284. systemNameList14Res: response
  285. })
  286. })
  287. wx.hideNavigationBarLoading()
  288. },
  289. // 获取当前报告人的信息
  290. getReportUserInfoFn (reportid) {
  291. var that = this
  292. return new Promise((reslove,reject) => {
  293. getReportUserInfo({
  294. reportId: reportid
  295. }).then(res => {
  296. wx.hideLoading()
  297. that.setData({
  298. addTime: res.data.addTime,
  299. realName: res.data.realName
  300. })
  301. reslove(res)
  302. })
  303. })
  304. },
  305. // 获取具体的报告信息
  306. getReportFn (name, index = 0) {
  307. var that = this
  308. var data = {
  309. reportId: this.data.reportId,
  310. name: name
  311. }
  312. return new Promise((resolve, reject) => {
  313. getReport(data).then(res => {
  314. /* if (name == 'ReportTotal' || name == '精神及心理') {
  315. that.setData({
  316. summaryList: res.data || []
  317. })
  318. } else {
  319. that.handleRespose(res.data, index)
  320. } */
  321. resolve(res.data)
  322. }).catch(e => {
  323. reject(e)
  324. wx.showModal({
  325. content: e,
  326. confirmColor: '#333',
  327. showCancel: false
  328. })
  329. })
  330. })
  331. },
  332. // 处理系统返回的数据
  333. handleRespose (response, index) {
  334. var outKey = Object.keys(response)
  335. var result = []
  336. for (var index = 0; index < outKey.length; index++) {
  337. const element = outKey[index];
  338. const innetList = Object.keys(response[element])
  339. var tempArr = []
  340. for (var i = 0; i < innetList.length; i++) {
  341. const innerElement = innetList[i];
  342. tempArr.push({
  343. fatherName: element,
  344. name: innerElement,
  345. value: response[element][innerElement]
  346. })
  347. }
  348. result.push(
  349. {
  350. name: element,
  351. childNode: tempArr
  352. }
  353. )
  354. }
  355. var handleResult = [...result]
  356. for (var index = 0; index < handleResult.length; index++) {
  357. const element = handleResult[index];
  358. hanldSort(element.childNode)
  359. }
  360. function hanldSort (childNode) {
  361. childNode.sort(function(a,b){
  362. return b.value - a.value
  363. })
  364. }
  365. return handleResult
  366. },
  367. // 排序函数
  368. handleSortFn (result) {
  369. var handleResult = [...result]
  370. for (var index = 0; index < handleResult.length; index++) {
  371. const element = handleResult[index];
  372. hanldSort(element.childNode)
  373. }
  374. function hanldSort (childNode) {
  375. childNode.sort(function(a,b){
  376. return b.value - a.value
  377. })
  378. }
  379. this.setData({
  380. systemList: handleResult
  381. })
  382. },
  383. /**
  384. * 用户点击左侧系统分类
  385. */
  386. handleSwitchNav(e) {
  387. var navIndex = e.currentTarget.dataset.index
  388. var toview = e.currentTarget.dataset.toview
  389. this.setData({
  390. leftNavActive: navIndex,
  391. toView: toview
  392. })
  393. }
  394. })