xuanzejumin_one.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. // 基本信息(包括userAgent)
  2. var baseInfo = null,
  3. // 基础环境信息(包括当前webview)
  4. baseEnv = null;
  5. // 搜索输入框
  6. var $searchbarInput = $('.search-input'),
  7. // 搜索结果展示容器
  8. $searchtResult = $('#search_result'),
  9. // 搜索无结果时显示
  10. $noResultWrap = $('#no_result_wrap'),
  11. // 所选团队的团队名称显示
  12. $selectedTeamName = $('#selected_team_name'),
  13. // 患者分组列表
  14. $patiList = $('#pati_list'),
  15. $recordBtn = $('#recordBtn');
  16. var lastTeamId,
  17. activeGroupType = "",
  18. typeId = "1"; //记录排列的值
  19. var origin,//搜索来源位置
  20. chooseDate,
  21. follow_type = 0; //记录随访方式 1-新增随访,2-临时随访
  22. // 获取登录相关信息
  23. var getBaseInfo = function() {
  24. var userAgent = JSON.parse(plus.storage.getItem("userAgent"));
  25. follow_type = baseEnv.webview.follow_type;
  26. var self = plus.webview.currentWebview();
  27. origin = self.origin;
  28. chooseDate = self.chooseDate;
  29. return {
  30. userAgent: userAgent,
  31. teamInfo: JSON.parse(plus.storage.getItem("teamInfo"))
  32. }
  33. },
  34. // 获取基础环境信息
  35. getBaseEnvPromise = function () {
  36. var env = {
  37. webview: plus&&plus.webview.currentWebview()
  38. };
  39. return Promise.resolve().then(function(res) {
  40. return env;
  41. });
  42. },
  43. updateLastTeamId = function(id) {
  44. lastTeamId = id;
  45. plus.storage.setItem("selectedTeamId",lastTeamId+"");
  46. },
  47. updateTypeId = function(id){
  48. typeId = id;
  49. plus.storage.setItem("selectedTypeId",typeId+"");
  50. }
  51. // 初始化选择团队
  52. initTeams = function (){
  53. // 判断缓存中的团队是否在团队列表中
  54. var isExist = _.some(baseInfo.teamInfo.data,function(t) {
  55. return lastTeamId == t.id
  56. });
  57. if(!isExist) {
  58. if(baseInfo.teamInfo.data.length>0){
  59. updateLastTeamId(baseInfo.teamInfo.data[0].id);
  60. }else{
  61. plus.nativeUI.toast("您还没有任何团队!");
  62. return;
  63. }
  64. }
  65. template.helper("setChecked", function(id, i) {
  66. if(lastTeamId && lastTeamId==id)
  67. return "checked";
  68. return "";
  69. });
  70. $('.lin-sel-group').html(template('teams_tmpl', baseInfo.teamInfo));
  71. if(!lastTeamId && baseInfo.teamInfo.data && baseInfo.teamInfo.data.length) {
  72. updateLastTeamId(baseInfo.teamInfo.data[0].id);
  73. $selectedTeamName.text(baseInfo.teamInfo.data[0].name);
  74. $('.lin-sel-group li').eq(0).addClass("checked");
  75. } else {
  76. var $selected = $('.lin-sel-group').find("li.checked");
  77. $selectedTeamName.text($selected.attr("data-name"));
  78. }
  79. if(typeId){
  80. $(".sel-group li[data-type="+typeId+"]").eq(0).addClass("checked").find("img").attr("src",'../images/checked_all.png');;
  81. }
  82. },
  83. //显示选中的分组
  84. showGroup = function(type) {
  85. if(type){
  86. activeGroupType = type;
  87. }
  88. },
  89. showGroupSel = function() {
  90. var isShow = isShow || $('.lin-sel-group:hidden').length != 0;
  91. $('.lin-mask').toggle(isShow);
  92. if($(".sel-group:hidden").length == 0 && isShow){
  93. $('.sel-group').toggle(!isShow);
  94. }
  95. $('.lin-sel-group').toggle(isShow);
  96. },
  97. showGroupType = function() {
  98. var isShow = isShow || $('.sel-group:hidden').length != 0;
  99. $('.lin-mask').toggle(isShow);
  100. if($(".lin-sel-group:hidden").length == 0 && isShow){
  101. $('.lin-sel-group').toggle(!isShow);
  102. }
  103. $('.sel-group').toggle(isShow);
  104. },
  105. hideMask = function(){
  106. var isShow = isShow || $('.lin-mask:hidden').length != 0,
  107. isTeamShow = $('.lin-sel-group:hidden').length != 0,
  108. isTypeShow = $('.sel-group:hidden').length != 0;
  109. $('.lin-mask').toggle(isShow);
  110. if(!isTeamShow){
  111. $('.lin-sel-group').toggle(isShow);
  112. }
  113. if(!isTypeShow){
  114. $('.sel-group').toggle(isShow);
  115. }
  116. },
  117. // 初始化画面患者分组列表
  118. initPatientGroupsList = function() {
  119. if(!lastTeamId){
  120. return;
  121. }
  122. getReqPromise("doctor/patient_label_info/label_patient_amount",{labelType: typeId, teamCode: lastTeamId})
  123. .then(function(res) {
  124. if(res.status == 200) {
  125. var data = _.filter(res.data,function(o) {
  126. //过滤团队标签中分组人数为0的数据
  127. if(typeId == 4 && o.amount == 0){
  128. return false;
  129. }
  130. return o.labelCode != 0 || (o.labelCode==0 && o.amount > 0);
  131. });
  132. if(data && data.length) {
  133. var html = template("pati_group_tmpl", {list: data});
  134. $patiList.empty().append(html);
  135. if(activeGroupType) {
  136. $patiList.find('.patient-list[data-group="'+activeGroupType+'"]').trigger("click");
  137. }
  138. $noResultWrap.hide();
  139. $searchtResult.show();
  140. } else {
  141. $searchtResult.hide();
  142. $noResultWrap.show();
  143. }
  144. }
  145. }).catch(function(e){ console && console.error(e) });;
  146. },
  147. showLoadMore = function($el) {
  148. var amount = $el.attr("data-amount"),
  149. loaded = $el.find('ul.n-list li').length,
  150. $loadMore = $el.find('.load-more');
  151. if(amount>loaded) {
  152. $loadMore.show();
  153. } else {
  154. $loadMore.hide();
  155. }
  156. },
  157. initPatientListByGroup = function(code) {
  158. plus.nativeUI.showWaiting();
  159. var $group = $patiList.find('.patient-list[data-group="'+code+'"]');
  160. getReqPromise("doctor/patient_label_info/patients_by_label",{labelType: typeId,labelCode: code, teamCode: lastTeamId, page: 1, pagesize: 50})
  161. .then(function(res) {
  162. if(res.status == 200) {
  163. //判断父类组是否以选中
  164. console.log(res.data)
  165. var groupChecked = $group.find(".check-img").hasClass("checked");
  166. var html = template("pati_list_tmpl", {list: _.map(res.data,function(o) {
  167. o.groupChecked = groupChecked;
  168. o.jsonStr = JSON.stringify(o);
  169. return o;
  170. })});
  171. $group.find('ul.n-list').empty().append(html);
  172. showLoadMore($group);
  173. } else {
  174. plus.nativeUI.toast(res.msg);
  175. }
  176. plus.nativeUI.closeWaiting();
  177. }).catch(function(e){ console && console.error(e); plus.nativeUI.closeWaiting(); });
  178. },
  179. togglePatientListShow = function($el) {
  180. var isOpen = $el.hasClass("current"),
  181. $list = $el.find('ul.n-list'),
  182. $siblings = $el.siblings();
  183. if(isOpen) {
  184. $el.removeClass("current");
  185. $list.hide();
  186. $el.find('.load-more').hide();
  187. } else {
  188. $el.addClass("current");
  189. showLoadMore($el);
  190. $siblings.removeClass('current').find("ul.n-list").hide();
  191. $siblings.find('.load-more').hide();
  192. $list.show();
  193. //判断是否选中,选中则将所有子元素的选择框选中
  194. var isChecked = $el.find(".check-img").hasClass('checked');
  195. if(isChecked){
  196. $list.find('.n-list-checked').addClass('checked');
  197. }
  198. }
  199. return isOpen;
  200. },
  201. refreshPage = function(){
  202. baseInfo = getBaseInfo();
  203. lastTypeId = plus.storage.getItem("selectedTypeId");
  204. initPatientGroupsList();
  205. },
  206. // 绑定页面事件
  207. bindEvents = function () {
  208. $patiList.on('touchstart','.load-more',function() {
  209. plus.nativeUI.showWaiting();
  210. var $wrap = $(this).closest(".patient-list"),
  211. code = $wrap.attr("data-group"),
  212. page = parseInt($wrap.attr("data-page"));
  213. getReqPromise("doctor/patient_label_info/patients_by_label",{labelType: typeId,labelCode: code, teamCode: lastTeamId, page: page + 1, pagesize: 50})
  214. .then(function(res) {
  215. if(res.status == 200) {
  216. var html = template("pati_list_tmpl", {list: _.map(res.data,function(o) {
  217. o.jsonStr = JSON.stringify(o);
  218. return o;
  219. })});
  220. $wrap.find('ul.n-list').append(html);
  221. $wrap.attr("data-page",page+1);
  222. showLoadMore($wrap);
  223. }
  224. plus.nativeUI.closeWaiting();
  225. }).catch(function(e){ console && console.error(e); plus.nativeUI.closeWaiting(); });
  226. return false;
  227. }).on('click','.patient-list',function() {
  228. var code = $.trim($(this).attr("data-group")),
  229. isOpen = togglePatientListShow($(this)),
  230. isEmpty = !$(this).find('ul.n-list li').length;
  231. $patiList.find(".patient-type").css({position: "relative", top: "initial", "z-index": "initial"});
  232. code && !isOpen && isEmpty && initPatientListByGroup(code);
  233. }).on('click','.n-list li[data-patient-code]',function(e) {
  234. var patiInfo = $(this).attr("data-json");
  235. e.stopPropagation();
  236. patiInfo = JSON.parse(patiInfo);
  237. if(origin == 'wdyy'){
  238. openWebview("../../wdyy/html/appointment-register.html",{patient:patiInfo.code});
  239. return false;
  240. }
  241. if(origin == 'suifang'){
  242. if(follow_type == 1){
  243. openWebview("../../suifang/html/add_plan.html",{patientInfo: patiInfo,chooseDate:chooseDate});
  244. return false;
  245. }
  246. if(follow_type == 2){
  247. openWebview("../../suifang/html/follow_way.html",{patientInfo: patiInfo});
  248. return false;
  249. }
  250. }
  251. });
  252. $('#sort').on('click', showGroupType);
  253. $('.lin-mask').on('touchstart',function(e){
  254. e.preventDefault();
  255. hideMask();
  256. })
  257. //排列选项
  258. $('.sel-group').on('click', 'li.group-item', function(){
  259. updateTypeId($(this).attr("data-type"));
  260. hideMask();
  261. if(!$(this).hasClass('checked')){
  262. $(this).addClass('checked');
  263. $(this).find('img').attr("src",'../images/checked_all.png');
  264. $(this).siblings().removeClass('checked');
  265. $(this).siblings().find('img').attr('src', '');
  266. }
  267. refreshPage();
  268. });
  269. $('.demo-comtop h1').on('click', showGroupSel);
  270. $('.lin-mask').on('click', showGroupSel);
  271. $('.lin-sel-group').on('click', 'li', function(){
  272. updateLastTeamId($(this).attr("data-code"));
  273. $selectedTeamName.text($(this).attr("data-name"));
  274. showGroupSel(undefined, false);
  275. if(!$(this).hasClass('checked')){
  276. $(this).addClass('checked').siblings().removeClass('checked');
  277. }
  278. refreshPage();
  279. });
  280. $searchbarInput.on('click',function() {
  281. if(origin == 'suifang'){
  282. openWebviewExtras("sousuojumin_one.html",{follow_type:follow_type,origin:origin,chooseDate:chooseDate});
  283. }else{
  284. openWebviewExtras("sousuojumin_one.html",{origin:origin});
  285. }
  286. });
  287. $recordBtn.on('click',function() {
  288. openWebviewExtras("../../wdyy/html/doctor-appointment.html");
  289. });
  290. /*刷新事件*/
  291. window.addEventListener("refresh", function refresh(e) {
  292. refreshPage();
  293. });
  294. window.onscroll = function() {
  295. var scrollTop = document.body.scrollTop,
  296. $current = $('.patient-list.current',$patiList).eq(0),
  297. top = $current.length && $current.offset().top;
  298. if($current.length) {
  299. if(scrollTop >= top - 50) {
  300. $current.find(".patient-type").css({position: "fixed", top: 45, "z-index": 2});
  301. } else {
  302. $current.find(".patient-type").css({position: "relative", top: "initial", "z-index": "initial"});
  303. }
  304. }
  305. }
  306. };
  307. // 页面业务处理流程开始
  308. new Promise(function(resolve, reject) {
  309. // TODO 临时放开
  310. //resolve(true);
  311. mui.plusReady(function() {
  312. // hrefhrefplus已经准备好,可以往下执行
  313. resolve(true);
  314. });
  315. }).then(function() {
  316. // 获取基础环境信息
  317. return getBaseEnvPromise().then(function(env) {
  318. baseEnv = env;
  319. }).then(function() {
  320. // 获取登录基本信息
  321. baseInfo = getBaseInfo();
  322. lastTeamId = plus.storage.getItem("selectedTeamId");
  323. typeId = plus.storage.getItem("selectedTypeId");
  324. if(typeId == null){
  325. typeId = "1";
  326. }
  327. if(origin=="wdyy") {
  328. $recordBtn.show();
  329. }
  330. // 绑定页面事件
  331. bindEvents();
  332. initTeams();
  333. initPatientGroupsList();
  334. });
  335. }).catch(function(e) {
  336. plus.nativeUI.closeWaiting();
  337. console && console.error(e);
  338. });