yaowei-view.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  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. $xtAdd = $('.xt-add'),
  23. $cancelBtn = $('.cancel-btn'),
  24. $okBtn = $('.ok-btn'),
  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. isTrue = false,
  33. page = 0,
  34. pagesize = 10,
  35. d1 = [],
  36. d2 = [],
  37. d3 = [],
  38. d4 = [],
  39. dayNum = 6,
  40. $xyList = $('.xy-list-con'),
  41. $xyTmp = $('#xyTmp'),
  42. isLoad = false;
  43. var norTime = '',
  44. sn = 0;
  45. mui.plusReady(function() {
  46. self = plus.webview.currentWebview();
  47. patientCode = self.code;
  48. begindate = self.dateT;
  49. norTime = self.dateT;
  50. type = self.type;
  51. enddate = getDateFromCurrentDate(begindate, -dayNum);
  52. bindEvents();
  53. scroller1 = new IScrollPullUpDown('wrapper6', {
  54. probeType: 2,
  55. bounceTime: 250,
  56. bounceEasing: 'quadratic',
  57. mouseWheel: false,
  58. scrollbars: true,
  59. fadeScrollbars: true,
  60. interactiveScrollbars: false,
  61. click: true,
  62. }, null, pullUpAction);
  63. init();
  64. });
  65. function changeTabCon() {
  66. var qsv = $qushiView.css('display'),
  67. lbv = $liebiaoView.css('display');
  68. if(qsv === 'block') {
  69. lbv.hide();
  70. }
  71. }
  72. function bindEvents() {
  73. $viewTabs.on('click', 'li', function(e) {
  74. e.stopPropagation();
  75. var index = $(this).index();
  76. $(this).siblings().removeClass('curr');
  77. $(this).addClass('curr');
  78. if(index === 0) {
  79. $qushiView.show();
  80. $liebiaoView.hide();
  81. $xtEdit.hide();
  82. } else {
  83. $qushiView.hide();
  84. $liebiaoView.show();
  85. $xtEdit.show();
  86. var data = null;
  87. if(dayNum == 7) {
  88. data = d1.list;
  89. }
  90. if(dayNum == 30) {
  91. data = d2.list;
  92. }
  93. if(dayNum == 90) {
  94. data = d3.list;
  95. }
  96. if(dayNum == -1) {
  97. data = d4.list;
  98. }
  99. if(!isLoad) {
  100. // isLoad = true;
  101. loadListPromise();
  102. }
  103. // $xyList.html(template('xyTmp',{data:data}));
  104. }
  105. });
  106. $selDate.on('click', 'li', function(e) {
  107. var index = $(this).index();
  108. $(this).siblings().removeClass('curr');
  109. $(this).addClass('curr');
  110. console.log(index);
  111. $swiperWrapper.find('.swiper-slide').html('');
  112. swiper.slideTo(swiper.slides.length - 1, 0, false); //切换到最后一个slide
  113. sn = swiper.slides.length - 1;
  114. begindate = norTime;
  115. switch(index) {
  116. case 0:
  117. dayNum = 6;
  118. break;
  119. case 1:
  120. dayNum = 30;
  121. break;
  122. case 2:
  123. dayNum = 90;
  124. break;
  125. case 3:
  126. dayNum = 365 / 2;
  127. break;
  128. }
  129. enddate = getDateFromCurrentDate(begindate, -dayNum);
  130. loadPromise(sn, enddate, begindate);
  131. });
  132. }
  133. function queryListByTypeP(type, begindate, enddate, page, pagesize, code) {
  134. plus.nativeUI.showWaiting();
  135. //拼请求内容
  136. var params = {};
  137. params.type = type;
  138. params.page = page;
  139. params.pagesize = pagesize;
  140. params.begin = begindate + " 00:00:00";
  141. params.end = enddate + " 23:59:59";
  142. params.patient = code;
  143. return new Promise(function(resolve, reject) {
  144. sendPost("doctor/health_index/list", params, function(res) {
  145. resolve(res)
  146. console.log(res);
  147. }, function(res) {
  148. if(res.status == 200) {
  149. plus.nativeUI.closeWaiting();
  150. resolve(res)
  151. } else {
  152. queryListFailed(res);
  153. }
  154. });
  155. })
  156. }
  157. function getxAxisData(data) {
  158. var a = [],
  159. b = [];
  160. b = _.chain(data).pluck('date').map(function(d) {
  161. return d.substr(5, 5)
  162. }).value();
  163. for(var i = b.length - 1; i >= 0; i--) {
  164. a.push(b[i]);
  165. }
  166. return a;
  167. }
  168. function getSeriesData(data) {
  169. var a = [],
  170. b = [];
  171. b = _.chain(data).pluck('value1').map(function(v) {
  172. return v;
  173. }).value();
  174. for(var i = b.length - 1; i >= 0; i--) {
  175. a.push(b[i]);
  176. }
  177. return a;
  178. }
  179. //上拉加载数据
  180. function pullUpAction(theScrollerTemp) {
  181. $(".pullUp").show();
  182. setTimeout(function() {
  183. loadListPromise();
  184. }, 1000);
  185. }
  186. function loadListPromise() {
  187. page++;
  188. Promise.all([
  189. queryListByTypeP(4, getDateFromCurrentDate(norTime, -2000), norTime, page, pagesize, patientCode)
  190. ])
  191. .then(function(res) {
  192. $(".pullUp").hide();
  193. var data = res[0];
  194. if (data.list.length > 0) {
  195. console.log(page);
  196. $xyList.append(template('xyTmp', {
  197. data: data.list
  198. }));
  199. scroller1.refresh();
  200. } else {
  201. if(!isLoad) {
  202. mui.toast("暂无数据!");
  203. } else {
  204. mui.toast("暂无更多数据!");
  205. }
  206. }
  207. isLoad = true;
  208. })
  209. .catch(function(e) {
  210. console && console.error(e)
  211. });
  212. }
  213. //初始化swiper
  214. function init() {
  215. Promise.all([(function() {
  216. $swiperWrapper
  217. .append($('<li id="chart0" class="swiper-slide"> </li>'))
  218. .append($('<li id="chart1" class="swiper-slide"> </li>'))
  219. .append($('<li id="chart2" class="swiper-slide"> </li>'))
  220. .append($('<li id="chart3" class="swiper-slide"> </li>'));
  221. })()])
  222. .then(function(echarts) {
  223. swiper = new Swiper('.swiper-container', {
  224. paginationClickable: false,
  225. onSlideChangeStart: function(swiper) {
  226. //切换
  227. var ind = swiper.activeIndex;
  228. if(ind < sn) {
  229. begindate = enddate;
  230. enddate = getDateFromCurrentDate(begindate, -dayNum);
  231. } else {
  232. enddate = begindate;
  233. begindate = getDateFromCurrentDate(begindate, dayNum);
  234. }
  235. sn = ind;
  236. loadPromise(sn, enddate, begindate);
  237. }
  238. });
  239. })
  240. .then(function() {
  241. $swiperWrapper.find('.swiper-slide');
  242. swiper.slideTo(swiper.slides.length - 1, 0, false); //切换到最后一个slide
  243. sn = swiper.slides.length - 1;
  244. loadPromise(sn, enddate, begindate);
  245. })
  246. .catch(function(e) {
  247. console && console.error(e)
  248. })
  249. }
  250. function loadPromise(n, enddate, begindate) {
  251. plus.nativeUI.showWaiting();
  252. Promise.all([
  253. queryChatByTypePromise(4, enddate, begindate, 0, patientCode)
  254. ])
  255. .then(function(res) {
  256. d1 = res[0];
  257. loadData(n);
  258. })
  259. .catch(function(e) {
  260. console && console.error(e)
  261. });
  262. }
  263. //初始化echart
  264. function loadData(n) {
  265. new Promise(function(resolve, reject) {
  266. var yAxisName = '单位(cm)';
  267. var el = document.getElementById('chart' + n);
  268. Promise.all([
  269. createChartPromise(el, 4, yAxisName, getxAxisData(d1.list), getSeriesData(d1.list))
  270. ])
  271. .then(function(echarts) {
  272. plus.nativeUI.closeWaiting();
  273. charts.push(echarts[0]);
  274. $(el).append('<div class="c-time">< ' + enddate + ' 至 ' + begindate + ' ></div>');
  275. })
  276. .then(function() {
  277. })
  278. .catch(function(e) {
  279. console && console.error(e)
  280. })
  281. });
  282. }
  283. //根据sd获取n天前的时间;
  284. function getDateFromCurrentDate(fromDate, dayInterval) {
  285. var curDate = new Date(Date.parse(fromDate.replace(/-/g, "/")));
  286. curDate.setDate(curDate.getDate() + dayInterval);
  287. var year = curDate.getFullYear();
  288. var month = (curDate.getMonth() + 1) < 10 ? "0" + (curDate.getMonth() + 1) : (curDate.getMonth() + 1);
  289. var day = curDate.getDate() < 10 ? "0" + curDate.getDate() : curDate.getDate();
  290. return year + "-" + month + "-" + day;
  291. };
  292. //function loadPromise(cb) {
  293. // Promise.all([
  294. // queryChatByTypePromise(4, getBeforeDate(begindate, 7), begindate, 0, patientCode),
  295. // queryChatByTypePromise(4, getBeforeDate(begindate, 30), begindate, 0, patientCode),
  296. // queryChatByTypePromise(4, getBeforeDate(begindate, 90), begindate, 0, patientCode),
  297. // queryChatByTypePromise(4, getBeforeDate(begindate, 365 / 2), begindate, 0, patientCode)
  298. // ])
  299. // .then(function(res) {
  300. // d1 = res[0];
  301. // d2 = res[1];
  302. // d3 = res[2];
  303. // d4 = res[3];
  304. //
  305. // plus.nativeUI.closeWaiting();
  306. // cb && cb.call(this);
  307. // })
  308. // .catch(function(e) {
  309. // console && console.error(e)
  310. // });
  311. //}
  312. //
  313. //function loadData() {
  314. // new Promise(function(resolve, reject) {
  315. // var yAxisName = '单位(cm)';
  316. // $swiperWrapper
  317. // .append('<li id="chart3" class="swiper-slide">')
  318. // .append('<li id="chart2" class="swiper-slide">')
  319. // .append('<li id="chart1" class="swiper-slide">')
  320. // .append('<li id="chart0" class="swiper-slide">');
  321. //
  322. // var el1 = document.getElementById('chart0'),
  323. // el2 = document.getElementById('chart1'),
  324. // el3 = document.getElementById('chart2'),
  325. // el4 = document.getElementById('chart3')
  326. // Promise.all([
  327. // createChartPromise(el1, 4, yAxisName, getxAxisData(d1.list), getSeriesData(d1.list)),
  328. // createChartPromise(el2, 4, yAxisName, getxAxisData(d2.list), getSeriesData(d2.list)),
  329. // createChartPromise(el3, 4, yAxisName, getxAxisData(d3.list), getSeriesData(d3.list)),
  330. // createChartPromise(el4, 4, yAxisName, getxAxisData(d4.list), getSeriesData(d4.list))
  331. // ])
  332. // .then(function(echarts) {
  333. // charts.push(echarts[0]);
  334. // charts.push(echarts[1]);
  335. // charts.push(echarts[2]);
  336. // $(el1).append('<div class="c-time">< ' + getBeforeDate(begindate, 7) + ' 至 ' + begindate + ' ></div>');
  337. // $(el2).append('<div class="c-time">< ' + getBeforeDate(begindate, 30) + ' 至 ' + begindate + ' ></div>');
  338. // $(el3).append('<div class="c-time">< ' + getBeforeDate(begindate, 90) + ' 至 ' + begindate + ' ></div>');
  339. // $(el4).append('<div class="c-time">< ' + getBeforeDate(begindate, 365 / 2) + ' 至 ' + begindate + ' ></div>');
  340. //
  341. // })
  342. // .then(function(res) {
  343. // swiper = new Swiper('.swiper-container', {
  344. // paginationClickable: false,
  345. // normalizeSlideIndex: false,
  346. // onSlideChangeStart: function(swiper) {
  347. // var ind = swiper.activeIndex;
  348. // console.log(ind);
  349. // switch(ind) {
  350. // case 0:
  351. // $selDate.find('li').removeClass('curr').eq(3).addClass('curr');
  352. // dayNum = -1;
  353. // break;
  354. // case 1:
  355. // $selDate.find('li').removeClass('curr').eq(2).addClass('curr');
  356. // dayNum = 90;
  357. // break;
  358. // case 2:
  359. // $selDate.find('li').removeClass('curr').eq(1).addClass('curr');
  360. // dayNum = 30;
  361. // break;
  362. // case 3:
  363. // $selDate.find('li').removeClass('curr').eq(0).addClass('curr');
  364. // dayNum = 7;
  365. // break;
  366. // }
  367. // }
  368. // });
  369. // $swiperWrapper.find('.swiper-slide')
  370. // swiper.slideTo(swiper.slides.length - 1, 0, false); //切换到最后一个slide
  371. // })
  372. // .then(function() {
  373. // bindEvents()
  374. // })
  375. // .catch(function(e) {
  376. // console && console.error(e)
  377. // })
  378. // });
  379. //}
  380. //
  381. //function checkLoad() {
  382. // if(!isTrue) {
  383. // loadPromise(loadData);
  384. // } else {
  385. // loadData();
  386. // }
  387. //}