huanzhe-specal.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  1. // 基本信息(包括userAgent)
  2. var baseInfo = null,
  3. // 基础环境信息(包括当前webview)
  4. baseEnv = null;
  5. var // 搜索
  6. $searchbar = $('.searchbar'),
  7. // 搜索取消按钮
  8. $searchCancelBtn = $('.searchbar-cancel'),
  9. // 搜索框下面悬浮的搜索提示
  10. $searchSuggest = $('#search_suggest_text'),
  11. // 搜索结果展示容器
  12. $searchtResult = $('#search_result'),
  13. // 搜索无结果时显示
  14. $noResultWrap = $('#no_result_wrap'),
  15. // 患者分组列表
  16. $patiList = $('#pati_list'),
  17. // 居民未分配健管师“点击处理”
  18. $handleLink = $('#handle_link');
  19. // 从缓存取出所选团队
  20. var lastTeamId,
  21. activeGroupType = "";
  22. var self;
  23. var docInfo;
  24. var labelType = 7;// 标签类型 1:服务类型 2:健康情况 3:疾病类型 4:自定义,5.周月标签 6.老年人标识 7.专病类型,8.健康情况
  25. var judgeIndex = 0;// 用于判断所选列表
  26. var assisantHtml = []
  27. var myScroll,
  28. startScrollX,
  29. scrollXd,
  30. $scrollDom;
  31. function initScroller(){
  32. //阻尼系数
  33. var deceleration = mui.os.ios?0.003:0.0009;
  34. mui('#wrapper1').scroll({
  35. scrollX: true,
  36. bounce: false,
  37. indicators: true, //是否显示滚动条
  38. deceleration:deceleration
  39. });
  40. mui('#wrapper').scroll({
  41. scrollX: true,
  42. bounce: false,
  43. indicators: true, //是否显示滚动条
  44. deceleration:deceleration
  45. });
  46. myScroll = mui(".mui-scroll").pullToRefresh({
  47. down: {
  48. callback: function() {
  49. var self = this;
  50. setTimeout(function() {
  51. $('.lin-mask').hide();
  52. $('.lin-sel-group').hide();
  53. refreshPage();
  54. self.endPullDownToRefresh();
  55. }, 1000);
  56. }
  57. },
  58. scrollLeft: function(){
  59. xScroll = true;
  60. }
  61. });
  62. }
  63. /*刷新事件*/
  64. window.addEventListener("refresh", function refresh(e) {
  65. $('.lin-mask').hide();
  66. $('.lin-sel-group').hide();
  67. getBaseEnvPromise();
  68. refreshPage();
  69. getNoTapNumber();
  70. });
  71. // 获取登录相关信息
  72. var getBaseInfo = function() {
  73. // 登录的相关信息
  74. var userAgent = JSON.parse(plus.storage.getItem("userAgent"))
  75. return {
  76. userAgent: userAgent,
  77. teamInfo: JSON.parse(plus.storage.getItem("teamInfo"))
  78. }
  79. },
  80. // 获取基础环境信息
  81. getBaseEnvPromise = function () {
  82. self = plus.webview.currentWebview();
  83. docInfo = JSON.parse(plus.storage.getItem("docInfo"));
  84. // 获取医生下未分配标签数目
  85. getNoTapNumber();
  86. var env = {
  87. webview: plus&&plus.webview.currentWebview()
  88. };
  89. return Promise.resolve().then(function(res) {
  90. return env;
  91. });
  92. },
  93. updateLastTeamId = function(id) {
  94. lastTeamId = id;
  95. plus.storage.setItem("selectedTeamId",lastTeamId+"");
  96. },
  97. // 初始化选择团队
  98. initTeams = function (){
  99. //判断缓存中的团队是否在团队列表中
  100. var isExist = _.some(baseInfo.teamInfo.data,function(t) {
  101. return lastTeamId == t.id
  102. });
  103. if(!isExist) {
  104. updateLastTeamId(baseInfo.teamInfo.data[0].id);
  105. }
  106. getSpecailType();
  107. },
  108. // 滚动框数据渲染
  109. setListData = function($ele, $noele, html) {
  110. $ele.empty().append(html);
  111. if(activeGroupType) {
  112. $ele.find('.patient-list[data-group="'+activeGroupType+'"]').trigger("tap");
  113. }
  114. $noele.hide();
  115. $ele.show();
  116. },
  117. setUnListData = function($ele, $noele) {
  118. $ele.empty();
  119. $noele.show();
  120. $ele.hide();
  121. },
  122. // 获取未分配居民数目
  123. getNoTapNumber = function() {
  124. var url = "/doctor/specialist/findSpecialistPatientRelationCout";
  125. plus.nativeUI.showWaiting();
  126. getReqPromise(url, {doctor: docInfo.code},'GET',true)
  127. .then(function(res) {
  128. if(res.status == 200) {
  129. if(!res.data) {
  130. $(".no-manage-tap").hide();
  131. $(".setNotapHeight").css({
  132. 'height':$(window).height()-85
  133. })
  134. $("#wrapper").css({
  135. 'top': '91px',
  136. 'height': $(window).height()-91
  137. })
  138. } else {
  139. $(".no-manage-tap").show();
  140. $(".setNotapHeight").css({
  141. 'height':$(window).height()-150
  142. })
  143. $("#wrapper").css({
  144. 'top': '155px',
  145. 'height': $(window).height()-155
  146. })
  147. $("#no_tap").html(res.data)
  148. }
  149. } else {
  150. plus.nativeUI.toast(res.msg);
  151. }
  152. plus.nativeUI.closeWaiting();
  153. }).catch(function(e){ console && console.error(e); plus.nativeUI.closeWaiting(); });
  154. },
  155. // 获取labelType下的label列表
  156. getSpecailType = function(){
  157. plus.nativeUI.showWaiting();
  158. sendPost("/doctor/specialist/findLabelAndPatientCount", {doctor: docInfo.code, type: labelType, teamCode: lastTeamId}, null, function(res){
  159. plus.nativeUI.closeWaiting();
  160. if(res.status == 200){
  161. var data = _.filter(res.data,function(o) {
  162. return o.label!= 0 || (o.label==0 && o.count > 0);
  163. });
  164. if(data && data.length) {
  165. var html = template("pati_group_tmpl", {list: data});
  166. setListData($patiList, $noResultWrap, html)
  167. } else {
  168. setUnListData($patiList, $noResultWrap)
  169. }
  170. } else {
  171. mui.toast(res.msg || "加载失败!");
  172. }
  173. },'GET','',true)
  174. },
  175. // 获取未分配计管师居民
  176. getUnAssistantPat = function(boolean, ele) {// boolean->true 表示只获取列表
  177. plus.nativeUI.showWaiting();
  178. var $group;
  179. if(boolean) {
  180. $group = ele.find('.patient-list[data-noassisant="'+docInfo.code+'"]')
  181. }
  182. sendPost("/doctor/specialist/findPatientNoAssistant", {doctor: docInfo.code, page: 1, size: 50}, null, function(res){
  183. plus.nativeUI.closeWaiting();
  184. if(res.status == 200){
  185. if (boolean) {
  186. var html = template("pati_list_tmpl", {list: _.map(res.data.detailModelList, function(o) {
  187. o.jsonStr = JSON.stringify(o);
  188. return o;
  189. })});
  190. $group.find('ul.n-list').empty().append(html);
  191. showLoadMore($group);
  192. } else {
  193. assisantHtml = []
  194. var obj = {name: "我", doctor: docInfo.code, count: res.data.totalCount}
  195. assisantHtml.push(obj)
  196. getPowerList()
  197. }
  198. } else {
  199. mui.toast(res.msg || "加载失败!");
  200. }
  201. },'GET','',true)
  202. },
  203. // 有权限的获取计管师列表
  204. getPowerList = function() {
  205. plus.nativeUI.showWaiting();
  206. sendPost("/doctor/specialist/findHealthAssistantPatientCount", {doctor: docInfo.code}, null, function(res){
  207. plus.nativeUI.closeWaiting();
  208. if(res.status == 200){
  209. var data = _.filter(res.data,function(o) {
  210. return o.label != 0 || (o.label==0 && o.count > 0);
  211. });
  212. if(data && data.length) {
  213. var list = assisantHtml.concat(data)
  214. var html = template("pati_group_tmpl", {list: list});
  215. setListData($patiList, $noResultWrap, html)
  216. } else {
  217. setUnListData($patiList, $noResultWrap)
  218. }
  219. } else {
  220. mui.toast(res.msg || "加载失败!");
  221. }
  222. },'GET','',true)
  223. },
  224. //显示选中的分组
  225. showGroup = function(type) {
  226. if(type){
  227. activeGroupType = type;
  228. }
  229. },
  230. showGroupSel = function() {
  231. if(self.type == 1)
  232. return;
  233. var isShow = isShow || $('.lin-mask:hidden').length != 0;
  234. $('.lin-mask').toggle(isShow);
  235. $('.lin-sel-group').toggle(isShow);
  236. },
  237. showLoadMore = function($el) {
  238. var amount = $el.attr("data-amount"),
  239. loaded = $el.find('ul.n-list li').length,
  240. $loadMore = $el.find('.load-more');
  241. if(amount>loaded) {
  242. $loadMore.show();
  243. } else {
  244. $loadMore.hide();
  245. }
  246. },
  247. // label下居民列表
  248. initPatientListByGroup = function(code, ele) {
  249. var url = "/doctor/specialist/getPatientByLabel";
  250. plus.nativeUI.showWaiting();
  251. var $group = ele.find('.patient-list[data-group="'+code+'"]');
  252. getReqPromise(url, {doctor: docInfo.code, labelType: labelType, labelCode: code, page: 1, size: 50},'POST',true)
  253. .then(function(res) {
  254. if(res.status == 200) {
  255. var html = template("pati_list_tmpl", {list: _.map(res.data,function(o) {
  256. o.jsonStr = JSON.stringify(o);
  257. return o;
  258. })});
  259. $group.find('ul.n-list').empty().append(html);
  260. showLoadMore($group);
  261. } else {
  262. plus.nativeUI.toast(res.msg);
  263. }
  264. plus.nativeUI.closeWaiting();
  265. }).catch(function(e){ console && console.error(e); plus.nativeUI.closeWaiting(); });
  266. },
  267. initSpecailPatientListByGroup = function(assistant, ele) {
  268. var url = "/doctor/specialist/findPatientRelatioByAssistant";
  269. plus.nativeUI.showWaiting();
  270. var $group = ele.find('.patient-list[data-code="'+assistant+'"]');
  271. getReqPromise(url, {assistant: assistant, doctor: docInfo.code, page: 1, size: 50},'GET',true)
  272. .then(function(res) {
  273. if(res.status == 200) {
  274. var html = template("pati_list_tmpl", {list: _.map(res.data,function(o) {
  275. o.jsonStr = JSON.stringify(o);
  276. o.healthAssistant = assistant;
  277. return o;
  278. })});
  279. $group.find('ul.n-list').empty().append(html);
  280. showLoadMore($group);
  281. } else {
  282. plus.nativeUI.toast(res.msg);
  283. }
  284. plus.nativeUI.closeWaiting();
  285. }).catch(function(e){ console && console.error(e); plus.nativeUI.closeWaiting(); });
  286. }
  287. togglePatientListShow = function($el) {
  288. var isOpen = $el.hasClass("current"),
  289. $list = $el.find('ul.n-list'),
  290. $siblings = $el.siblings('.patient-list');
  291. if(isOpen) {
  292. $el.removeClass("current");
  293. $list.hide();
  294. $el.find('.load-more').hide();
  295. } else {
  296. $el.addClass("current");
  297. showLoadMore($el);
  298. $siblings.removeClass('current').find("ul.n-list").hide();
  299. $siblings.find('.load-more').hide();
  300. $list.show();
  301. }
  302. return isOpen;
  303. },
  304. refreshPage = function(){
  305. baseInfo = getBaseInfo();
  306. lastTeamId = plus.storage.getItem("selectedTeamId");
  307. if(judgeIndex == 3) {
  308. getUnAssistantPat()
  309. } else {
  310. getSpecailType();
  311. }
  312. },
  313. bindEventFunction = function(ele) {
  314. ele.on('tap','.load-more',function() {
  315. plus.nativeUI.showWaiting();
  316. var $wrap = $(this).closest(".patient-list"),
  317. code = $wrap.attr("data-group"),
  318. assistant = $wrap.attr("data-code"),
  319. page = parseInt($wrap.attr("data-page"));
  320. var url = code ? "/doctor/specialist/getPatientByLabel" : "/doctor/specialist/findPatientRelatioByAssistant";
  321. if(code) {
  322. getReqPromise(url,{doctor: docInfo.code, labelType: labelType, labelCode: code, page: page + 1, pagesize: 50},'POST',true)
  323. .then(function(res) {
  324. if(res.status == 200) {
  325. var html = template("pati_list_tmpl", {list: _.map(res.data,function(o) {
  326. o.jsonStr = JSON.stringify(o);
  327. return o;
  328. })});
  329. $wrap.find('ul.n-list').append(html);
  330. $wrap.attr("data-page",page+1);
  331. showLoadMore($wrap);
  332. }
  333. plus.nativeUI.closeWaiting();
  334. }).catch(function(e){ console && console.error(e); plus.nativeUI.closeWaiting(); });
  335. } else if(assistant) {
  336. getReqPromise(url,{assistant: assistant, page: page + 1, pagesize: 50},'POST',true)
  337. .then(function(res) {
  338. if(res.status == 200) {
  339. var html = template("pati_list_tmpl", {list: _.map(res.data,function(o) {
  340. o.jsonStr = JSON.stringify(o);
  341. return o;
  342. })});
  343. $wrap.find('ul.n-list').append(html);
  344. $wrap.attr("data-page",page+1);
  345. showLoadMore($wrap);
  346. }
  347. plus.nativeUI.closeWaiting();
  348. }).catch(function(e){ console && console.error(e); plus.nativeUI.closeWaiting(); });
  349. } else {
  350. getReqPromise("/doctor/specialist/findPatientNoAssistant",{doctor: docInfo.code, page: page + 1, pagesize: 50},'POST',true)
  351. .then(function(res) {
  352. if(res.status == 200) {
  353. var html = template("pati_list_tmpl", {list: _.map(res.data,function(o) {
  354. o.jsonStr = JSON.stringify(o);
  355. return o;
  356. })});
  357. $wrap.find('ul.n-list').append(html);
  358. $wrap.attr("data-page",page+1);
  359. showLoadMore($wrap);
  360. }
  361. plus.nativeUI.closeWaiting();
  362. }).catch(function(e){ console && console.error(e); plus.nativeUI.closeWaiting(); });
  363. }
  364. return false;
  365. }).on('tap','.patient-list',function() {
  366. if($(".patient-list.current").length>0 && !$(this).hasClass('current')){
  367. mui('#wrapper').scroll().scrollTo(0,0,0);
  368. }
  369. var code = $.trim($(this).attr("data-group")),
  370. isOpen = togglePatientListShow($(this)),
  371. isEmpty = !$(this).find('ul.n-list li').length,
  372. assistant = $.trim($(this).attr("data-code"));
  373. ele.find(".patient-type").css({position: "relative", top: "initial", "z-index": "initial"});
  374. code && !isOpen && isEmpty && initPatientListByGroup(code, ele);
  375. assistant && !isOpen && isEmpty && initSpecailPatientListByGroup(assistant, ele);
  376. !code && !assistant && !isOpen && isEmpty && getUnAssistantPat(true, ele);
  377. }).on('tap','li[data-patient-code]',function(e) {
  378. var patiInfo = $(this).attr("data-json");
  379. var info = JSON.parse(patiInfo);
  380. openWebview("../../kfgl/html/denizen.html",{
  381. patiCode: info.code || info.patient
  382. })
  383. return false;
  384. }).on('tap','.patient-type-big',function(){
  385. var self = $(this);
  386. var groupType = self.attr('data-groupindex');
  387. $('.patient-list').each(function(i,el){
  388. if($(el).attr('data-parent') == groupType){
  389. if(!$(el).hasClass('show')){
  390. $(el).show().addClass('show');
  391. self.addClass('current');
  392. }else{
  393. $(el).hide().removeClass('show');
  394. self.removeClass('current');
  395. }
  396. }
  397. })
  398. })
  399. },
  400. // 绑定页面事件
  401. bindEvents = function () {
  402. $("#con_tit div").on("tap", function() {
  403. var $this = $(this),
  404. index = $this.index();
  405. if($this.hasClass("active")){
  406. return false;
  407. }
  408. $this.siblings().removeClass("active");
  409. $this.addClass("active");
  410. if(index == 0) {
  411. judgeIndex = 0;
  412. labelType = 7;
  413. getSpecailType();
  414. };
  415. if(index == 1) {
  416. judgeIndex = 1;
  417. labelType = 8;
  418. getSpecailType();
  419. };
  420. if(index == 2) {
  421. judgeIndex = 2;
  422. labelType = 4;
  423. getSpecailType();
  424. };
  425. if(index == 3) {
  426. judgeIndex = 3;
  427. getUnAssistantPat();
  428. // getPowerList()
  429. };
  430. })
  431. bindEventFunction($patiList);
  432. $('.lin-mask').on('tap', showGroupSel).on('touchmove',function() {
  433. return false;
  434. });
  435. $('.lin-sel-group').on('touchmove',function() {
  436. // return false;
  437. });
  438. $('.lin-sel-group').on('tap', 'li', function(){
  439. updateLastTeamId($(this).attr("data-code"));
  440. showGroupSel(undefined, false);
  441. if(!$(this).hasClass('checked')){
  442. $(this).addClass('checked').siblings().removeClass('checked');
  443. }
  444. getTeamPatientCount();
  445. refreshPage();
  446. });
  447. $searchbar.on('tap',function() {
  448. var searchPage = plus.webview.getWebviewById('searchPatSpecail');
  449. if(searchPage){
  450. mui.fire(searchPage, "initSearch")
  451. } else {
  452. mui.openWindow({
  453. id: "searchPatSpecail",
  454. url: "../../huanzhe/html/searchPatSpecail.html"
  455. })
  456. }
  457. });
  458. // 跳转分配标签页面
  459. $(".no-manage-tap").on("tap", function() {
  460. mui.openWindow({
  461. url: "../../zhuanbing/html/dingyibiaoqian.html",
  462. id: "dingyibiaoqian"
  463. })
  464. })
  465. $(".list").on("tap", ".operate", function(e) {
  466. e.preventDefault();
  467. e.stopPropagation();
  468. openWebview("../../zhuanbing/html/fenpeijianguanshi.html",{
  469. patiCode: $(this).attr("data-patient"),
  470. healthAssistant: $(this).attr("data-healthAssistant")
  471. })
  472. }).on('touchstart', '.n-list-link', function(e){ //左滑动作开始
  473. e.preventDefault();
  474. startScrollX = e.originalEvent.targetTouches[0].screenX;
  475. })
  476. .on('touchmove', '.n-list-link', function(e){ //左滑动作移动
  477. e.preventDefault();
  478. scrollXd = e.originalEvent.targetTouches[0].screenX - startScrollX;
  479. var offLeft = $(e.currentTarget).find('div.operate').children('div').length * (-65);
  480. if(scrollXd<0 && scrollXd >= offLeft)
  481. $(e.currentTarget).css('left', scrollXd + 'px');
  482. })
  483. .on('touchend', '.n-list-link', function(e){ //左滑动作结束
  484. e.preventDefault();
  485. if(scrollXd<-50){
  486. $scrollDom = $(e.currentTarget);
  487. var offLeft = $(e.currentTarget).find('div.operate').children('div').length * (-65);
  488. $scrollDom.animate({left: offLeft}, "fast");
  489. } else{
  490. startScrollX = undefined;
  491. $scrollDom = undefined;
  492. $(e.currentTarget).animate({left: '0px'}, "fast");
  493. }
  494. scrollXd = undefined;
  495. xScroll = false;
  496. myScroll.options.isLeftScroll = false;
  497. })
  498. window.onscroll = function() {
  499. var scrollTop = document.body.scrollTop,
  500. $current = $('.patient-list.current',$patiList).eq(0),
  501. top = $current.length && $current.offset().top;
  502. if($current.length) {
  503. if(scrollTop >= top - 50) {
  504. $current.find(".patient-type").css({position: "fixed", top: 45, "z-index": 9999});
  505. } else {
  506. $current.find(".patient-type").css({position: "relative", top: "initial", "z-index": "initial"});
  507. }
  508. }
  509. }
  510. };
  511. // 页面业务处理流程开始
  512. new Promise(function(resolve, reject) {
  513. // TODO 临时放开
  514. //resolve(true);
  515. mui.plusReady(function() {
  516. // hrefhrefplus已经准备好,可以往下执行
  517. resolve(true);
  518. });
  519. }).then(function() {
  520. mui('#wrapper1').scroll()
  521. initScroller();
  522. // 获取基础环境信息
  523. return getBaseEnvPromise().then(function(env) {
  524. baseEnv = env;
  525. $('.mid-bar').toggle(self.type!=1);
  526. }).then(function() {
  527. // 获取登录基本信息
  528. baseInfo = getBaseInfo();
  529. lastTeamId = plus.storage.getItem("selectedTeamId");
  530. // 绑定页面事件
  531. bindEvents();
  532. initTeams();
  533. })
  534. }).catch(function(e) {
  535. plus.nativeUI.closeWaiting();
  536. console && console.error(e);
  537. });