xuanzejumin_more.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. // 基本信息(包括userAgent)
  2. var baseInfo = null,
  3. // 基础环境信息(包括当前webview)
  4. baseEnv = null;
  5. // 搜索输入框
  6. var $searchbarInput = $('.search-input'),
  7. // 搜索结果展示容器
  8. $searchtResult = $('#search_result'),
  9. // 搜索无结果时显示
  10. $noResultWrap = $('#no_result_wrap'),
  11. // 患者分组列表
  12. $patiList = $('#pati_list'),
  13. // 所选团队的团队名称显示
  14. $selectedTeamName = $('#selected_team_name'),
  15. //发送数量
  16. $sendCount = '';
  17. var lastTeamId,
  18. activeGroupType = "",
  19. typeId = 1, //记录排列的值
  20. sendCount = 0, //记录发送的数量
  21. sendPatiId = []; //记录发送的用户id列表
  22. var origin = '',//搜索来源位置
  23. article=null,//健康文章code
  24. articleTitle = "";//健康文章标题
  25. var timeOut,timeOut1;
  26. // 获取登录相关信息
  27. var getBaseInfo = function() {
  28. var userAgent = JSON.parse(plus.storage.getItem("userAgent"));
  29. var self = plus.webview.currentWebview();
  30. article = self.article;
  31. articleTitle = self.articleTitle;
  32. origin = self.origin;
  33. return {
  34. userAgent: userAgent,
  35. teamInfo: JSON.parse(plus.storage.getItem("teamInfo"))
  36. }
  37. },
  38. // 获取基础环境信息
  39. getBaseEnvPromise = function () {
  40. var env = {
  41. webview: plus&&plus.webview.currentWebview()
  42. };
  43. return Promise.resolve().then(function(res) {
  44. return env;
  45. });
  46. },
  47. updateLastTeamId = function(id) {
  48. lastTeamId = id;
  49. plus.storage.setItem("selectedTeamId",lastTeamId+"");
  50. },
  51. updateTypeId = function(id){
  52. typeId = id;
  53. plus.storage.setItem("selectedTypeId",typeId+"");
  54. }
  55. // 初始化选择团队
  56. initTeams = function (){
  57. // 判断缓存中的团队是否在团队列表中
  58. var isExist = _.some(baseInfo.teamInfo.data,function(t) {
  59. return lastTeamId == t.id
  60. });
  61. if(!isExist) {
  62. if(baseInfo.teamInfo.data.length>0){
  63. updateLastTeamId(baseInfo.teamInfo.data[0].id);
  64. }else{
  65. plus.nativeUI.toast("您还没有任何团队!");
  66. return;
  67. }
  68. }
  69. template.helper("setChecked", function(id, i) {
  70. if(lastTeamId && lastTeamId==id)
  71. return "checked";
  72. return "";
  73. })
  74. $('.lin-sel-group').html(template('teams_tmpl', baseInfo.teamInfo));
  75. if(!lastTeamId && baseInfo.teamInfo.data && baseInfo.teamInfo.data.length) {
  76. updateLastTeamId(baseInfo.teamInfo.data[0].id);
  77. $selectedTeamName.text(baseInfo.teamInfo.data[0].name);
  78. $('.lin-sel-group li').eq(0).addClass("checked");
  79. } else {
  80. var $selected = $('.lin-sel-group').find("li.checked");
  81. $selectedTeamName.text($selected.attr("data-name"));
  82. }
  83. if(typeId){
  84. $(".sel-group li[data-type="+typeId+"]").eq(0).addClass("checked").find("img").attr("src",'../images/checked_all.png');;
  85. }
  86. //切换底部信息footer
  87. var html = template("footer_tmpl", {origin:origin});
  88. $('#patiFooter').append(html);
  89. $sendCount = $("#sendCount");
  90. },
  91. //显示选中的分组
  92. showGroup = function(type) {
  93. if(type){
  94. activeGroupType = type;
  95. }
  96. },
  97. showGroupSel = function() {
  98. var isShow = isShow || $('.lin-sel-group:hidden').length != 0;
  99. $('.lin-mask').toggle(isShow);
  100. if($(".sel-group:hidden").length == 0 && isShow){
  101. $('.sel-group').toggle(!isShow);
  102. }
  103. $('.lin-sel-group').toggle(isShow);
  104. },
  105. showGroupType = function() {
  106. var isShow = isShow || $('.sel-group:hidden').length != 0;
  107. $('.lin-mask').toggle(isShow);
  108. if($(".lin-sel-group:hidden").length == 0 && isShow){
  109. $('.lin-sel-group').toggle(!isShow);
  110. }
  111. $('.sel-group').toggle(isShow);
  112. },
  113. hideMask = function(){
  114. var isShow = isShow || $('.lin-mask:hidden').length != 0,
  115. isTeamShow = $('.lin-sel-group:hidden').length != 0,
  116. isTypeShow = $('.sel-group:hidden').length != 0;
  117. $('.lin-mask').toggle(isShow);
  118. if(!isTeamShow){
  119. $('.lin-sel-group').toggle(isShow);
  120. }
  121. if(!isTypeShow){
  122. $('.sel-group').toggle(isShow);
  123. }
  124. },
  125. // 初始化画面患者分组列表
  126. initPatientGroupsList = function() {
  127. if(!lastTeamId){
  128. return;
  129. }
  130. getReqPromise("doctor/patient_label_info/label_patient_amount",{labelType: typeId, teamCode: lastTeamId})
  131. .then(function(res) {
  132. if(res.status == 200) {
  133. var data = _.filter(res.data,function(o) {
  134. //过滤团队标签中分组人数为0的数据
  135. if(typeId == 4 && o.amount == 0){
  136. return false;
  137. }
  138. return o.labelCode != 0 || (o.labelCode==0 && o.amount > 0);
  139. });
  140. if(data && data.length) {
  141. var html = template("pati_group_tmpl", {list: data});
  142. $patiList.empty().append(html);
  143. if(activeGroupType) {
  144. $patiList.find('.patient-list[data-group="'+activeGroupType+'"]').trigger("click");
  145. }
  146. $noResultWrap.hide();
  147. $searchtResult.show();
  148. } else {
  149. $searchtResult.hide();
  150. $noResultWrap.show();
  151. }
  152. }
  153. }).catch(function(e){ console && console.error(e) });;
  154. },
  155. refreshPage = function(){
  156. baseInfo = getBaseInfo();
  157. lastTypeId = plus.storage.getItem("selectedTypeId");
  158. initPatientGroupsList();
  159. },
  160. // 绑定页面事件
  161. bindEvents = function () {
  162. $patiList.on('click','.patient-list',function(e) {
  163. e.stopPropagation();
  164. var $this = $(this).find('.check-img'),
  165. value = $this.hasClass('checked'),
  166. groupAmount = $this.closest('.patient-list').attr('data-amount');
  167. if(value){
  168. $this.removeClass('checked');
  169. $this.attr('src','../images/unchecked.png');
  170. $this.closest('.patient-list').find(".n-list-checked").removeClass('checked');
  171. sendCount -= parseInt(groupAmount);
  172. }else{
  173. $this.addClass('checked');
  174. $this.attr('src','../images/checked_all.png');
  175. $this.closest('.patient-list').find(".n-list-checked").addClass('checked');
  176. sendCount = sendCount + parseInt(groupAmount);
  177. }
  178. $sendCount.text(sendCount);
  179. })
  180. function againLoad(){
  181. timeOut1=setTimeout(function(){
  182. plus.nativeUI.closeWaiting();
  183. dialog({
  184. content: '<div class="c-f16 c-323232">后台正在处理</div>',
  185. okValue: '继续等待',
  186. cancelValue: '返回首页',
  187. cancel: function () {
  188. backArticle();
  189. },
  190. ok: function() {
  191. plus.nativeUI.showWaiting();
  192. againLoad()
  193. }
  194. }).showModal();
  195. },30000)
  196. }
  197. function backArticle(){
  198. var view = plus.webview.getWebviewById("jiankangjiaoyu");
  199. if(view){
  200. mui.fire(view,"refresh");
  201. }
  202. view=plus.webview.getWebviewById("article");
  203. if(view){
  204. mui.fire(view,"refresh");
  205. }
  206. mui.back();
  207. }
  208. $('#sort').on('click', showGroupType);
  209. $('.lin-mask').on('touchstart',function(e){
  210. e.preventDefault();
  211. hideMask();
  212. })
  213. //排列选项
  214. $('.sel-group').on('click', 'li.group-item', function(){
  215. updateTypeId($(this).attr("data-type"));
  216. hideMask();
  217. if(!$(this).hasClass('checked')){
  218. $(this).addClass('checked');
  219. $(this).find('img').attr("src",'../images/checked_all.png');
  220. $(this).siblings().removeClass('checked');
  221. $(this).siblings().find('img').attr('src', '');
  222. }
  223. refreshPage();
  224. $sendCount.text(0);
  225. sendCount=0;
  226. });
  227. $('.demo-comtop h1').on('click', showGroupSel);
  228. $('.lin-mask').on('click', showGroupSel);
  229. $('.lin-sel-group').on('click', 'li', function(){
  230. updateLastTeamId($(this).attr("data-code"));
  231. $selectedTeamName.text($(this).attr("data-name"));
  232. showGroupSel(undefined, false);
  233. if(!$(this).hasClass('checked')){
  234. $(this).addClass('checked').siblings().removeClass('checked');
  235. }
  236. refreshPage();
  237. });
  238. $searchbarInput.on('click',function() {
  239. if(origin == 'jiaoyu'){
  240. openWebviewExtras("sousuojumin_more.html",{article:article,origin:origin,articleTitle:articleTitle});
  241. }
  242. });
  243. $("#patiFooter").on('click','#sendBtn',function(){
  244. var groupList=[];
  245. var patientList=[];
  246. var amount = 0;
  247. $(".patient-list").each(function(){
  248. var groupimg = $(this).find("img.check-img");
  249. if(groupimg.hasClass("checked")){
  250. var code = $.trim($(this).attr("data-group"));
  251. groupList.push(code);
  252. amount += parseInt($.trim($(this).attr('data-amount')));
  253. }
  254. })
  255. if(amount > 0){
  256. //健康教育模块
  257. if(origin == 'jiaoyu'){
  258. dialog({
  259. title: '<div><div class="c-f18 c-17b3ec c-t-left">发送给</div><div class="mt5 c-f14 c-t-left c-909090">'+amount+'人</div></div>',
  260. content: '<div><div class="c-f16 c-323232 c-t-left mb10">《'+articleTitle+'》</div><input id="messageInput" class="c-f14 pl10" placeholder="给居民留言..."/></div>',
  261. okValue: '立即发送',
  262. cancelValue: '我再看看',
  263. cancel: function () {
  264. return;
  265. },
  266. ok: function() {
  267. var params = {};
  268. params.code =article;
  269. params.patient=patientList.join(",");
  270. params.group=groupList.join(",");
  271. params.labelType = typeId;
  272. params.teamCode = lastTeamId;
  273. params.attachedContent = $.trim($('#messageInput').val());
  274. plus.nativeUI.showWaiting();
  275. sendPost("/doctor/jkEdu/article/doctorSendArticleToPatients",params,sendError,sendSuccess,'POST',2400000);
  276. timeOut=setTimeout(function(){
  277. plus.nativeUI.closeWaiting();
  278. dialog({
  279. content: '<div class="c-f16 c-323232">后台正在处理您的请求,结束后将自动跳转,您可先处理其他事宜</div>',
  280. okValue: '继续等待',
  281. cancelValue: '返回首页',
  282. cancel: function () {
  283. backArticle();
  284. },
  285. ok: function() {
  286. plus.nativeUI.showWaiting();
  287. againLoad();
  288. }
  289. }).showModal();
  290. },30000);
  291. function sendError(res){
  292. plus.nativeUI.closeWaiting();
  293. window.clearTimeout(timeOut);
  294. window.clearTimeout(timeOut1);
  295. if(res && res.msg){
  296. mui.toast(res.msg);
  297. }else{
  298. mui.toast("发送失败!");
  299. }
  300. };
  301. function sendSuccess(res){
  302. plus.nativeUI.closeWaiting();
  303. window.clearTimeout(timeOut);
  304. window.clearTimeout(timeOut1);
  305. if(res.status==200){
  306. plus.nativeUI.closeWaiting();
  307. mui.toast("发送成功!");
  308. var view = plus.webview.getWebviewById("jiankangjiaoyu");
  309. if(view){
  310. mui.fire(view,"refresh");
  311. }
  312. view=plus.webview.getWebviewById("article");
  313. if(view){
  314. mui.fire(view,"refresh");
  315. }
  316. mui.back();
  317. }else{
  318. sendError(res);
  319. }
  320. };
  321. }
  322. }).showModal()
  323. }
  324. }else{
  325. mui.toast("发送人数为0");
  326. }
  327. })
  328. /*刷新事件*/
  329. window.addEventListener("refresh", function refresh(e) {
  330. refreshPage();
  331. });
  332. window.onscroll = function() {
  333. var scrollTop = document.body.scrollTop,
  334. $current = $('.patient-list.current',$patiList).eq(0),
  335. top = $current.length && $current.offset().top;
  336. if($current.length) {
  337. if(scrollTop >= top - 50) {
  338. $current.find(".patient-type").css({position: "fixed", top: 45, "z-index": 2});
  339. } else {
  340. $current.find(".patient-type").css({position: "relative", top: "initial", "z-index": "initial"});
  341. }
  342. }
  343. }
  344. };
  345. // 页面业务处理流程开始
  346. new Promise(function(resolve, reject) {
  347. // TODO 临时放开
  348. //resolve(true);
  349. mui.plusReady(function() {
  350. // hrefhrefplus已经准备好,可以往下执行
  351. resolve(true);
  352. });
  353. }).then(function() {
  354. // 获取基础环境信息
  355. return getBaseEnvPromise().then(function(env) {
  356. baseEnv = env;
  357. }).then(function() {
  358. // 获取登录基本信息
  359. baseInfo = getBaseInfo();
  360. lastTeamId = plus.storage.getItem("selectedTeamId");
  361. // 绑定页面事件
  362. bindEvents();
  363. initTeams();
  364. initPatientGroupsList();
  365. });
  366. }).catch(function(e) {
  367. plus.nativeUI.closeWaiting();
  368. console && console.error(e);
  369. })