jiuzhenjilu.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. var d= dialog({contentType:'load', skin:'bk-popup'}).show();
  2. var pagetype = 28;
  3. var $records = $('#records'),
  4. $wrapper = $('#wrapper'),
  5. $content = $('.div-content'),
  6. $noResult = $('#no_result_wrap');
  7. var scrollIns = null;
  8. var page = 1;
  9. appendFamilyMember($('#memberContainer'),function(){
  10. queryInit();
  11. },function(){
  12. //判断有授权家人,修改样式
  13. if($('#memberContainer').is(':hidden')){
  14. $('#wrapper').css('top','0px');
  15. }else{
  16. $('#wrapper').css('top','90px');
  17. $('.vertical-line').css('top','90px');
  18. $('.no-result-img').css('margin-top','150px')
  19. }
  20. })
  21. function getYear(date) {
  22. if(date) {
  23. return date.substr(0,4);
  24. }
  25. return "";
  26. }
  27. function getMD(date) {
  28. if(date) {
  29. return date.substr(5,5);
  30. }
  31. return "";
  32. }
  33. function getEventTypeClass(type) {
  34. if(type=="1") {
  35. return "menzhen";
  36. } else if(type=="2"){
  37. return "zhuyuan";
  38. } else if(type == "3"){
  39. return "tijian";
  40. }
  41. return "menzhen";
  42. }
  43. function getEventTypeName(type) {
  44. if(type=="1") {
  45. return "门诊";
  46. } else if(type=="2"){
  47. return "住院";
  48. } else if(type == "3"){
  49. return "体检";
  50. }
  51. }
  52. function hasGroup(date) {
  53. var year = getYear(date),
  54. $year = $('.record-year[data-year="'+ year +'"]');
  55. if($year.length) {
  56. return true;
  57. }
  58. return false;
  59. }
  60. function updatePullUpText(scroller,list) {
  61. scroller.off('refresh');
  62. scroller.on('refresh',function() {
  63. var $wrap = $(scroller.wrapper),
  64. $pullupLabel = $wrap.find('.pullUpLabel');
  65. if(!list || !list.length) {
  66. $pullupLabel.text('没有更多');
  67. } else {
  68. $pullupLabel.text('上拉加载更多');
  69. }
  70. });
  71. }
  72. function parseToHtml(eventData) {
  73. var sortedEvents = _.sortBy(eventData.data,function(event) {
  74. return -Date.parse(event.eventDate)
  75. });
  76. var groupEvents = _.groupBy(sortedEvents,function(event) {
  77. return getYear(event.eventDate)
  78. });
  79. var years = _.chain(groupEvents).keys().sortBy(function(year) {
  80. return -year;
  81. }).value();
  82. _.each(years,function(year) {
  83. var yearHtml = '', html = '';
  84. if(!hasGroup(year)) {
  85. yearHtml = '<li class="record-year c-909090" data-year="'+year+'">'+year+'</li>'
  86. }
  87. html = template('li_tmpl', {list: groupEvents[year]});
  88. $records.append(yearHtml+html);
  89. })
  90. }
  91. function toJson(o) {
  92. if(o) {
  93. return JSON.stringify(o);
  94. }
  95. return "{}";
  96. }
  97. scrollIns = new IScrollPullUpDown('wrapper',{
  98. probeType:2,
  99. bounceTime: 250,
  100. bounceEasing: 'quadratic',
  101. mouseWheel:false,
  102. scrollbars:true,
  103. fadeScrollbars:true,
  104. click: true,
  105. interactiveScrollbars:false
  106. },null,function pullUpAction() {
  107. var lastTime = $records.find('li:last').attr('data-event-date');
  108. getReqPromise('patient/archives/event',{type:'',page:page+1,pageSize:10,lastTime: lastTime},'JSON','GET')
  109. .then(function(res) {
  110. if(res.status==200) {
  111. page++;
  112. parseToHtml(res)
  113. updatePullUpText(scrollIns.myScroll,res.data);
  114. setTimeout(function() {
  115. scrollIns.myScroll.refresh();
  116. },100)
  117. }
  118. }).catch(function(e) { console && console.error(e) });
  119. });
  120. checkUserAgent();
  121. function bindEvents() {
  122. $records.on('click','li[data-from="1"]',function() {
  123. var id = $(this).attr('data-id');
  124. function checkSign(){
  125. d.show();
  126. var userAgent = window.localStorage.getItem(agentName);
  127. if(userAgent){
  128. var data = {};
  129. $.ajax(server + "patient/is_sign", {
  130. data: data,
  131. type: 'POST',
  132. dataType: 'json',
  133. beforeSend: function(request) {
  134. request.setRequestHeader("userAgent", userAgent);
  135. },
  136. error: function(res) {
  137. d.close();
  138. if(res.status == 999 || res.status == 998 || res.status == 997){
  139. loginUrl(res.status);
  140. return;
  141. }
  142. dialog({contentType:'tipsbox', skin:'bk-popup' , content:'校验失败',bottom:true}).show();
  143. },
  144. success: function(res) {
  145. d.close();
  146. if(res.status == 999 || res.status == 998 || res.status == 997){
  147. loginUrl(res.status);
  148. }
  149. else if (res.status == 200) {
  150. // -1 未签约 0 待签约 1 已签约 2待解约
  151. var is_sign = res.data;
  152. if(is_sign > 0){
  153. window.location.href = "event-profile.html?event="+id
  154. }else{
  155. dialog({
  156. title: '提示',
  157. content: '对不起,签约家庭医生之后才能查看健康档案!',
  158. okValue:'我要签约',
  159. ok: function (){
  160. window.location.href = "../../qygl/html/signing-doctors.html";
  161. },
  162. cancelValue: '了解签约',
  163. cancel: function () {
  164. window.location.href = "../../qygl/html/signing-share2.html";
  165. }
  166. }).showModal();
  167. }
  168. } else {
  169. dialog({contentType:'tipsbox', skin:'bk-popup' , content:res.msg,bottom:true}).show();
  170. }
  171. }
  172. });
  173. }
  174. else{
  175. dialog({contentType:'tipsbox', skin:'bk-popup' , content:'用户信息错误',bottom:true}).show();
  176. }
  177. }
  178. checkSign();
  179. }).on('click','li[data-from="2"]',function() {
  180. var id = $(this).attr('data-id');
  181. window.location.href = "jiuzhenxiangqing.html?event="+id
  182. })
  183. }
  184. function templateHelper() {
  185. template.helper("getYear", getYear);
  186. template.helper("getMD", getMD);
  187. template.helper("getEventTypeName", getEventTypeName);
  188. template.helper("getEventTypeClass", getEventTypeClass);
  189. template.helper("hasGroup", hasGroup);
  190. template.helper("toJson", toJson);
  191. }
  192. templateHelper();
  193. bindEvents();
  194. function queryInit() {
  195. page = 1;
  196. d.show();
  197. $records.empty();
  198. getReqPromise('patient/archives/event',{type:'',page:page,pageSize:10,lastTime: ''},'JSON','GET')
  199. .then(function(res) {
  200. d.close();
  201. if(res.status == 200) {
  202. if(res.data && res.data.length) {
  203. $noResult.hide();
  204. $content.show();
  205. parseToHtml(res);
  206. return true;
  207. } else {
  208. $content.hide();
  209. $noResult.show();
  210. return false;
  211. }
  212. } else {
  213. d.close();
  214. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:res.msg}).show();
  215. }
  216. }).then(function() {
  217. scrollIns.myScroll.refresh();
  218. }).catch(function(e) {
  219. d.close();
  220. console && console.error(e);
  221. });
  222. }
  223. window.onpageshow = function() {
  224. var isLoaded = localStorage.getItem("jiuzhenjilu");
  225. localStorage.removeItem("jiuzhenjilu");
  226. if(isLoaded=="1") {
  227. localStorage.removeItem("jiuzhenjilu");
  228. }
  229. else {
  230. localStorage.setItem("jiuzhenjilu","1");
  231. }
  232. }