xueya-view.js 13 KB

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