huanzhe.js 14 KB

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