huanzhe-by-type.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. // TODO 临时构造plus对象,使得能够在浏览器中进行调试
  2. //var plus = null;
  3. // TODO 列表数据示例
  4. //var groupData = {"msg":"患者列表查询成功!","data":[{labelCode:"mbrq",labelName:"慢病人群",isSystem:"1",amount:45},{labelCode:"65sysrq",labelName:"65岁以上人群",isSystem:"1",amount:32},{labelCode:"ptrq",labelName:"普通人群",isSystem:"1",amount:3}],"status":200};
  5. //var patientData = {"msg":"患者列表查询成功!","data":[{"qyrq":"2016-09-18","code":"82c28c0634aa42a797f9e2eecebc79b8","disease":0,"sex":1,"idcard":"352602197602291394","name":"张西亮","signType":"2","diseases":"","partAmount":0,"age":40},{"qyrq":"2016-08-04","code":"tudouP2016082901","disease":1,"recordAmount":0,"sex":1,"idcard":"11010119900101231X","name":"谢小平","photo":"","signType":"1","diseases":[{"diseaseName":"高血压","disease":"1","signType":"1","del":"1"}],"age":26,"diseaseLevel":0}],"status":200};
  6. // 基本信息(包括userAgent)
  7. var baseInfo = null,
  8. // 基础环境信息(包括当前webview)
  9. baseEnv = null;
  10. var self;
  11. var lastTeamId;
  12. // 搜索框
  13. var $searchbar = $('.searchbar'),
  14. // 搜索输入框
  15. $searchbarInput = $('.searchbar .search-input'),
  16. // 搜索取消按钮
  17. $searchCancelBtn = $('.searchbar-cancel'),
  18. // 搜索框下面悬浮的搜索提示
  19. $searchSuggest = $('#search_suggest_text'),
  20. // 搜索结果展示容器
  21. $searchtResult = $('#search_result'),
  22. // 搜索无结果时显示
  23. $noResultWrap = $('#no_result_wrap'),
  24. // 患者分组列表
  25. $patiList = $('#pati_list'),
  26. $selectedTypeName = $('#selected_type_name'),
  27. $shezhiBtn = $("#shezhi_btn");
  28. // 获取登录相关信息
  29. var getBaseInfo = function() {
  30. // 登录的相关信息
  31. var userAgent = JSON.parse(plus.storage.getItem("userAgent"))
  32. return {
  33. userAgent: userAgent,
  34. teamInfo: JSON.parse(plus.storage.getItem("teamInfo")),
  35. accessData: baseEnv.webview.accessData
  36. }
  37. },
  38. // 获取基础环境信息
  39. getBaseEnvPromise = function () {
  40. self = plus.webview.currentWebview();
  41. var env = {
  42. webview: plus&&plus.webview.currentWebview()
  43. };
  44. return Promise.resolve().then(function(res) {
  45. return env;
  46. });
  47. },
  48. // 初始化画面患者分组列表
  49. initPatientGroupsList = function() {
  50. var url = self.type == 1 ? "/doctor/patient_label_info/label_team_amount" : "doctor/patient_label_info/label_patient_amount";
  51. getReqPromise(url,{labelType: baseInfo.accessData.labelType, teamCode: lastTeamId})
  52. .then(function(res) {
  53. if(res.status == 200) {
  54. var rsData = res.data;
  55. if(baseInfo.accessData.labelType == "9"){
  56. rsData = res.data.result;
  57. }
  58. var data = _.filter(rsData,function(o) {
  59. return o.labelCode != 0 || (o.labelCode==0 && o.amount > 0);
  60. });
  61. if(data && data.length) {
  62. var html = template("pati_group_tmpl", {list: data});
  63. $patiList.empty().append(html);
  64. $noResultWrap.hide();
  65. $searchtResult.show();
  66. } else {
  67. $searchtResult.hide();
  68. $noResultWrap.show();
  69. }
  70. }
  71. }).catch(function(e){ console && console.error(e); plus.nativeUI.closeWaiting(); });
  72. },
  73. showLoadMore = function($el) {
  74. var amount = $el.attr("data-amount"),
  75. loaded = $el.find('ul.n-list li').length,
  76. $loadMore = $el.find('.load-more');
  77. if(amount>loaded) {
  78. $loadMore.show();
  79. } else {
  80. $loadMore.hide();
  81. }
  82. },
  83. initPatientListByGroup = function(code) {
  84. var url = self.type == 1 ? "doctor/patient_label_info/team_patient" : "doctor/patient_label_info/patients_by_label";
  85. plus.nativeUI.showWaiting();
  86. var $group = $patiList.find('.patient-list[data-group="'+code+'"]');
  87. getReqPromise(url, {labelType: baseInfo.accessData.labelType, labelCode: code, teamCode: lastTeamId, page: 1, pagesize: 50})
  88. .then(function(res) {
  89. if(res.status == 200) {
  90. var data = res.data;
  91. if(baseInfo.accessData.labelType == "9"){
  92. data = res.data.result;
  93. }
  94. var html = template("pati_list_tmpl", {list: _.map(data,function(o) {
  95. o.jsonStr = JSON.stringify(o);
  96. return o;
  97. })});
  98. $group.find('ul.n-list').empty().append(html);
  99. showLoadMore($group);
  100. }
  101. plus.nativeUI.closeWaiting();
  102. }).catch(function(e){ console && console.error(e); plus.nativeUI.closeWaiting(); });
  103. },
  104. togglePatientListShow = function($el) {
  105. var isOpen = $el.hasClass("current"),
  106. $list = $el.find('ul.n-list'),
  107. $siblings = $el.siblings();
  108. if(isOpen) {
  109. $el.removeClass("current");
  110. $list.hide();
  111. $el.find('.load-more').hide();
  112. } else {
  113. $el.addClass("current");
  114. showLoadMore($el);
  115. $siblings.removeClass('current').find("ul.n-list").hide();
  116. $siblings.find('.load-more').hide();
  117. $list.show();
  118. }
  119. return isOpen;
  120. },
  121. showSheZhi = function() {
  122. if(baseInfo.accessData.labelType == 4) {
  123. $shezhiBtn.show();
  124. } else {
  125. $shezhiBtn.hide();
  126. }
  127. },
  128. refreshPage = function(){
  129. baseInfo = getBaseInfo();
  130. lastTeamId = plus.storage.getItem("selectedTeamId");
  131. $selectedTypeName.text(baseInfo.accessData.typeName);
  132. showSheZhi();
  133. initPatientGroupsList();
  134. },
  135. // 绑定页面事件
  136. bindEvents = function () {
  137. $patiList.on('click','.load-more',function() {
  138. plus.nativeUI.showWaiting();
  139. var url = self.type == 1 ? "doctor/patient_label_info/team_patient" : "doctor/patient_label_info/patients_by_label";
  140. var $wrap = $(this).closest(".patient-list"),
  141. code = $wrap.attr("data-group"),
  142. page = parseInt($wrap.attr("data-page"));
  143. getReqPromise(url,{labelType: baseInfo.accessData.labelType,labelCode: code, teamCode: lastTeamId, page: page + 1, pagesize: 50})
  144. .then(function(res) {
  145. if(res.status == 200) {
  146. var rsData = res.data;
  147. if(baseInfo.accessData.labelType == "9"){
  148. rsData = res.data.result;
  149. }
  150. var html = template("pati_list_tmpl", {list: _.map(rsData,function(o) {
  151. o.jsonStr = JSON.stringify(o);
  152. return o;
  153. })});
  154. $wrap.find('ul.n-list').append(html);
  155. $wrap.attr("data-page",page+1);
  156. showLoadMore($wrap);
  157. }
  158. plus.nativeUI.closeWaiting();
  159. }).catch(function(e){ console && console.error(e) });
  160. return false;
  161. }).on('click','.patient-list',function() {
  162. var code = $.trim($(this).attr("data-group")),
  163. isOpen = togglePatientListShow($(this)),
  164. isEmpty = !$(this).find('ul.n-list li').length;
  165. $patiList.find(".patient-type").css({position: "relative", top: "initial", "z-index": "initial"});
  166. code && !isOpen && isEmpty && initPatientListByGroup(code);
  167. }).on('click','li[data-patient-code]',function() {
  168. var patiInfo = $(this).attr("data-json");
  169. if(baseEnv.webview.message) {
  170. var info = JSON.parse(patiInfo);
  171. openWebview("../../message/html/p2p.html",{otherCode: info.code,otherName: info.name,otherPhoto: info.photo,otherSex: info.sex});
  172. } else {
  173. var overdue = "";
  174. var patiCode = $(this).attr("data-patient-code");
  175. if(baseInfo.accessData.labelType == "9"){
  176. overdue = 1;
  177. }
  178. openWebview("../../huanzhe/html/huanzhexinxi.html",{teamCode: lastTeamId, patiCode:patiCode, overdue : overdue});
  179. }
  180. return false;
  181. })
  182. $searchbarInput.on('click',function() {
  183. mui.openWindow({
  184. id:"searchhuanzhe",
  185. url: '../../huanzhe/html/searchhuanzhe.html',
  186. extras: {
  187. message: baseEnv.webview.message,
  188. type: self.type,
  189. labelType:baseInfo.accessData.labelType
  190. }
  191. });
  192. });
  193. $shezhiBtn.on('click',function() {
  194. openWebview("../../huanzhe/html/biaoqianguanli.html",{
  195. teamCode: plus.storage.getItem("selectedTeamId")
  196. });
  197. });
  198. /*刷新事件*/
  199. window.addEventListener("refresh", function refresh(e) {
  200. refreshPage();
  201. });
  202. // window.onscroll = function() {
  203. // var scrollTop = document.body.scrollTop,
  204. // $current = $('.patient-list.current',$patiList).eq(0),
  205. // top = $current.length && $current.offset().top;
  206. // if($current.length) {
  207. // if(scrollTop >= top - 50) {
  208. // $current.find(".patient-type").css({position: "fixed", top: 45, "z-index": 9999});
  209. // } else {
  210. // $current.find(".patient-type").css({position: "relative", top: "initial", "z-index": "initial"});
  211. // }
  212. // }
  213. // }
  214. /*提醒续签*/
  215. $("#remindRenew").on("tap", function(){
  216. var remindInfo = window.localStorage.getItem("remindXQ");
  217. //remindInfo = {date: '2017-05-07', remind: 1}
  218. var info = remindInfo && JSON.parse(remindInfo);
  219. var date = new Date(),
  220. dateStr = date.format("yyyy-MM-dd");
  221. if(remindInfo && (info.date == dateStr) && (info.remind == 1)){
  222. mui.toast("对不起,您今天已经全部提醒过,无法再次全部提醒");
  223. return;
  224. }
  225. var url = "/doctor/sign/sendRenewToPatients";
  226. dialog({
  227. content: "是否向所有去年签约到期居民发送签约提醒?(如绑定手机号则短信提醒,如绑定微信则微信提醒)",
  228. okValue: "立即提醒",
  229. ok: function(){
  230. plus.nativeUI.showWaiting();
  231. sendPost(url, {}, null, function(res){
  232. if(res.status == 200){
  233. if(res.data == 0){
  234. mui.toast(res.msg);
  235. }else{
  236. mui.toast("已向所有待续签居民发出续签提醒");
  237. }
  238. var obj = {date: dateStr, remind: 1};
  239. localStorage.setItem("remindXQ", JSON.stringify(obj));
  240. // $(".header-link").hide();
  241. }else{
  242. mui.toast(res.msg);
  243. }
  244. plus.nativeUI.closeWaiting();
  245. }, "post", "", true);
  246. },
  247. cancelValue: "不了,谢谢",
  248. cancel: function(){}
  249. }).showModal();
  250. });
  251. };
  252. // 页面业务处理流程开始
  253. new Promise(function(resolve, reject) {
  254. // TODO 临时放开
  255. //resolve(true);
  256. mui.plusReady(function() {
  257. // hrefhrefplus已经准备好,可以往下执行
  258. var oldBack = mui.back;
  259. mui.back = function() {
  260. var preWebview = plus.webview.currentWebview().opener();
  261. mui.fire(preWebview,"refresh");
  262. oldBack();
  263. }
  264. resolve(true);
  265. });
  266. }).then(function() {
  267. // 获取基础环境信息
  268. return getBaseEnvPromise().then(function(env) {
  269. baseEnv = env;
  270. }).then(function() {
  271. // 获取登录基本信息
  272. baseInfo = getBaseInfo();
  273. lastTeamId = plus.storage.getItem("selectedTeamId");
  274. $selectedTypeName.text(baseInfo.accessData.typeName);
  275. //如果是签约过期居民,显示“提醒续签”按钮
  276. if(baseInfo.accessData.labelType == "9"){
  277. $("#remindRenew").show();
  278. }else{
  279. $("#remindRenew").hide();
  280. }
  281. showSheZhi();
  282. // 绑定页面事件
  283. bindEvents();
  284. initPatientGroupsList();
  285. })
  286. }).catch(function(e) {
  287. plus.nativeUI.closeWaiting();
  288. console && console.error(e);
  289. });