huanzhe.js 15 KB

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