huanzhe.js 7.8 KB

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