huanzhe.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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. patientInfo = null;
  13. // 获取基本信息(包括userAgent、上个页面传递的数据)
  14. var getBaseInfoPromise = function() {
  15. // 登录的相关信息
  16. var userAgent = plus && JSON.parse(plus.storage.getItem("userAgent"))
  17. return {
  18. userAgent: userAgent
  19. }
  20. },
  21. // 获取基础环境信息
  22. getBaseEnvPromise = function () {
  23. var env = {
  24. webview: plus&&plus.webview.currentWebview()
  25. };
  26. return Promise.resolve().then(function(res) {
  27. return env;
  28. });
  29. },
  30. //获取分组信息
  31. getGroupData = function(){
  32. docInfo = JSON.parse(plus.storage.getItem("docInfo"));
  33. var url = "doctor/patient_label_info/label_patient_amount",
  34. params = {
  35. labelType: 4, //获取团队标签
  36. teamCode: docInfo.adminTeamCode
  37. };
  38. plus.nativeUI.showWaiting();
  39. sendPost(url, params, null,function(res){
  40. if(res.status == 200){
  41. for(i=0; i<res.data.length; i++){
  42. var item = res.data[i];
  43. pages[item.labelCode] = 1;
  44. }
  45. var html = template("pati_group_tmpl", {list: res.data});
  46. $("#groupList").empty().append(html);
  47. plus.nativeUI.closeWaiting();
  48. }else{
  49. plus.nativeUI.closeWaiting();
  50. mui.toast(res.msg);
  51. }
  52. });
  53. },
  54. // 分页查询列表
  55. initPatientListByGroup = function(code, isInit) {
  56. if(isInit){
  57. pages[code] = 1;
  58. }
  59. var url = "doctor/patient_label_info/patients_by_label",
  60. params = {
  61. labelType: 4,
  62. labelCode: code,
  63. teamCode: docInfo.adminTeamCode,
  64. page: pages[code],
  65. pagesize: 20
  66. };
  67. sendGet(url, params, null, function(res){
  68. if(res.status == 200){
  69. var list = res.data;
  70. if(list.length == 0){
  71. $(".group-item[data-group="+code+"]").find(".load-more").hide();
  72. }else{
  73. var html = template("pati_list_tmpl", {list: list});
  74. if(isInit){
  75. $(".n-list[data-group="+code+"]").empty().append(html);
  76. }else{
  77. $(".n-list[data-group="+code+"]").append(html);
  78. }
  79. if(list.length < 20){
  80. $(".group-item[data-group="+code+"]").find(".load-more").hide();
  81. }else{
  82. pages[code] ++;
  83. $(".group-item[data-group="+code+"]").find(".load-more").show();
  84. }
  85. }
  86. }else{
  87. mui.toast(res.msg);
  88. }
  89. }, true)
  90. },
  91. // 滚动条分页实例初始化
  92. initScroller = function() {
  93. //阻尼系数
  94. var deceleration = mui.os.ios?0.003:0.0009;
  95. mui('.mui-scroll-wrapper').scroll({
  96. bounce: false,
  97. indicators: true, //是否显示滚动条
  98. deceleration:deceleration
  99. });
  100. mui(".mui-scroll").pullToRefresh({
  101. down: {
  102. callback: function() {
  103. var self = this;
  104. setTimeout(function() {
  105. getGroupData();
  106. self.endPullDownToRefresh();
  107. }, 1000);
  108. }
  109. }
  110. });
  111. },
  112. // 绑定页面事件
  113. bindEvents = function () {
  114. $("#groupList").on('tap','li[data-patient-code]',function(e) {
  115. var code = $(this).attr("data-patient-code");
  116. var mobile = $(this).attr("data-patient-phone");
  117. var address = $(this).attr("data-patient-address");
  118. if(baseEnv.webview.origin=="suifang") {//“随访”功能
  119. if(baseEnv.webview.follow_type == 1){
  120. openWebview("../../suifang/html/add_plan.html",{patientInfo: {code:code,mobile:mobile,address:address},chooseDate:baseEnv.webview.chooseDate});
  121. return false;
  122. }
  123. if(baseEnv.webview.follow_type == 2){
  124. openWebview("../../suifang/html/follow_way.html",{patientInfo: {code:code,mobile:mobile,address:address}});
  125. return false;
  126. }
  127. }else{
  128. openWebview("../../huanzhe/html/huanzhexinxi.html",{
  129. patiCode: code
  130. });
  131. }
  132. return false;
  133. });
  134. $("#groupList").on('tap', ".group-item", function(){
  135. var $el = $(this),
  136. code = $.trim($el.attr("data-group")),
  137. amount = parseInt($el.attr("data-amount")),
  138. isOpen = $el.hasClass("current"),
  139. $groupInfo = $el.find('.group-info'),
  140. $siblings = $el.siblings();
  141. if(isOpen) {
  142. $el.removeClass("current");
  143. $el.find(".ui-arrow").removeClass("ui-arrow-t");
  144. $el.find(".ui-arrow").addClass("ui-arrow-b");
  145. $groupInfo.hide();
  146. }else{
  147. var $opened = $(".group-item.current");
  148. $el.addClass("current");
  149. $el.find(".ui-arrow").removeClass("ui-arrow-b");
  150. $el.find(".ui-arrow").addClass("ui-arrow-t");
  151. if($opened.length > 0){
  152. $opened.removeClass('current').find(".group-info").hide();
  153. $opened.find(".ui-arrow").removeClass("ui-arrow-t");
  154. $opened.find(".ui-arrow").addClass("ui-arrow-b");
  155. }
  156. if(amount > 0){
  157. $groupInfo.show();
  158. var liLen = $el.find('ul.n-list li').length;
  159. if(liLen == 0){
  160. initPatientListByGroup(code, true);
  161. }
  162. }
  163. }
  164. });
  165. $("#groupList").on('tap', ".load-more", function(e){
  166. e.stopPropagation();
  167. var $this = $(this),
  168. code = $this.attr("data-group");
  169. // mui('.mui-scroll-wrapper').refresh();
  170. initPatientListByGroup(code, false);
  171. });
  172. $searchbarInput.on('tap',function() {
  173. mui.openWindow({
  174. id: "searchhuanzhe2",
  175. url: "../../huanzhe/html/searchhuanzhe.html",
  176. extras: {}
  177. })
  178. });
  179. $(".header-link").on('click', function(){
  180. openWebview("../../huanzhe/html/biaoqianguanli.html",{
  181. teamCode: docInfo.adminTeamCode
  182. });
  183. })
  184. /*刷新事件*/
  185. window.addEventListener("refresh", function group(e) {
  186. getGroupData();
  187. });
  188. };
  189. // 页面业务处理流程开始
  190. new Promise(function(resolve, reject) {
  191. // TODO 临时放开
  192. //resolve(true);
  193. mui.plusReady(function() {
  194. // plus已经准备好,可以往下执行
  195. resolve(true);
  196. });
  197. }).then(function() {
  198. // 获取基础环境信息
  199. return getBaseEnvPromise().then(function(env) {
  200. baseEnv = env;
  201. }).then(function() {
  202. // 获取登录医生信息
  203. baseInfo = getBaseInfoPromise();
  204. initScroller();
  205. // searchByPaging(true);
  206. getGroupData();
  207. // 绑定页面事件
  208. bindEvents();
  209. if(baseEnv.webview.origin){//“随访”功能,需要返回按钮
  210. $(".mui-action-back").show();
  211. }
  212. })
  213. }).catch(function(e) {
  214. plus.nativeUI.closeWaiting();
  215. console && console.error(e);
  216. });
  217. function setAge(age) {
  218. if(age == 0) {
  219. return "<1";
  220. }
  221. if(age == -1)
  222. return "未知";
  223. return age;
  224. }
  225. template.helper("setAge", setAge);
  226. function setSex(s) {
  227. if(s == 1) {
  228. return "男";
  229. } else if(s == 2) {
  230. return "女";
  231. }
  232. }
  233. template.helper("setSex", setSex);
  234. template.helper("getPhoto", function(str){
  235. return getImgUrl(str);
  236. })