tuandui.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. // TODO 临时构造plus对象,使得能够在浏览器中进行调试
  2. // var plus = null;
  3. // 基本信息(包括userAgent、上个页面传递的数据)
  4. var baseInfo = null,
  5. // 基础环境信息(包括当前webview)
  6. baseEnv = null,
  7. pages = {}, //记录个分组内数据页数
  8. docInfo;
  9. var $searchbarInput = $('.searchbar .search-input'),
  10. // 搜索无结果时显示
  11. $noResultWrap = $('#no_result_wrap'),
  12. // 页面顶部分类标签列表(四个列表项)
  13. $groupLabelList = $('#group_label_list'),
  14. patientInfo = null;
  15. // 获取基本信息(包括userAgent、上个页面传递的数据)
  16. var getBaseInfoPromise = function() {
  17. // 登录的相关信息
  18. var userAgent = plus && JSON.parse(plus.storage.getItem("userAgent"))
  19. return {
  20. userAgent: userAgent
  21. }
  22. },
  23. // 获取基础环境信息
  24. getBaseEnvPromise = function () {
  25. var env = {
  26. webview: plus&&plus.webview.currentWebview()
  27. };
  28. return Promise.resolve().then(function(res) {
  29. return env;
  30. });
  31. },
  32. //获取分组信息
  33. getGroupData = function(){
  34. docInfo = JSON.parse(plus.storage.getItem("docInfo"));
  35. var url = "doctor/dept_group_list",
  36. params = {};
  37. plus.nativeUI.showWaiting();
  38. sendGet(url, params, null,function(res){
  39. if(res.status == 200){
  40. var html = template("pati_group_tmpl", {list: res.data});
  41. $("#groupList").empty().append(html);
  42. plus.nativeUI.closeWaiting();
  43. }else{
  44. plus.nativeUI.closeWaiting();
  45. mui.toast(res.msg);
  46. }
  47. });
  48. },
  49. // 滚动条分页实例初始化
  50. initScroller = function() {
  51. //阻尼系数
  52. var deceleration = mui.os.ios?0.003:0.0009;
  53. mui('.mui-scroll-wrapper').scroll({
  54. bounce: false,
  55. indicators: true, //是否显示滚动条
  56. deceleration:deceleration
  57. });
  58. mui(".mui-scroll").pullToRefresh({
  59. down: {
  60. callback: function() {
  61. var self = this;
  62. setTimeout(function() {
  63. getGroupData();
  64. self.endPullDownToRefresh();
  65. }, 1000);
  66. }
  67. }
  68. });
  69. },
  70. // 绑定页面事件
  71. bindEvents = function () {
  72. $("#groupList").on('tap','.group-info li[data-code]',function(e) {
  73. var code = $(this).attr("data-code");
  74. var name = $(this).attr("data-name");
  75. mui.openWindow('../../mine/html/zuyuanziliao.html', 'zuyuanziliao', {
  76. extras: {
  77. docCode: code,
  78. docName:name,
  79. teamCode: docInfo.adminTeamCode,
  80. // isTeamOwner: isTeamOwner
  81. }
  82. });
  83. return false;
  84. });
  85. $("#groupList").on('tap', ".group-item", function(){
  86. var $el = $(this),
  87. code = $.trim($el.attr("data-group")),
  88. isOpen = $el.hasClass("current"),
  89. $groupInfo = $el.find('.group-info');
  90. if(isOpen) {
  91. $el.removeClass("current");
  92. $el.find(".ui-arrow").removeClass("ui-arrow-b");
  93. $el.find(".ui-arrow").addClass("ui-arrow-r");
  94. $groupInfo.hide();
  95. }else{
  96. var $opened = $(".group-item.current");
  97. $el.addClass("current");
  98. $el.find(".ui-arrow").removeClass("ui-arrow-r");
  99. $el.find(".ui-arrow").addClass("ui-arrow-b");
  100. if($opened.length > 0){
  101. $opened.removeClass('current').find(".group-info").hide();
  102. $opened.find(".ui-arrow").removeClass("ui-arrow-b");
  103. $opened.find(".ui-arrow").addClass("ui-arrow-r");
  104. }
  105. $groupInfo.show();
  106. }
  107. });
  108. $searchbarInput.on('tap',function() {
  109. mui.openWindow({
  110. id: "searchhuanzhe2",
  111. url: "../../tuandui/html/searchdoctor.html",
  112. extras: {}
  113. })
  114. });
  115. /*刷新事件*/
  116. window.addEventListener("refresh", function group(e) {
  117. getGroupData();
  118. });
  119. };
  120. // 页面业务处理流程开始
  121. new Promise(function(resolve, reject) {
  122. // TODO 临时放开
  123. //resolve(true);
  124. mui.plusReady(function() {
  125. // plus已经准备好,可以往下执行
  126. resolve(true);
  127. });
  128. }).then(function() {
  129. // 获取基础环境信息
  130. return getBaseEnvPromise().then(function(env) {
  131. baseEnv = env;
  132. }).then(function() {
  133. // 获取登录医生信息
  134. baseInfo = getBaseInfoPromise();
  135. initScroller();
  136. getGroupData();
  137. // 绑定页面事件
  138. bindEvents();
  139. if(baseEnv.webview.origin){//“随访”功能,需要返回按钮
  140. $(".mui-action-back").show();
  141. }
  142. })
  143. }).catch(function(e) {
  144. plus.nativeUI.closeWaiting();
  145. console && console.error(e);
  146. });
  147. function setAge(age) {
  148. if(age == 0) {
  149. return "<1";
  150. }
  151. if(age == -1)
  152. return "未知";
  153. return age;
  154. }
  155. template.helper("setAge", setAge);
  156. function setSex(s) {
  157. if(s == 1) {
  158. return "男";
  159. } else if(s == 2) {
  160. return "女";
  161. }
  162. }
  163. template.helper("setSex", setSex);
  164. template.helper("getPhoto", function(str){
  165. return getImgUrl(str);
  166. })