huanzhe.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493
  1. // 基本信息(包括userAgent)
  2. var baseInfo = null,
  3. // 基础环境信息(包括当前webview)
  4. baseEnv = null;
  5. // 搜索框
  6. var $searchbar = $('.searchbar'),
  7. // 搜索输入框
  8. $searchbarInput = $('.searchbar .search-input'),
  9. // 搜索取消按钮
  10. $searchCancelBtn = $('.searchbar-cancel'),
  11. // 搜索框下面悬浮的搜索提示
  12. $searchSuggest = $('#search_suggest_text'),
  13. // 搜索结果展示容器
  14. $searchtResult = $('#search_result'),
  15. // 搜索无结果时显示
  16. $noResultWrap = $('#no_result_wrap'),
  17. // 患者分组列表
  18. $patiList = $('#pati_list'),
  19. // 所选团队的团队名称显示位置
  20. $selectedTeamName = $('.demo-comtop h1'),
  21. // 当医生是当前所选团队的团队长时,如果有居民未分配健管师则显示顶部信息提示
  22. $topMsgBar = $('#top_msg_bar'),
  23. // 居民未分配健管师数量显示位置
  24. $unassignedNum = $('#unassigned_num'),
  25. // 页面顶部分类标签列表(四个列表项)
  26. $groupLabelList = $('#group_label_list'),
  27. // 居民未分配健管师“点击处理”
  28. $handleLink = $('#handle_link'),
  29. $wfp = $('.div-wfp'),
  30. $qbjm = $('.div-qbjm'),
  31. $back = $('.mui-action-back');
  32. // 从缓存取出所选团队
  33. var lastTeamId,
  34. activeGroupType = "";
  35. var self;
  36. var docInfo;
  37. var myScroll;
  38. function initScroller(){
  39. //阻尼系数
  40. var deceleration = mui.os.ios?0.003:0.0009;
  41. mui('.mui-scroll-wrapper').scroll({
  42. scrollX: true,
  43. bounce: false,
  44. indicators: true, //是否显示滚动条
  45. deceleration:deceleration
  46. });
  47. myScroll = mui(".mui-scroll").pullToRefresh({
  48. down: {
  49. callback: function() {
  50. var self = this;
  51. setTimeout(function() {
  52. $('.lin-mask').hide();
  53. $('.lin-sel-group').hide();
  54. refreshPage();
  55. self.endPullDownToRefresh();
  56. showTopMsgBar();
  57. }, 1000);
  58. }
  59. },
  60. scrollLeft: function(){
  61. xScroll = true;
  62. }
  63. });
  64. }
  65. // 获取登录相关信息
  66. var getBaseInfo = function() {
  67. // 登录的相关信息
  68. var userAgent = JSON.parse(plus.storage.getItem("userAgent"))
  69. return {
  70. userAgent: userAgent,
  71. teamInfo: JSON.parse(plus.storage.getItem("teamInfo"))
  72. }
  73. },
  74. // 获取基础环境信息
  75. getBaseEnvPromise = function () {
  76. self = plus.webview.currentWebview();
  77. docInfo = JSON.parse(plus.storage.getItem("docInfo"));
  78. var env = {
  79. webview: plus&&plus.webview.currentWebview()
  80. };
  81. return Promise.resolve().then(function(res) {
  82. return env;
  83. });
  84. },
  85. updateLastTeamId = function(id) {
  86. lastTeamId = id;
  87. plus.storage.setItem("selectedTeamId",lastTeamId+"");
  88. },
  89. // 初始化选择团队
  90. initTeams = function (){
  91. // 判断缓存中的团队是否在团队列表中
  92. // var isExist = _.some(baseInfo.teamInfo.data,function(t) {
  93. // return lastTeamId == t.id
  94. // });
  95. //
  96. // if(!isExist) {
  97. updateLastTeamId(baseInfo.teamInfo.data[0].id);
  98. // }
  99. template.helper("setChecked", function(id, i) {
  100. if(lastTeamId && lastTeamId==id)
  101. return "checked";
  102. return "";
  103. });
  104. $('.lin-sel-group').html(template('teams_tmpl', baseInfo.teamInfo));
  105. var $selected;
  106. if(!lastTeamId && baseInfo.teamInfo.data && baseInfo.teamInfo.data.length) {
  107. updateLastTeamId(baseInfo.teamInfo.data[0].id);
  108. setTitle(baseInfo.teamInfo.data[0].name);
  109. $selected = $('.lin-sel-group li').eq(0);
  110. $selected.addClass("checked");
  111. } else {
  112. $selected = $('.lin-sel-group').find("li.checked");
  113. setTitle($selected.attr("data-name"));
  114. }
  115. getTeamPatientCount();
  116. $qbjm.toggle($selected.attr('data-leadercode') == docInfo.code);
  117. },
  118. getTeamPatientCount = function(){
  119. sendPost("/doctor/patient_label_info/team_amount", {teamCode: lastTeamId}, null, function(res){
  120. if(res.status == 200){
  121. $('.div-qbjm label').html("("+ res.data.focusAmount +"/"+ res.data.amount+")");
  122. } else {
  123. mui.toast("获取居民总数失败!");
  124. }
  125. },'POST','',true)
  126. },
  127. setTitle = function(title){
  128. if(self.type == 1)
  129. $selectedTeamName.html(title + "签约居民管理");
  130. else
  131. $selectedTeamName.html(title + '签约居民<label class="lin-down-arrow"></label>');
  132. },
  133. //显示选中的分组
  134. showGroup = function(type) {
  135. if(type){
  136. activeGroupType = type;
  137. }
  138. },
  139. showGroupSel = function() {
  140. if(self.type == 1)
  141. return;
  142. var isShow = isShow || $('.lin-mask:hidden').length != 0;
  143. $('.lin-mask').toggle(isShow);
  144. $('.lin-sel-group').toggle(isShow);
  145. },
  146. // 初始化画面患者分组列表
  147. initPatientGroupsList = function() {
  148. plus.nativeUI.showWaiting();
  149. var url = self.type == 1 ? "/doctor/patient_label_info/label_team_amount" : "doctor/patient_label_info/label_patient_amount";
  150. getReqPromise(url,{labelType: 1, teamCode: lastTeamId},'POST',true)
  151. .then(function(res) {
  152. if(res.status == 200) {
  153. var data = _.filter(res.data,function(o) {
  154. return o.labelCode != 0 || (o.labelCode==0 && o.amount > 0);
  155. });
  156. if(data && data.length) {
  157. var html = template("pati_group_tmpl", {list: data});
  158. $patiList.empty().append(html);
  159. if(activeGroupType) {
  160. $patiList.find('.patient-list[data-group="'+activeGroupType+'"]').trigger("tap");
  161. }
  162. $noResultWrap.hide();
  163. $searchtResult.show();
  164. } else {
  165. $searchtResult.hide();
  166. $noResultWrap.show();
  167. }
  168. }
  169. plus.nativeUI.closeWaiting();
  170. }).catch(function(e){
  171. plus.nativeUI.closeWaiting();
  172. console && console.error(e) });;
  173. },
  174. showLoadMore = function($el) {
  175. var amount = $el.attr("data-amount"),
  176. loaded = $el.find('ul.n-list li').length,
  177. $loadMore = $el.find('.load-more');
  178. if(amount>loaded) {
  179. $loadMore.show();
  180. } else {
  181. $loadMore.hide();
  182. }
  183. },
  184. initPatientListByGroup = function(code) {
  185. var url = self.type == 1 ? "doctor/patient_label_info/team_patient" : "doctor/patient_label_info/patients_by_label";
  186. plus.nativeUI.showWaiting();
  187. var $group = $patiList.find('.patient-list[data-group="'+code+'"]');
  188. getReqPromise(url, {labelType:1, teamCode: lastTeamId, labelCode: code, page: 1, pagesize: 50},'POST',true)
  189. .then(function(res) {
  190. if(res.status == 200) {
  191. var html = template("pati_list_tmpl", {list: _.map(res.data,function(o) {
  192. o.jsonStr = JSON.stringify(o);
  193. return o;
  194. })});
  195. $group.find('ul.n-list').empty().append(html);
  196. showLoadMore($group);
  197. } else {
  198. plus.nativeUI.toast(res.msg);
  199. }
  200. plus.nativeUI.closeWaiting();
  201. }).catch(function(e){ console && console.error(e); plus.nativeUI.closeWaiting(); });
  202. },
  203. togglePatientListShow = function($el) {
  204. var isOpen = $el.hasClass("current"),
  205. $list = $el.find('ul.n-list'),
  206. $siblings = $el.siblings('.patient-list');
  207. if(isOpen) {
  208. $el.removeClass("current");
  209. $list.hide();
  210. $el.find('.load-more').hide();
  211. } else {
  212. $el.addClass("current");
  213. showLoadMore($el);
  214. $siblings.removeClass('current').find("ul.n-list").hide();
  215. $siblings.find('.load-more').hide();
  216. $list.show();
  217. }
  218. return isOpen;
  219. },
  220. showTopMsgBar = function() {
  221. if(baseEnv.webview.message){//“转发给”功能,需要返回按钮
  222. return false;
  223. }
  224. var leadCode = $(".lin-sel-group li.checked").attr("data-leaderCode");
  225. $qbjm.toggle(leadCode==docInfo.code);
  226. if($.trim(leadCode) == $.trim(baseInfo.userAgent.uid)) {
  227. getReqPromise("doctor/family_contract/findNoHealthSignFamilyNum",{doctor: leadCode, teamCode: lastTeamId},'POST',true)
  228. .then(function(res){
  229. if(res.status == 200) {
  230. if(parseInt(res.data.num)) {
  231. $('.div-wfp label').html("("+ res.data.num +")");
  232. $wfp.show();
  233. } else {
  234. $wfp.hide();
  235. }
  236. }
  237. }).catch(function(e){ console && console.error(e); plus.nativeUI.closeWaiting(); });
  238. } else {
  239. $wfp.hide();
  240. }
  241. },
  242. refreshPage = function(){
  243. baseInfo = getBaseInfo();
  244. lastTeamId = plus.storage.getItem("selectedTeamId");
  245. initPatientGroupsList();
  246. getTeamPatientCount();
  247. },
  248. // 绑定页面事件
  249. bindEvents = function () {
  250. $patiList.on('tap','.load-more',function() {
  251. plus.nativeUI.showWaiting();
  252. var $wrap = $(this).closest(".patient-list"),
  253. code = $wrap.attr("data-group"),
  254. page = parseInt($wrap.attr("data-page"));
  255. var url = self.type == 1 ? "doctor/patient_label_info/team_patient" : "doctor/patient_label_info/patients_by_label";
  256. getReqPromise(url,{labelType: 1,labelCode: code, teamCode: lastTeamId, page: page + 1, pagesize: 50},'POST',true)
  257. .then(function(res) {
  258. if(res.status == 200) {
  259. var html = template("pati_list_tmpl", {list: _.map(res.data,function(o) {
  260. o.jsonStr = JSON.stringify(o);
  261. return o;
  262. })});
  263. $wrap.find('ul.n-list').append(html);
  264. $wrap.attr("data-page",page+1);
  265. showLoadMore($wrap);
  266. }
  267. plus.nativeUI.closeWaiting();
  268. }).catch(function(e){ console && console.error(e); plus.nativeUI.closeWaiting(); });
  269. return false;
  270. }).on('tap','.patient-list',function() {
  271. if($(".patient-list.current").length>0 && !$(this).hasClass('current')){
  272. mui('.mui-scroll-wrapper').scroll().scrollTo(0,0,0);
  273. }
  274. var code = $.trim($(this).attr("data-group")),
  275. isOpen = togglePatientListShow($(this)),
  276. isEmpty = !$(this).find('ul.n-list li').length;
  277. $patiList.find(".patient-type").css({position: "relative", top: "initial", "z-index": "initial"});
  278. code && !isOpen && isEmpty && initPatientListByGroup(code);
  279. }).on('tap','li[data-patient-code]',function(e) {
  280. var patiInfo = $(this).attr("data-json");
  281. var info = JSON.parse(patiInfo);
  282. if(baseEnv.webview.message) {
  283. openWebview("../../message/html/p2p.html",{otherCode: info.code,otherName: info.name,otherPhoto: info.photo,otherSex: info.sex});
  284. } else {
  285. openWebview("../../huanzhe/html/huanzhexinxi.html",{
  286. teamCode: self.type==1? lastTeamId : undefined,
  287. patiInfo: patiInfo,
  288. patiCode: info.code
  289. });
  290. }
  291. return false;
  292. }).on('tap','.patient-type-big',function(){
  293. var self = $(this);
  294. var groupType = self.attr('data-groupindex');
  295. $('.patient-list').each(function(i,el){
  296. if($(el).attr('data-parent') == groupType){
  297. if(!$(el).hasClass('show')){
  298. $(el).show().addClass('show');
  299. self.addClass('current');
  300. }else{
  301. $(el).hide().removeClass('show');
  302. self.removeClass('current');
  303. }
  304. }
  305. })
  306. })
  307. $('.demo-comtop h1').on('tap', showGroupSel);
  308. $('.lin-mask').on('tap', showGroupSel).on('touchmove',function() {
  309. return false;
  310. });
  311. $('.lin-sel-group').on('touchmove',function() {
  312. // return false;
  313. });
  314. $('.lin-sel-group').on('tap', 'li', function(){
  315. updateLastTeamId($(this).attr("data-code"));
  316. setTitle($(this).attr("data-name"));
  317. showGroupSel(undefined, false);
  318. if(!$(this).hasClass('checked')){
  319. $(this).addClass('checked').siblings().removeClass('checked');
  320. }
  321. showTopMsgBar();
  322. getTeamPatientCount();
  323. refreshPage();
  324. });
  325. $topMsgBar.on('tap','.close-btn',function(){
  326. $topMsgBar.hide();
  327. });
  328. $groupLabelList.on('tap',"li.group-item",function() {
  329. openWebview("../../huanzhe/html/huanzhe-by-type.html",{
  330. type: self.type,
  331. accessData: {
  332. labelType: $(this).attr("data-type"),
  333. typeName: $(this).find(".item-label").text()
  334. },
  335. message: baseEnv.webview.message});
  336. })
  337. $groupLabelList.on('tap',"li.group-qytx",function() {
  338. openWebview("../../huanzhe/html/huanzhe-tijian.html",{
  339. type: self.type,
  340. accessData: {
  341. labelType: $(this).attr("data-type"),
  342. typeName: $(this).find(".item-label").text()
  343. },
  344. message: baseEnv.webview.message});
  345. })
  346. $searchbarInput.on('tap',function() {
  347. var searchPage = plus.webview.getWebviewById('searchhuanzhe');
  348. if(searchPage){
  349. mui.fire(searchPage, "initSearch", {
  350. msgForward: "",
  351. type: self.type
  352. })
  353. }
  354. if(self.type == 1){
  355. mui.openWindow({
  356. id: "searchhuanzhe2",
  357. url: "../../huanzhe/html/searchhuanzhe.html",
  358. extras: {
  359. msgForward: "",
  360. type: 1
  361. }
  362. })
  363. }else{
  364. mui.openWindow({
  365. id: "searchhuanzhe",
  366. url: "../../huanzhe/html/searchhuanzhe.html",
  367. extras: {
  368. msgForward: "",
  369. type: self.type
  370. }
  371. })
  372. }
  373. });
  374. $handleLink.on('click',function() {
  375. openWebview("../../tuandui/html/xuanzezhuanyijumin.html",{
  376. docCode: baseInfo.userAgent.uid,
  377. teamCode: lastTeamId,
  378. type: "dfp"
  379. });
  380. });
  381. $wfp.on('tap', function(){
  382. mui.openWindow({
  383. id: "zhuanyijumin",
  384. url: "../../search/html/zhuanyijumin.html",
  385. extras: {
  386. type: "分配",
  387. teamCode: lastTeamId,
  388. }
  389. });
  390. return;
  391. openWebview("../../tuandui/html/fp-xuanzejumin.html",{
  392. docCode: "",
  393. teamCode: lastTeamId,
  394. type: "dfp"
  395. });
  396. })
  397. $qbjm.on('tap', function(){
  398. var $team = $('.lin-sel-group li.checked');
  399. mui.openWindow("huanzhe.html", "quanbu-huanzhe", {
  400. extras: {
  401. type: 1,
  402. teamName: $team.attr('data-name')
  403. }
  404. })
  405. })
  406. /*刷新事件*/
  407. window.addEventListener("refresh", function refresh(e) {
  408. $('.lin-mask').hide();
  409. $('.lin-sel-group').hide();
  410. refreshPage();
  411. });
  412. window.addEventListener("refreshWfp", function refresh(e) {
  413. showTopMsgBar();
  414. });
  415. window.onscroll = function() {
  416. var scrollTop = document.body.scrollTop,
  417. $current = $('.patient-list.current',$patiList).eq(0),
  418. top = $current.length && $current.offset().top;
  419. if($current.length) {
  420. if(scrollTop >= top - 50) {
  421. $current.find(".patient-type").css({position: "fixed", top: 45, "z-index": 9999});
  422. } else {
  423. $current.find(".patient-type").css({position: "relative", top: "initial", "z-index": "initial"});
  424. }
  425. }
  426. }
  427. };
  428. // 页面业务处理流程开始
  429. new Promise(function(resolve, reject) {
  430. // TODO 临时放开
  431. //resolve(true);
  432. mui.plusReady(function() {
  433. // hrefhrefplus已经准备好,可以往下执行
  434. resolve(true);
  435. });
  436. }).then(function() {
  437. mui('.mui-scroll-wrapper').scroll()
  438. initScroller();
  439. // 获取基础环境信息
  440. return getBaseEnvPromise().then(function(env) {
  441. baseEnv = env;
  442. if(self.type == 1){
  443. $back.show();
  444. setTitle(self.teamName);
  445. }
  446. $('.mid-bar').toggle(self.type!=1);
  447. }).then(function() {
  448. // 获取登录基本信息
  449. baseInfo = getBaseInfo();
  450. lastTeamId = plus.storage.getItem("selectedTeamId");
  451. // 绑定页面事件
  452. bindEvents();
  453. initTeams();
  454. showTopMsgBar();
  455. initPatientGroupsList();
  456. if(baseEnv.webview.message){//“转发给”功能,需要返回按钮
  457. $(".mui-action-back").show();
  458. }
  459. })
  460. }).catch(function(e) {
  461. plus.nativeUI.closeWaiting();
  462. console && console.error(e);
  463. });