yongyao-view.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. var Request = GetRequest();
  2. var scroller1 = null;
  3. var render = function(tmpl, data){
  4. return tmpl.replace(/\{\{(\w+)\}\}/g, function(m, $1){
  5. return data[$1];
  6. });
  7. },
  8. //根据sd获取n天前的时间
  9. getBeforeDate = function ( sd, n) {
  10. var n = n;
  11. var d = new Date(sd.replace(/\-/g, "/"));
  12. var year = d.getFullYear();
  13. var mon=d.getMonth()+1;
  14. var day=d.getDate();
  15. if(day <= n){
  16. if(mon>1) {
  17. mon=mon-1;
  18. }
  19. else {
  20. year = year-1;
  21. mon = 12;
  22. }
  23. }
  24. d.setDate(d.getDate()-n);
  25. year = d.getFullYear();
  26. mon=d.getMonth()+1;
  27. day=d.getDate();
  28. s = year + "-" + (mon < 10 ? ('0' + mon) : mon) + "-" + (day < 10 ? ('0' + day) : day);
  29. return s;
  30. },
  31. //半年前
  32. halfYear = 365 / 2 * 24 * 3600 * 1000;
  33. $(function () {
  34. var $duringList = $('#duringList'),
  35. $qushiView = $('#qushiView'),
  36. $liebiaoView = $('#liebiaoView'),
  37. $xtEdit = $('.xt-edit'),
  38. $btns = $('.btns'),
  39. $cancelBtn = $('.cancel-btn'),
  40. $okBtn = $('.ok-btn'),
  41. $xtAdd = $('.xt-add'),
  42. $popMain = $('.pop-main'),
  43. $popBtns = $('.pop-btns'),
  44. $popEditBtn = $('.pop-edit-btn'),
  45. $popDelBtn = $('.pop-del-btn'),
  46. $popCancelBtn = $('.pop-cancel-btn'),
  47. isTrue = false,
  48. page = 0,
  49. pagesize = 10,
  50. $xyList = $('.xy-list-con'),
  51. $xyTmp = $('#xyTmp');
  52. var begindate = decodeURIComponent(Request["dateT"]),
  53. enddate = getBeforeDate( begindate, 1000);
  54. var charts = [];
  55. var begindate = '',
  56. enddate = '';
  57. var charts = [];
  58. //判断最后的日期
  59. sendPost("patient/health_record/recent", {}, "json", "get", function(){
  60. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'请求失败'}).show();
  61. }, function(res){
  62. if(res.status == 200){
  63. var d0 = decodeURIComponent(Request["dateT"]);
  64. if(res.data.medication){
  65. var d1 = res.data.medication.recordDate
  66. var d2 = Date.parse(new Date(d0))
  67. var d3 = Date.parse(new Date(d1))
  68. if(d2<d3){
  69. //取大
  70. begindate = d1
  71. }else{
  72. begindate = d0
  73. }
  74. }else{
  75. begindate = d0
  76. }
  77. enddate = getBeforeDate( begindate, 1000);
  78. loadData ();
  79. }else{
  80. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'数据查询失败'}).show();
  81. }
  82. })
  83. function changeTabCon () {
  84. var qsv = $qushiView.css('display'),
  85. lbv = $liebiaoView.css('display');
  86. if (qsv === 'block') {
  87. lbv.hide();
  88. }
  89. }
  90. function pushHistory() {
  91. var state = {
  92. title: "用药",
  93. url: "#"
  94. };
  95. window.history.pushState(state, "用药", "#");
  96. }
  97. pushHistory();
  98. function bindEvents() {
  99. setTimeout( function () {
  100. window.addEventListener("popstate", function(e) {
  101. location.href = 'health-record.html';
  102. }, false);
  103. }, 300);
  104. $xtEdit.on( 'click', function () {
  105. $(this).hide();
  106. $btns.show();
  107. $xtAdd.hide();
  108. $liebiaoView.find('.l-edit-icon').addClass('active');
  109. });
  110. $cancelBtn.on( 'click',function () {
  111. $liebiaoView.find('.l-edit-icon').removeClass('active');
  112. $xtEdit.show();
  113. $xtAdd.show();
  114. $btns.hide();
  115. });
  116. $okBtn.on( 'click', function () {
  117. $liebiaoView.find('.l-edit-icon').removeClass('active');
  118. $xtEdit.show();
  119. $xtAdd.show();
  120. $btns.hide();
  121. });
  122. $liebiaoView.on( 'click', '.l-item', function () {
  123. var lei = $(this).find('.l-edit-icon'),
  124. id = $(this).attr('data-id'),
  125. date = $(this).attr('data-date'),
  126. val = $(this).attr('data-val'),
  127. code = $(this).attr('data-code');
  128. if (lei.hasClass('active')) {
  129. $popMain.addClass('active');
  130. $popBtns.addClass('active');
  131. $popEditBtn.attr('data-id',id);
  132. $popEditBtn.attr('data-date',date);
  133. $popEditBtn.attr('data-val',val);
  134. $popEditBtn.attr('data-code',code);
  135. $popDelBtn.attr('data-id',id);
  136. }
  137. });
  138. $popCancelBtn.on('click',function () {
  139. $popMain.removeClass('active');
  140. $popBtns.removeClass('active');
  141. });
  142. // 修改
  143. $popEditBtn.on( 'click', function () {
  144. var id = $(this).attr('data-id'),
  145. date = $(this).attr('data-date'),
  146. val = $(this).attr('data-val'),
  147. code = $(this).attr('data-code');
  148. window.location.href = 'add-drug-record.html?id=' + id + '&date=' + date + '&val=' + val + '&code=' + code;
  149. });
  150. // 删除
  151. $popDelBtn.on( 'click', function () {
  152. var id = $(this).attr('data-id');
  153. sendPost("/patient/health_record/modifyHealthCare", {
  154. id:id,
  155. type: 3
  156. }, "json", "post", queryListFailed, function (res) {
  157. d.close();
  158. if (res.status == 200) {
  159. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'删除成功'}).show();
  160. setTimeout(function(){
  161. location.reload();
  162. },2000);
  163. } else {
  164. queryListFailed(res);
  165. }
  166. });
  167. });
  168. //
  169. $popMain.on( 'click', function () {
  170. $(this).removeClass('active');
  171. $popBtns.removeClass('active');
  172. });
  173. }
  174. function querySportList(page,pagesize,begindate,enddate) {
  175. //拼请求内容
  176. d.show();
  177. var params = {};
  178. params.page = page;
  179. params.pagesize = pagesize;
  180. params.start = begindate+" 00:00:00";
  181. params.end = enddate+" 23:59:59";
  182. return new Promise(function(resolve, reject) {
  183. //发送ajax请求
  184. sendPost("patient/health_record/list_medication", params, "json", "post", queryListFailed, function (res) {
  185. d.close();
  186. if (res.status == 200) {
  187. resolve(res)
  188. } else {
  189. queryListFailed(res);
  190. }
  191. });
  192. })
  193. }
  194. bindEvents();
  195. scroller1 = new IScrollPullUpDown('wrapper6',{
  196. probeType:2,
  197. bounceTime: 250,
  198. bounceEasing: 'quadratic',
  199. mouseWheel:false,
  200. scrollbars:true,
  201. fadeScrollbars:true,
  202. click:true,
  203. // preventDefault: false,
  204. interactiveScrollbars:false
  205. },null,pullUpAction);
  206. //上拉加载数据
  207. function pullUpAction(theScrollerTemp) {
  208. $(".pullUp").show();
  209. setTimeout(function () {
  210. loadData();
  211. }, 1000);
  212. }
  213. function loadData () {
  214. page++;
  215. Promise.all([
  216. querySportList( page, pagesize, getBeforeDate( begindate, 1000), begindate)])
  217. .then(function(res) {
  218. $(".pullUp").hide();
  219. var data = res[0];
  220. if (data.list.length > 0) {
  221. $xyList.append(template('xyTmp',{data:data.list}));
  222. scroller1.myScroll.refresh();
  223. } else {
  224. if(!isTrue) {
  225. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'暂无数据'}).show();
  226. $xtEdit.unbind('click');
  227. } else {
  228. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'暂无更多数据'}).show();
  229. }
  230. }
  231. isTrue = true;
  232. })
  233. .catch(function(e) {
  234. console && console.error(e)
  235. });
  236. }
  237. })