edu_history.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. var page = 10,
  2. pagesize = 10,
  3. reqInfo = [
  4. {url:"doctor/jkEdu/article/PC/fetchPatientArticlePushedList",page: 1,template: 'edu_tmpl'},
  5. {url:"doctor/health/guidance/list_by_team",page: 1,template: 'zhidao_tmpl'}
  6. ],
  7. patiCode = "",
  8. teamCode,
  9. activeIndex = 0;
  10. var eduObj, zhidaoObj;
  11. var noResultWrap = '<div id="no_result_wrap" style="width: 320px; height: 184px; margin: 60px auto 0px;">'+
  12. '<img src="../../../images/shujuweikong_img.png" /><div style="color:#666;font-size:16px;text-align:center;">暂无数据</div></div>';
  13. mui.init();
  14. (function($) {
  15. //阻尼系数
  16. var deceleration = mui.os.ios?0.003:0.0009;
  17. $('.mui-scroll-wrapper').scroll({
  18. bounce: false,
  19. indicators: true, //是否显示滚动条
  20. deceleration:deceleration
  21. });
  22. $.plusReady(function() {
  23. //循环初始化所有下拉刷新,上拉加载。
  24. $.each(document.querySelectorAll('.mui-slider-group .mui-scroll-wrapper'), function(index, pullRefreshEl) {
  25. $(pullRefreshEl).pullRefresh({
  26. down: {
  27. callback: function() {
  28. var self = this;
  29. setTimeout(function() {
  30. getList(pullRefreshEl, index, true, true);
  31. self.endPulldownToRefresh();
  32. }, 1000);
  33. }
  34. },
  35. up: {
  36. callback: function() {
  37. var self = this;
  38. setTimeout(function() {
  39. getList(pullRefreshEl, index, false);
  40. self.endPullupToRefresh();
  41. }, 1000);
  42. }
  43. }
  44. });
  45. });
  46. var self = plus.webview.currentWebview();
  47. patiCode = self.patientCode;
  48. initTemplateHelper();
  49. getTeamInfo();
  50. bindEvents();
  51. });
  52. })(mui);
  53. function getTeamInfo(){
  54. plus.nativeUI.showWaiting();
  55. // TODO 团队选择
  56. return getReqPromise("doctor/family_contract/patient_doctor_teams",{
  57. patient: patiCode
  58. }).then(function(res) {
  59. if(res.status == 200) {
  60. var data = res.data,teams = [];
  61. // 是否有签约关系 1:有 0:无,此时jtTeam与ssTeam都没有
  62. if(data.hasSign=="1") {
  63. data.ssTeam && (function() {
  64. var team = data.ssTeam.team;
  65. team.hasSign = data.ssTeam.hasSign; // 医生与患者是否有签约关系
  66. team.isLeader = data.ssTeam.isLeader; // 是否是团队长
  67. teams.push(team)
  68. })();
  69. data.jtTeam && (function() {
  70. var team = data.jtTeam.team;
  71. team.hasSign = data.jtTeam.hasSign; // 医生与患者是否有签约关系
  72. team.isLeader = data.jtTeam.isLeader; // 是否是团队长
  73. teams.push(team)
  74. })();
  75. }
  76. }
  77. $('.lin-sel-group').html(template('teams_tmpl', {data:teams}));
  78. //初始默认选中第一个团队信息
  79. var $select = $(".lin-sel-group li").eq(0);
  80. var code = parseInt($select.attr("data-code"));
  81. $(".lin-sel-group li").removeClass("checked");
  82. $select.addClass("checked");
  83. teamCode = code;
  84. $("#Dtitle").html($select.find("label").html()).attr("data-index",code);
  85. }).then(function(){
  86. // plus.nativeUI.closeWaiting();
  87. getList(document.getElementsByClassName("mui-scroll-wrapper")[activeIndex], activeIndex, true);
  88. });
  89. }
  90. function getList(el, index, isInit, refresh){
  91. page = isInit? 1: page;
  92. var url = reqInfo[index].url,
  93. params = {
  94. patientCode: patiCode,
  95. patient: patiCode,
  96. teamCode: teamCode || "",
  97. page: page,
  98. pagesize: pagesize,
  99. };
  100. if(!refresh && ((index == 0 && eduObj) || (index == 1 && zhidaoObj))){
  101. return false;
  102. }
  103. plus.nativeUI.showWaiting();
  104. sendPost(url, params, null, function(res){
  105. if(res.status == 200){
  106. var list = res.list || res.data;
  107. if(index == 0){
  108. eduObj = list;
  109. }else{
  110. zhidaoObj = list;
  111. }
  112. if(list.length > 0){
  113. page++;
  114. var html = template(reqInfo[index].template, {list: list});
  115. if(isInit){
  116. $(el).find(".mui-scroll").empty().append(html);
  117. }else{
  118. $(el).find(".mui-scroll").append(html);
  119. }
  120. if(list.length < pagesize){
  121. mui(mui('.mui-scroll-wrapper')[activeIndex]).pullRefresh().endPullupToRefresh(true);
  122. }
  123. }else{
  124. //无数据
  125. if(isInit){
  126. $(el).find(".mui-scroll").append(noResultWrap);
  127. }
  128. }
  129. }else{
  130. mui.toast(res.msg);
  131. }
  132. plus.nativeUI.closeWaiting();
  133. }, 'POST', '', true);
  134. }
  135. function bindEvents(){
  136. //切换菜单
  137. $('.mui-control-item a').on('tap',function(){
  138. var index = this.getAttribute('data-index'),
  139. el = document.getElementsByClassName("mui-scroll-wrapper")[index];
  140. page = 1;
  141. activeIndex = index;
  142. getList(el, index, true);
  143. var slider = mui('.mui-slider').slider();
  144. slider.gotoItem(index);
  145. });
  146. document.getElementById('slider').addEventListener('slide', function(event) {
  147. var idx = event.detail.slideNumber,
  148. el = document.getElementsByClassName("mui-scroll-wrapper")[idx];
  149. getList(el, idx, true);
  150. });
  151. $('body').on("tap", ".zd_detail", function(){
  152. chooseItem(this,"zhidao")
  153. }).on("tap", ".edu_detail", function(){
  154. chooseItem(this, "edu");
  155. });
  156. $(".demo-comtop").on("click","h1",function(){
  157. $(".lin-mask").show();
  158. $(".lin-sel-group").show();
  159. });
  160. $(".lin-mask").on("click",function(){
  161. $(".lin-mask").hide();
  162. $(".lin-sel-group").hide();
  163. });
  164. $(".lin-sel-group").on("click","li",function(){
  165. var index = parseInt($(this).attr("data-code"));
  166. $(".lin-sel-group li").removeClass("checked");
  167. $(this).addClass("checked");
  168. $(".lin-mask").trigger("click");
  169. $("#Dtitle").html($(this).find("label").html()).attr("data-index",index);
  170. teamCode = $(this).attr("data-code");
  171. //重新加载数据
  172. getList(document.getElementsByClassName("mui-scroll-wrapper")[activeIndex], activeIndex, true);
  173. });
  174. }
  175. function chooseItem(ele, type){
  176. var info = ele.getAttribute("data-info"),
  177. self = plus.webview.currentWebview();
  178. var questionaires = plus.webview.getWebviewById("questionaires");
  179. mui.fire(questionaires, "fillEdu", {info: info, type: type});
  180. questionaires.show();
  181. mui.later(function(){
  182. self.close('none');
  183. }, 300);
  184. }
  185. function initTemplateHelper(){
  186. template.helper('toInfo', function(v){
  187. return JSON.stringify(v);
  188. });
  189. template.helper("setSex", function(s) {
  190. if(s == 1) {
  191. return "男"
  192. } else if(s == 2) {
  193. return "女"
  194. }
  195. });
  196. template.helper("setPhoto", function(p) {
  197. if(!p || p.length == 0) {
  198. return "../../../images/p-default.png";
  199. } else {
  200. return getImgUrl(p);
  201. }
  202. });
  203. template.helper("setTime", function(p) {
  204. // 为了防止类似“2016-12-21 14:08:10.0”在IOS上无法识别问题
  205. if(p){
  206. p = p.split('.')[0];
  207. return new Date(Date.parse(p.replace(/-/g, "/"))).format("yyyy-MM-dd hh:mm:ss")
  208. }else{
  209. return "";
  210. }
  211. });
  212. }