yundong-view.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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. $xtAdd = $('.xt-add'),
  39. $btns = $('.btns'),
  40. $cancelBtn = $('.cancel-btn'),
  41. $okBtn = $('.ok-btn'),
  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 = '',
  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.sprot){
  62. var d1 = res.data.sprot.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. //编辑
  102. $xtEdit.on( 'click', function () {
  103. $(this).hide();
  104. $xtAdd.hide();
  105. $btns.show();
  106. $liebiaoView.find('.l-edit-icon').addClass('active');
  107. });
  108. //取消
  109. $cancelBtn.on( 'click',function () {
  110. $liebiaoView.find('.l-edit-icon').removeClass('active');
  111. $xtEdit.show();
  112. $xtAdd.show();
  113. $btns.hide();
  114. });
  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. //点击列表-行
  123. $liebiaoView.on( 'click', '.l-item', function () {
  124. var lei = $(this).find('.l-edit-icon'),
  125. id = $(this).attr('data-id'),
  126. type = $(this).attr('data-type'),
  127. date = $(this).attr('data-date'),
  128. time = $(this).attr('data-time'),
  129. sports = $(this).attr('data-sports');
  130. if (lei.hasClass('active')) {
  131. $popMain.addClass('active');
  132. $popBtns.addClass('active');
  133. $popEditBtn.attr('data-id',id);
  134. $popEditBtn.attr('data-type',type);
  135. $popEditBtn.attr('data-time',time);
  136. $popEditBtn.attr('data-sports',sports);
  137. $popEditBtn.attr('data-date',date);
  138. $popDelBtn.attr('data-id',id);
  139. }
  140. });
  141. //取消
  142. $popCancelBtn.on('click',function () {
  143. $popMain.removeClass('active');
  144. $popBtns.removeClass('active');
  145. });
  146. //
  147. $popMain.on( 'click', function () {
  148. $(this).removeClass('active');
  149. $popBtns.removeClass('active');
  150. });
  151. // 修改
  152. $popEditBtn.on( 'click', function () {
  153. var id = $(this).attr('data-id'),
  154. type = $(this).attr('data-type'),
  155. time = $(this).attr('data-time'),
  156. sports = $(this).attr('data-sports'),
  157. date = $(this).attr('data-date');
  158. window.location.href = 'add-sport-record.html?id=' + id + '&type=' + type + '&time=' + time + '&sports=' + sports + '&date=' + date;
  159. });
  160. // 删除
  161. $popDelBtn.on( 'click', function () {
  162. var id = $(this).attr('data-id');
  163. sendPost("patient/health_record/modifyHealthCare?id=" + id + '&type=2', {}, "json", "post", queryListFailed, function (res) {
  164. d.close();
  165. if (res.status == 200) {
  166. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'删除成功'}).show();
  167. setTimeout(function(){
  168. location.reload();
  169. },2000);
  170. } else {
  171. queryListFailed(res);
  172. }
  173. });
  174. });
  175. }
  176. //加载运动记录
  177. function querySportList(page,pagesize,begindate,enddate) {
  178. //拼请求内容
  179. d.show();
  180. var params = {};
  181. params.page = page;
  182. params.pagesize = pagesize;
  183. params.start = begindate+" 00:00:00";
  184. params.end = enddate+" 23:59:59";
  185. return new Promise(function(resolve, reject) {
  186. //发送ajax请求
  187. sendPost("patient/health_record/list_sports", params, "json", "post", queryListFailed, function (res) {
  188. d.close();
  189. if (res.status == 200) {
  190. resolve(res)
  191. } else {
  192. queryListFailed(res);
  193. }
  194. });
  195. })
  196. }
  197. scroller1 = new IScrollPullUpDown('wrapper6',{
  198. probeType:2,
  199. bounceTime: 250,
  200. bounceEasing: 'quadratic',
  201. mouseWheel:false,
  202. scrollbars:true,
  203. fadeScrollbars:true,
  204. click:true,
  205. // preventDefault: false,
  206. interactiveScrollbars:false
  207. },null,pullUpAction);
  208. //上拉加载数据
  209. function pullUpAction(theScrollerTemp) {
  210. $(".pullUp").show();
  211. setTimeout(function () {
  212. loadData();
  213. }, 1000);
  214. }
  215. function loadData () {
  216. page++;
  217. Promise.all([
  218. querySportList( page, pagesize, getBeforeDate( begindate, 1000), begindate)])
  219. .then(function(res) {
  220. $(".pullUp").hide();
  221. var data = res[0];
  222. if (data.list.length > 0) {
  223. $xyList.append(template('xyTmp',{data:data.list}));
  224. scroller1.myScroll.refresh();
  225. } else {
  226. if(!isTrue) {
  227. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'暂无数据'}).show();
  228. $xtEdit.unbind('click');
  229. } else {
  230. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'暂无更多数据'}).show();
  231. }
  232. }
  233. isTrue = true;
  234. })
  235. .catch(function(e) {
  236. console && console.error(e)
  237. });
  238. }
  239. bindEvents();
  240. });