yinshi-view.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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. $popMain = $('.pop-main'),
  42. $xtAdd = $('.xt-add'),
  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 = '',
  53. enddate = '';
  54. var charts = [];
  55. //判断最后的日期
  56. sendPost("patient/health_record/recent", {}, "json", "get", function(){
  57. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'请求失败'}).show();
  58. }, function(res){
  59. if(res.status == 200){
  60. var d0 = decodeURIComponent(Request["dateT"]);
  61. if(res.data.diet){
  62. var d1 = res.data.diet.recordDate
  63. var d2 = Date.parse(new Date(d0))
  64. var d3 = Date.parse(new Date(d1))
  65. if(d2<d3){
  66. //取大
  67. begindate = d1
  68. }else{
  69. begindate = d0
  70. }
  71. }else{
  72. begindate = d0
  73. }
  74. enddate = getBeforeDate( begindate, 1000);
  75. loadData ();
  76. }else{
  77. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'数据查询失败'}).show();
  78. }
  79. })
  80. function changeTabCon () {
  81. var qsv = $qushiView.css('display'),
  82. lbv = $liebiaoView.css('display');
  83. if (qsv === 'block') {
  84. lbv.hide();
  85. }
  86. }
  87. function pushHistory() {
  88. var state = {
  89. title: "饮食",
  90. url: "#"
  91. };
  92. window.history.pushState(state, "饮食", "#");
  93. }
  94. pushHistory();
  95. function bindEvents() {
  96. setTimeout( function () {
  97. window.addEventListener("popstate", function(e) {
  98. location.href = 'health-record.html';
  99. }, false);
  100. }, 300);
  101. $xtEdit.on( 'click', function () {
  102. $(this).hide();
  103. $btns.show();
  104. $xtAdd.hide();
  105. $liebiaoView.find('.l-edit-icon').addClass('active');
  106. });
  107. $cancelBtn.on( 'click',function () {
  108. $liebiaoView.find('.l-edit-icon').removeClass('active');
  109. $xtEdit.show();
  110. $xtAdd.show();
  111. $btns.hide();
  112. });
  113. $okBtn.on( 'click', function () {
  114. $liebiaoView.find('.l-edit-icon').removeClass('active');
  115. $xtEdit.show();
  116. $xtAdd.show();
  117. $btns.hide();
  118. });
  119. $liebiaoView.on( 'click', '.l-item', function () {
  120. var lei = $(this).find('.l-edit-icon'),
  121. id = $(this).attr('data-id'),
  122. image = $(this).attr('data-image'),
  123. val = $(this).attr('data-val'),
  124. time = $(this).attr('data-time');
  125. if (lei.hasClass('active')) {
  126. $popMain.addClass('active');
  127. $popBtns.addClass('active');
  128. $popEditBtn.attr('data-id',id);
  129. $popEditBtn.attr('data-image',image);
  130. $popEditBtn.attr('data-time',time);
  131. $popEditBtn.attr('data-val',val);
  132. $popDelBtn.attr('data-id',id);
  133. }
  134. });
  135. //
  136. $popMain.on( 'click', function () {
  137. $(this).removeClass('active');
  138. $popBtns.removeClass('active');
  139. });
  140. $popCancelBtn.on('click',function () {
  141. $popMain.removeClass('active');
  142. $popBtns.removeClass('active');
  143. });
  144. // 修改
  145. $popEditBtn.on( 'click', function () {
  146. var id = $(this).attr('data-id'),
  147. image = $(this).attr('data-image'),
  148. time = $(this).attr('data-time'),
  149. val = $(this).attr('data-val');
  150. window.location.href = 'add-diet-record.html?id=' + id + '&image=' + image + '&time=' + time + '&val=' + val;
  151. });
  152. // 删除
  153. $popDelBtn.on( 'click', function () {
  154. var id = $(this).attr('data-id');
  155. sendPost("patient/health_record/modifyHealthCare?id=" + id + '&type=1', {}, "json", "post", queryListFailed, function (res) {
  156. d.close();
  157. if (res.status == 200) {
  158. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'删除成功'}).show();
  159. setTimeout(function(){
  160. location.reload();
  161. },2000);
  162. } else {
  163. queryListFailed(res);
  164. }
  165. });
  166. });
  167. }
  168. function querySportList(page,pagesize,begindate,enddate) {
  169. //拼请求内容
  170. d.show();
  171. var params = {};
  172. params.page = page;
  173. params.pagesize = pagesize;
  174. params.start = begindate+" 00:00:00";
  175. params.end = enddate+" 23:59:59";
  176. return new Promise(function(resolve, reject) {
  177. //发送ajax请求
  178. sendPost("patient/health_record/list_diet", params, "json", "post", queryListFailed, function (res) {
  179. d.close();
  180. if (res.status == 200) {
  181. resolve(res)
  182. } else {
  183. queryListFailed(res);
  184. }
  185. });
  186. })
  187. }
  188. bindEvents();
  189. scroller1 = new IScrollPullUpDown('wrapper6',{
  190. probeType:2,
  191. bounceTime: 250,
  192. bounceEasing: 'quadratic',
  193. mouseWheel:false,
  194. scrollbars:true,
  195. fadeScrollbars:true,
  196. click:true,
  197. // preventDefault: false,
  198. interactiveScrollbars:false
  199. },null,pullUpAction);
  200. //上拉加载数据
  201. function pullUpAction(theScrollerTemp) {
  202. $(".pullUp").show();
  203. setTimeout(function () {
  204. loadData();
  205. }, 1000);
  206. }
  207. function loadData () {
  208. page++;
  209. Promise.all([
  210. querySportList( page, pagesize, getBeforeDate( begindate, 1000), begindate)])
  211. .then(function(res) {
  212. $(".pullUp").hide();
  213. var data = res[0];
  214. if (data.list.length > 0) {
  215. $xyList.append(template('xyTmp',{data:data.list}));
  216. scroller1.myScroll.refresh();
  217. } else {
  218. if(!isTrue) {
  219. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'暂无数据'}).show();
  220. $xtEdit.unbind('click');
  221. } else {
  222. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'暂无更多数据'}).show();
  223. }
  224. }
  225. isTrue = true;
  226. })
  227. .catch(function(e) {
  228. console && console.error(e)
  229. });
  230. }
  231. })