xueya-view.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554
  1. var switchery = null;
  2. var date = new Date();
  3. var year = date.getFullYear();
  4. var begindate;
  5. var enddate;
  6. var page = 1;
  7. var pagesize = 10;
  8. var pagetype = 5;
  9. var patientCode = "";
  10. var charType = 1;
  11. var scroller1 = null;
  12. var self = null;
  13. var type = null;
  14. var charts = [];
  15. var $viewTabs = $('#viewTabs'),
  16. $swiperWrapper = $('.swiper-wrapper'),
  17. $duringList = $('#duringList'),
  18. $qushiView = $('#qushiView'),
  19. $liebiaoView = $('#liebiaoView'),
  20. $xtEdit = $('.xt-edit'),
  21. $btns = $('.btns'),
  22. $cancelBtn = $('.cancel-btn'),
  23. $okBtn = $('.ok-btn'),
  24. $xtAdd = $('.xt-add'),
  25. $popMain = $('.pop-main'),
  26. $popBtns = $('.pop-btns'),
  27. $popEditBtn = $('.pop-edit-btn'),
  28. $popDelBtn = $('.pop-del-btn'),
  29. $popCancelBtn = $('.pop-cancel-btn'),
  30. $selDate = $('#selDate'),
  31. swiper = null,
  32. d1 = [],
  33. d2 = [],
  34. d3 = [],
  35. d4 = [],
  36. page = 0,
  37. pagesize = 10,
  38. $zcNum = $('.ss-zc-num'),
  39. $pgNum = $('.ss-pg-num'),
  40. $pdNum = $('.ss-pd-num'),
  41. dayNum = 6,
  42. $xyList = $('.xy-list-con'),
  43. $xyTmp = $('#xyTmp'),
  44. thatIndex = 1,
  45. isTrue = false,
  46. isLoad = false;
  47. var norTime = '',
  48. enddate = '',
  49. sn = 0;
  50. mui.plusReady(function() {
  51. self = plus.webview.currentWebview();
  52. patientCode = self.code;
  53. begindate = self.dateT;
  54. norTime = self.dateT;
  55. enddate = getDateFromCurrentDate(begindate, -dayNum);
  56. type = self.type;
  57. bindEvents();
  58. scroller1 = new IScrollPullUpDown('wrapper6', {
  59. probeType: 2,
  60. bounceTime: 250,
  61. bounceEasing: 'quadratic',
  62. mouseWheel: false,
  63. scrollbars: true,
  64. fadeScrollbars: true,
  65. interactiveScrollbars: false,
  66. click: true,
  67. }, null, pullUpAction);
  68. // checkLoad(thatIndex);
  69. init();
  70. });
  71. function changeTabCon() {
  72. var qsv = $qushiView.css('display'),
  73. lbv = $liebiaoView.css('display');
  74. if(qsv === 'block') {
  75. lbv.hide();
  76. }
  77. }
  78. function getxAxisData(data) {
  79. var a = [],
  80. b = [];
  81. b = _.chain(data).pluck('date').map(function(d) {
  82. return d.substr(5, 5)
  83. }).value();
  84. for(var i = b.length - 1; i >= 0; i--) {
  85. a.push(b[i]);
  86. }
  87. return a;
  88. }
  89. function buildData1(value, max, min) {
  90. if((value > 0 && value < min) || value > max) {
  91. return {
  92. value: value,
  93. itemStyle: {
  94. normal: {
  95. color: '#f00'
  96. }
  97. }
  98. }
  99. } else {
  100. return value
  101. }
  102. }
  103. //初始化图表数据
  104. function initCD(list, n) {
  105. var seriesArray = [];
  106. var data1 = new Array();
  107. var data2 = new Array();
  108. var allDatas = new Array();
  109. var xynum = {};
  110. for(var i = 0; i < list.length; i++) {
  111. var data = list[i];
  112. if(!data) {
  113. continue;
  114. }
  115. data1.unshift(buildData1(data.value1, 139, 90));
  116. data2.unshift(buildData1(data.value2, 89, 60));
  117. }
  118. allDatas.unshift(data1);
  119. allDatas.unshift(data2);
  120. for(var i = 0; i < allDatas.length; i++) {
  121. var na = (i == 1 ? '收缩压' : '舒张压');
  122. var series = {
  123. name: na,
  124. type: 'line',
  125. symbol: 'emptyCircle',
  126. layerPadding: 0,
  127. nodePadding: 0,
  128. itemStyle: {
  129. normal: {
  130. borderWidth: 8,
  131. color: '#0ad800',
  132. lineStyle: { // 系列级个性化折线样式,横向渐变描边
  133. borderWidth: 2,
  134. color: i == 1 ? '#CC66FF' : '#5dd1d2',
  135. width: 4
  136. },
  137. nodeStyle: {
  138. borderWidth: 2,
  139. color: '#93DB70',
  140. borderColor: '#93DB70'
  141. }
  142. },
  143. emphasis: {
  144. label: {
  145. show: true
  146. }
  147. }
  148. },
  149. data: allDatas[i]
  150. };
  151. seriesArray.unshift(series);
  152. }
  153. return seriesArray;
  154. }
  155. function queryListByTypeP(type, begindate, enddate, page, pagesize, code) {
  156. plus.nativeUI.showWaiting();
  157. //拼请求内容
  158. var params = {};
  159. params.type = type;
  160. params.page = page;
  161. params.pagesize = pagesize;
  162. params.begin = begindate + " 00:00:00";
  163. params.end = enddate + " 23:59:59";
  164. params.patient = code;
  165. return new Promise(function(resolve, reject) {
  166. sendPost("doctor/health_index/list", params, function(res) {
  167. resolve(res)
  168. console.log(res);
  169. }, function(res) {
  170. if(res.status == 200) {
  171. plus.nativeUI.closeWaiting();
  172. resolve(res)
  173. } else {
  174. queryListFailed(res);
  175. }
  176. });
  177. })
  178. }
  179. function getSeriesData(data) {
  180. var a = [];
  181. for(var i = 1; i <= 2; i++) {
  182. a.unshift((_.chain(data).pluck('value' + i).map(function(v) {
  183. if(i == 1) {
  184. return buildData1(v, 139, 90);
  185. }
  186. if(i == 2) {
  187. return buildData1(v, 89, 60);
  188. }
  189. }).value()));
  190. }
  191. return a;
  192. }
  193. var val1 = [],
  194. val2 = [],
  195. val3 = [],
  196. val4 = [];
  197. function calNum(d, v, n1, n2) {
  198. var vv = {
  199. zc: 0,
  200. pg: 0,
  201. pd: 0
  202. };
  203. for(var i = 0, len = d.length; i < len; i++) {
  204. var data = d[i];
  205. if(data[v] > 0 && data[v] < n2) { //偏低
  206. vv.pd++;
  207. } else if(data[v] > n1) { //偏高
  208. vv.pg++;
  209. } else {
  210. vv.zc++;
  211. }
  212. }
  213. return vv;
  214. }
  215. //上拉加载数据
  216. function pullUpAction(theScrollerTemp) {
  217. $(".pullUp").show();
  218. setTimeout(function() {
  219. loadListPromise();
  220. }, 1000);
  221. }
  222. function loadListPromise() {
  223. page++;
  224. Promise.all([
  225. queryListByTypeP(2, getDateFromCurrentDate(norTime, -2000), norTime, page, pagesize, patientCode)
  226. ])
  227. .then(function(res) {
  228. $(".pullUp").hide();
  229. var data = res[0];
  230. if (data.list.length > 0) {
  231. console.log(data.list);
  232. $xyList.append(template('xyTmp', {
  233. data: data.list
  234. }));
  235. scroller1.refresh();
  236. } else {
  237. if(!isLoad) {
  238. mui.toast("暂无数据!");
  239. } else {
  240. mui.toast("暂无更多数据!");
  241. }
  242. }
  243. isLoad = true;
  244. })
  245. .catch(function(e) {
  246. console && console.error(e)
  247. });
  248. }
  249. //初始化swiper
  250. function init() {
  251. Promise.all([(function() {
  252. $swiperWrapper
  253. .append($('<li id="chart0" class="swiper-slide"> </li>'))
  254. .append($('<li id="chart1" class="swiper-slide"> </li>'))
  255. .append($('<li id="chart2" class="swiper-slide"> </li>'))
  256. .append($('<li id="chart3" class="swiper-slide"> </li>'));
  257. })()])
  258. .then(function(echarts) {
  259. swiper = new Swiper('.swiper-container', {
  260. paginationClickable: false,
  261. onSlideChangeStart: function(swiper) {
  262. //切换
  263. var ind = swiper.activeIndex;
  264. if(ind < sn) {
  265. begindate = enddate;
  266. enddate = getDateFromCurrentDate(begindate, -dayNum);
  267. } else {
  268. enddate = begindate;
  269. begindate = getDateFromCurrentDate(begindate, dayNum);
  270. }
  271. sn = ind;
  272. loadPromise(sn, enddate, begindate);
  273. }
  274. });
  275. })
  276. .then(function() {
  277. $swiperWrapper.find('.swiper-slide');
  278. swiper.slideTo(swiper.slides.length - 1, 0, false); //切换到最后一个slide
  279. sn = swiper.slides.length - 1;
  280. loadPromise(sn, enddate, begindate);
  281. })
  282. .catch(function(e) {
  283. console && console.error(e)
  284. })
  285. }
  286. function loadPromise(n, enddate, begindate) {
  287. plus.nativeUI.showWaiting();
  288. Promise.all([
  289. queryChatByTypePromise(2, enddate, begindate, 0, patientCode)
  290. ])
  291. .then(function(res) {
  292. d1 = res[0];
  293. loadData(n);
  294. })
  295. .catch(function(e) {
  296. console && console.error(e)
  297. });
  298. }
  299. function getZcNum (d) {
  300. var vv = {"ss_zc":0, "sz_zc": 0};
  301. for (var i = 0,len = d.length; i < len; i++) {
  302. if (d[i]['value1'] >= 90 && d[i]['value1'] <= 139) {
  303. vv.ss_zc ++;
  304. }else if(d[i]['value2'] >= 60 && d[i]['value2'] <= 89){
  305. vv.sz_zc ++;
  306. }
  307. }
  308. return vv;
  309. }
  310. //初始化echart
  311. function loadData(n) {
  312. new Promise(function(resolve, reject) {
  313. var yAxisName = '单位(mmHg)';
  314. if (typeof d1.list == 'undefined') {
  315. d1.list = [];
  316. }
  317. var el = document.getElementById('chart' + n);
  318. val1['value1'] = calNum(d1.list, 'value1', 139, 90);
  319. val1['value2'] = calNum(d1.list, 'value2', 89, 60);
  320. var zc = getZcNum(d1.list);
  321. $zcNum.html(zc.ss_zc);
  322. $('.sz-zc-num').html(zc.sz_zc);
  323. // $pgNum.html(Math.max(val1['value1'].pg, val1['value2'].pg)),
  324. // $pdNum.html(Math.max(val1['value1'].pd, val1['value2'].pd));
  325. $pgNum.html(val1['value1'].pg);
  326. $pdNum.html(val1['value1'].pd);
  327. $(".sz-pg-num").html(val1['value2'].pg);
  328. $(".sz-pd-num").html(val1['value2'].pd);
  329. Promise.all([
  330. createChartPromise(el, 2, yAxisName, getxAxisData(d1.list), initCD(d1.list))
  331. ])
  332. .then(function(echarts) {
  333. plus.nativeUI.closeWaiting();
  334. charts.push(echarts[0]);
  335. $(el).append('<div class="c-time">< ' + enddate + ' 至 ' + begindate + ' ></div>');
  336. })
  337. .then(function() {
  338. })
  339. .catch(function(e) {
  340. console && console.error(e)
  341. })
  342. });
  343. }
  344. //function loadPromise(t, cb) {
  345. // Promise.all([
  346. // queryChatByTypePromise(2, getBeforeDate(begindate, 7), begindate, 0, patientCode),
  347. // queryChatByTypePromise(2, getBeforeDate(begindate, 30), begindate, 0, patientCode),
  348. // queryChatByTypePromise(2, getBeforeDate(begindate, 90), begindate, 0, patientCode),
  349. // queryChatByTypePromise(2, getBeforeDate(begindate, 365 / 2), begindate, 0, patientCode)
  350. // ])
  351. // .then(function(res) {
  352. // plus.nativeUI.closeWaiting();
  353. // d1 = res[0];
  354. // d2 = res[1];
  355. // d3 = res[2];
  356. // d4 = res[3];
  357. //
  358. // cb && cb.call(this);
  359. // })
  360. // .catch(function(e) {
  361. // console && console.error(e)
  362. // });
  363. //}
  364. //
  365. //function loadData() {
  366. // new Promise(function(resolve, reject) {
  367. // var yAxisName = '单位(mmHg)';
  368. // $swiperWrapper
  369. // .append('<li id="chart3" class="swiper-slide">')
  370. // .append('<li id="chart2" class="swiper-slide">')
  371. // .append('<li id="chart1" class="swiper-slide">')
  372. // .append('<li id="chart0" class="swiper-slide">');
  373. //
  374. // var el1 = document.getElementById('chart0'),
  375. // el2 = document.getElementById('chart1'),
  376. // el3 = document.getElementById('chart2'),
  377. // el4 = document.getElementById('chart3')
  378. // Promise.all([
  379. // createChartPromise(el1, 2, yAxisName, getxAxisData(d1.list), initCD(d1.list)),
  380. // createChartPromise(el2, 2, yAxisName, getxAxisData(d2.list), initCD(d2.list)),
  381. // createChartPromise(el3, 2, yAxisName, getxAxisData(d3.list), initCD(d3.list)),
  382. // createChartPromise(el4, 2, yAxisName, getxAxisData(d4.list), initCD(d4.list))
  383. // ])
  384. // .then(function(echarts) {
  385. // charts.push(echarts[0]);
  386. // charts.push(echarts[1]);
  387. // charts.push(echarts[2]);
  388. // $(el1).append('<div class="c-time">< ' + getBeforeDate(begindate, 7) + ' 至 ' + begindate + ' ></div>');
  389. // $(el2).append('<div class="c-time">< ' + getBeforeDate(begindate, 30) + ' 至 ' + begindate + ' ></div>');
  390. // $(el3).append('<div class="c-time">< ' + getBeforeDate(begindate, 90) + ' 至 ' + begindate + ' ></div>');
  391. // $(el4).append('<div class="c-time">< ' + getBeforeDate(begindate, 365 / 2) + ' 至 ' + begindate + ' ></div>');
  392. //
  393. // val1['value1'] = calNum(d1.list, 'value1', 139, 90);
  394. // val1['value2'] = calNum(d1.list, 'value2', 89, 60);
  395. // val2['value1'] = calNum(d2.list, 'value1', 139, 90);
  396. // val2['value2'] = calNum(d2.list, 'value2', 89, 60);
  397. // val3['value1'] = calNum(d3.list, 'value1', 139, 90);
  398. // val3['value2'] = calNum(d3.list, 'value2', 89, 60);
  399. // val4['value1'] = calNum(d4.list, 'value1', 139, 90);
  400. // val4['value2'] = calNum(d4.list, 'value2', 89, 60);
  401. //
  402. // $zcNum.html(Math.max(val1['value1'].zc, val1['value2'].zc));
  403. // $pgNum.html(Math.max(val1['value1'].pg, val1['value2'].pg)),
  404. // $pdNum.html(Math.max(val1['value1'].pd, val1['value2'].pd));
  405. //
  406. // })
  407. // .then(function(res) {
  408. // swiper = new Swiper('.swiper-container', {
  409. // paginationClickable: false,
  410. // normalizeSlideIndex: false,
  411. // onSlideChangeStart: function(swiper) {
  412. // var ind = swiper.activeIndex;
  413. // console.log(ind);
  414. // switch(ind) {
  415. // case 0:
  416. // $zcNum.html(Math.max(val4['value1'].zc, val4['value2'].zc));
  417. // $pgNum.html(Math.max(val4['value1'].pg, val4['value2'].pg)),
  418. // $pdNum.html(Math.max(val4['value1'].pd, val4['value2'].pd));
  419. // $selDate.find('li').removeClass('curr').eq(3).addClass('curr');
  420. // dayNum = -1;
  421. // break;
  422. // case 1:
  423. // $zcNum.html(Math.max(val3['value1'].zc, val3['value2'].zc));
  424. // $pgNum.html(Math.max(val3['value1'].pg, val3['value2'].pg)),
  425. // $pdNum.html(Math.max(val3['value1'].pd, val3['value2'].pd));
  426. // $selDate.find('li').removeClass('curr').eq(2).addClass('curr');
  427. // dayNum = 90;
  428. // break;
  429. // case 2:
  430. // $zcNum.html(Math.max(val2['value1'].zc, val2['value2'].zc));
  431. // $pgNum.html(Math.max(val2['value1'].pg, val2['value2'].pg)),
  432. // $pdNum.html(Math.max(val2['value1'].pd, val2['value2'].pd));
  433. // $selDate.find('li').removeClass('curr').eq(1).addClass('curr');
  434. // dayNum = 30;
  435. // break;
  436. // case 3:
  437. // $zcNum.html(Math.max(val1['value1'].zc, val1['value2'].zc));
  438. // $pgNum.html(Math.max(val1['value1'].pg, val1['value2'].pg)),
  439. // $pdNum.html(Math.max(val1['value1'].pd, val1['value2'].pd));
  440. // $selDate.find('li').removeClass('curr').eq(0).addClass('curr');
  441. // dayNum = 7;
  442. // break;
  443. // }
  444. // }
  445. // });
  446. // $swiperWrapper.find('.swiper-slide')
  447. // swiper.slideTo(swiper.slides.length - 1, 0, false); //切换到最后一个slide
  448. // })
  449. // .then(function() {})
  450. // .catch(function(e) {
  451. // console && console.error(e)
  452. // })
  453. // });
  454. //}
  455. //
  456. //function checkLoad(d) {
  457. // if(!isTrue) {
  458. // loadPromise(d, loadData);
  459. // } else {
  460. // loadData();
  461. // }
  462. //}
  463. function bindEvents() {
  464. $viewTabs.on('click', 'li', function(e) {
  465. e.stopPropagation();
  466. var index = $(this).index();
  467. $(this).siblings().removeClass('curr');
  468. $(this).addClass('curr');
  469. if(index === 0) {
  470. $qushiView.show();
  471. $liebiaoView.hide();
  472. $xtEdit.hide();
  473. } else {
  474. $qushiView.hide();
  475. $liebiaoView.show();
  476. var data = null;
  477. if(dayNum == 6) {
  478. data = d1.list;
  479. }
  480. if(dayNum == 30) {
  481. data = d2.list;
  482. }
  483. if(dayNum == 90) {
  484. data = d3.list;
  485. }
  486. if(dayNum == -1) {
  487. data = d4.list;
  488. }
  489. if(!isLoad) {
  490. // isLoad = true;
  491. loadListPromise();
  492. }
  493. $xtEdit.show();
  494. }
  495. });
  496. $selDate.on('click', 'li', function(e) {
  497. var index = $(this).index();
  498. $(this).siblings().removeClass('curr');
  499. $(this).addClass('curr');
  500. console.log(index);
  501. $swiperWrapper.find('.swiper-slide').html('');
  502. swiper.slideTo(swiper.slides.length - 1, 0, false); //切换到最后一个slide
  503. sn = swiper.slides.length - 1;
  504. begindate = norTime;
  505. switch(index) {
  506. case 0:
  507. dayNum = 6;
  508. break;
  509. case 1:
  510. dayNum = 30;
  511. break;
  512. case 2:
  513. dayNum = 90;
  514. break;
  515. case 3:
  516. dayNum = 365 / 2;
  517. break;
  518. }
  519. enddate = getDateFromCurrentDate(begindate, -dayNum);
  520. loadPromise(sn, enddate, begindate);
  521. });
  522. }
  523. //根据sd获取n天前的时间;
  524. function getDateFromCurrentDate(fromDate, dayInterval) {
  525. var curDate = new Date(Date.parse(fromDate.replace(/-/g, "/")));
  526. curDate.setDate(curDate.getDate() + dayInterval);
  527. var year = curDate.getFullYear();
  528. var month = (curDate.getMonth() + 1) < 10 ? "0" + (curDate.getMonth() + 1) : (curDate.getMonth() + 1);
  529. var day = curDate.getDate() < 10 ? "0" + curDate.getDate() : curDate.getDate();
  530. return year + "-" + month + "-" + day;
  531. };