jiuzhenjilu.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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. var type=JSON.parse($(this).attr('data-json')).eventType; //cy
  125. function checkSign(){
  126. d.show();
  127. var userAgent = window.localStorage.getItem(agentName);
  128. if(userAgent){
  129. var data = {};
  130. $.ajax(server + "patient/is_sign", {
  131. data: data,
  132. type: 'POST',
  133. dataType: 'json',
  134. beforeSend: function(request) {
  135. request.setRequestHeader("userAgent", userAgent);
  136. },
  137. error: function(res) {
  138. d.close();
  139. if(res.status == 999 || res.status == 998 || res.status == 997){
  140. loginUrl(res.status);
  141. return;
  142. }
  143. dialog({contentType:'tipsbox', skin:'bk-popup' , content:'校验失败',bottom:true}).show();
  144. },
  145. success: function(res) {
  146. d.close();
  147. if(res.status == 999 || res.status == 998 || res.status == 997){
  148. loginUrl(res.status);
  149. }
  150. else if (res.status == 200) {
  151. // -1 未签约 0 待签约 1 已签约 2待解约
  152. var is_sign = res.data;
  153. if(is_sign > 0){
  154. window.location.href = "event-profile.html?event="+id+"&type="+type
  155. }else{
  156. dialog({
  157. title: '提示',
  158. content: '对不起,签约家庭医生之后才能查看健康档案!',
  159. okValue:'我要签约',
  160. ok: function (){
  161. window.location.href = "../../qygl/html/signing-doctors.html";
  162. },
  163. cancelValue: '了解签约',
  164. cancel: function () {
  165. window.location.href = "../../qygl/html/signing-share2.html";
  166. }
  167. }).showModal();
  168. }
  169. } else {
  170. dialog({contentType:'tipsbox', skin:'bk-popup' , content:res.msg,bottom:true}).show();
  171. }
  172. }
  173. });
  174. }
  175. else{
  176. dialog({contentType:'tipsbox', skin:'bk-popup' , content:'用户信息错误',bottom:true}).show();
  177. }
  178. }
  179. checkSign();
  180. }).on('click','li[data-from="2"]',function() {
  181. var id = $(this).attr('data-id');
  182. window.location.href = "jiuzhenxiangqing.html?event="+id
  183. })
  184. }
  185. function templateHelper() {
  186. template.helper("getYear", getYear);
  187. template.helper("getMD", getMD);
  188. template.helper("getEventTypeName", getEventTypeName);
  189. template.helper("getEventTypeClass", getEventTypeClass);
  190. template.helper("hasGroup", hasGroup);
  191. template.helper("toJson", toJson);
  192. }
  193. templateHelper();
  194. bindEvents();
  195. function queryInit() {
  196. page = 1;
  197. d.show();
  198. $records.empty();
  199. getReqPromise('patient/archives/event',{type:'',page:page,pageSize:10,lastTime: ''},'JSON','GET')
  200. .then(function(res) {
  201. d.close();
  202. if(res.status == 200) {
  203. if(res.data && res.data.length) {
  204. $noResult.hide();
  205. $content.show();
  206. parseToHtml(res);
  207. return true;
  208. } else {
  209. $content.hide();
  210. $noResult.show();
  211. return false;
  212. }
  213. } else {
  214. d.close();
  215. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:res.msg}).show();
  216. }
  217. }).then(function() {
  218. scrollIns.myScroll.refresh();
  219. }).catch(function(e) {
  220. d.close();
  221. console && console.error(e);
  222. });
  223. }
  224. window.onpageshow = function() {
  225. var isLoaded = localStorage.getItem("jiuzhenjilu");
  226. localStorage.removeItem("jiuzhenjilu");
  227. if(isLoaded=="1") {
  228. localStorage.removeItem("jiuzhenjilu");
  229. }
  230. else {
  231. localStorage.setItem("jiuzhenjilu","1");
  232. }
  233. }