article-list.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  1. var firstLevelId,
  2. secondLevelId = '',
  3. selectedTab = 0, //顶部tab选中的index
  4. page = [],
  5. pageSize = 10,
  6. loaded = [],
  7. patient,
  8. patientName,
  9. teamCode,
  10. pCodes, //从慢病管理页面中跳转过来的多个居民的code
  11. referrer,
  12. isfromAdmin;
  13. var isAdmin; //判断是否是管理员
  14. var docInfo;
  15. var scrollers = [];
  16. mui.init();
  17. mui.plusReady(function(){
  18. var self = plus.webview.currentWebview();
  19. firstLevelId = self.firstLevelId;
  20. var userAgent = JSON.parse(plus.storage.getItem("userAgent"));
  21. if(userAgent.observer){
  22. isfromAdmin=true;
  23. }
  24. isAdmin = self.isAdmin;
  25. patient = self.patient;
  26. patientName = self.patientName;
  27. teamCode = self.teamCode;
  28. pCodes = self.pCodes;
  29. referrer = self.referrer;
  30. if(!isAdmin){
  31. // $(".xuanfu").show();
  32. }
  33. docInfo = JSON.parse(plus.storage.getItem("docInfo"));
  34. getSecondLevelCategory();
  35. bindEvents();
  36. });
  37. function getSecondLevelCategory(){
  38. var url = "/third/jkEdu/Article/getCategoryList",
  39. params = {
  40. categoryLevel: 2,
  41. firstlevelId: firstLevelId
  42. };
  43. sendGet(url, params, null, function(res){
  44. if(res.status == 200){
  45. var html = template("tab-tmp", {list: res.data});
  46. // $("#tabPanel").empty().append(html);
  47. var controlPanelHtml = template("control-panel-tmp", {list: res.data});
  48. // $(".mui-slider-group").empty().append(controlPanelHtml);
  49. $(".mui-content").append(html + controlPanelHtml);
  50. var gallery = mui('.mui-slider');
  51. gallery.slider();
  52. initTabScroller();
  53. initScroller();
  54. // secondLevelId = res.data[0].categoryid;
  55. getArticleList(true);
  56. loaded[0] = "true";
  57. document.querySelector('.mui-slider').addEventListener('slide', function(event) {
  58. selectedTab = event.detail.slideNumber;
  59. var $item = $("#tabPanel a").eq(selectedTab);
  60. secondLevelId = $item.attr("data-id");
  61. if(loaded[selectedTab] == "false"){
  62. getArticleList(true);
  63. loaded[selectedTab] = "true";
  64. }
  65. });
  66. }else{
  67. mui.toast(res.msg);
  68. }
  69. },true);
  70. }
  71. function getArticleList(isInit){
  72. if(isInit){
  73. page[selectedTab] = 0;
  74. }
  75. var url = "/doctor/jkEdu/article/PC/queryArticlePcList",
  76. params = {
  77. firstLevelCategoryId: firstLevelId,
  78. secondLevelCategoryId: secondLevelId,
  79. currentUserRole: docInfo.hospital,
  80. currentUserRoleLevel: 4,
  81. iDisplayStart: page[selectedTab] * pageSize,
  82. iDisplayLength: pageSize,
  83. isAuthentication: 1, //已认证过的文章
  84. roleType: 1 //1、普通医生,2、管理员
  85. };
  86. if(patient){
  87. params.patient = patient;
  88. }
  89. if(isAdmin){
  90. var selectedRole = JSON.parse(plus.storage.getItem("selectedRole"));
  91. params.currentUserRole = selectedRole.code;
  92. params.currentUserRoleLevel = selectedRole.level;
  93. params.roleType = 2;
  94. }
  95. sendGet(url, params, null, function(res){
  96. if(res.status == 200){
  97. if(isInit){
  98. if(res.data.aaData.length == 0){
  99. $("#item"+(selectedTab)+" .mui-table-view").hide();
  100. $("#item"+(selectedTab)+" .no-result").show();
  101. }else{
  102. loaded[selectedTab] = "true";
  103. var html = template("articleimgLi", {list: res.data.aaData});
  104. $("#item"+(selectedTab)+" .mui-table-view").empty().append(html);
  105. }
  106. }else{
  107. var html = template("articleimgLi", {list: res.data.aaData});
  108. $("#item"+(selectedTab)+" .mui-table-view").append(html);
  109. }
  110. if(res.data.aaData.length < pageSize){
  111. // scrollers[selectedTab].disablePullupToRefresh();
  112. scrollers[selectedTab].endPullupToRefresh(true);
  113. }else{
  114. page[selectedTab] ++ ;
  115. scrollers[selectedTab].endPullupToRefresh();
  116. // scrollers[selectedTab].enablePullupToRefresh();
  117. }
  118. }else{
  119. mui.toast(res.msg);
  120. }
  121. }, true);
  122. }
  123. /*
  124. * 收藏文章
  125. */
  126. function collectionArticle(code,$this){
  127. plus.nativeUI.showWaiting();
  128. var params = {};
  129. params.articleId = code;
  130. params.userType = 1; //1医生,2居民
  131. sendPost("/third/jkEdu/Article/saveArticleCollection",params,function(res){
  132. plus.nativeUI.closeWaiting();
  133. if(res.msg){
  134. plus.nativeUI.toast(res.msg);
  135. }else{
  136. plus.nativeUI.toast("收藏失败!");
  137. }
  138. },function(res){
  139. plus.nativeUI.closeWaiting();
  140. if(res.status==200){
  141. $this.attr("data-status", 1);
  142. $this.find("img").attr("src", "../images/shoucang_pre.png");
  143. var span = $this.find("span");
  144. var collectNum = parseInt(span.html());
  145. span.html(collectNum+1);
  146. plus.nativeUI.toast("收藏成功");
  147. }else{
  148. if(res.msg){
  149. plus.nativeUI.toast(res.msg);
  150. }else{
  151. plus.nativeUI.toast("收藏失败!");
  152. }
  153. }
  154. })
  155. }
  156. /*
  157. * 取消收藏文章
  158. */
  159. function unCollectionArticle(code,$this){
  160. plus.nativeUI.showWaiting();
  161. var params = {};
  162. params.articleId=code;
  163. params.userType = 1; //1医生,2居民
  164. sendPost("/third/jkEdu/Article/cancelArticleCollection",params,function(res){
  165. plus.nativeUI.closeWaiting();
  166. if(res.msg){
  167. plus.nativeUI.toast(res.msg);
  168. }else{
  169. plus.nativeUI.toast("取消收藏失败!");
  170. }
  171. },function(res){
  172. plus.nativeUI.closeWaiting();
  173. if(res.status==200){
  174. $this.attr("data-status", 0);
  175. $this.find("img").attr("src", "../images/shoucang_button.png");
  176. var span = $this.find("span");
  177. var collectNum = parseInt(span.html());
  178. span.html(collectNum-1);
  179. plus.nativeUI.toast("取消收藏成功");
  180. }else{
  181. if(res.msg){
  182. plus.nativeUI.toast(res.msg);
  183. }else{
  184. plus.nativeUI.toast("取消收藏失败!");
  185. }
  186. }
  187. })
  188. }
  189. //弹框提示是否发送给居民
  190. function showDialog(article,title,patientName) {
  191. dialog({
  192. title: '<div><div class="c-f18 c-17b3ec c-t-left">发送给</div><div class="mt5 c-f14 c-t-left c-909090">'+patientName+'</div></div>',
  193. content: '<div><div class="c-f16 c-323232 c-t-left mb10">《'+title+'》</div><input id="messageInput" class="c-f14 pl10" placeholder="给居民留言..."/></div>',
  194. okValue: '立即发送',
  195. cancelValue: '我再看看',
  196. cancel: function () {
  197. return;
  198. },
  199. ok: function() {
  200. send(article);
  201. }
  202. }).showModal();
  203. }
  204. //发送文章给患者
  205. function send(article){
  206. var url = "/doctor/jkEdu/article/doctorSendArticleToPatients",
  207. params = {
  208. articleId: article,
  209. patientCode: patient,
  210. patient: patient,
  211. // teamCode: teamCode,
  212. leaveWords: $.trim($('#messageInput').val())
  213. };
  214. if(pCodes){
  215. params.patient = pCodes.join(",");
  216. }
  217. var docInfo = JSON.parse(plus.storage.getItem('docInfo'));
  218. params.currentUserRole = docInfo.hospital;
  219. params.currentUserRoleLevel = 4;
  220. plus.nativeUI.showWaiting();
  221. sendPost(url, params, null, function(res){
  222. if(res.status == 10000){
  223. mui.toast("发送成功!");
  224. var $this = $(".share[data-code="+article+"]");
  225. if(!pCodes){
  226. $this.after('<div class="sent-flag"><span class="c-fff c-f14 ml10">已发送</span></div>');
  227. }
  228. var num = $this.find(".send_count").text();
  229. $this.find(".send_count").text(parseInt(num)+1);
  230. if(referrer == "manbing"){
  231. var self = plus.webview.currentWebview(),
  232. selfId = self.id;
  233. backToManbingPage(self, selfId);
  234. }
  235. }else{
  236. if(res.msg){
  237. mui.toast(res.msg);
  238. }else{
  239. mui.toast("发送失败!");
  240. }
  241. }
  242. plus.nativeUI.closeWaiting();
  243. });
  244. }
  245. function bindEvents(){
  246. $("body").on('tap', '#tabPanel a', function(){
  247. if($(this).hasClass("mui-active")){
  248. return false;
  249. }
  250. selectedTab = $(this).index();
  251. secondLevelId = $(this).attr("data-id");
  252. if(loaded[selectedTab] == "false"){
  253. getArticleList(true);
  254. loaded[selectedTab] = "true";
  255. }
  256. });
  257. $(".xuanfu").on('click', function(){
  258. $(this).hide();
  259. $(".div-dialog-content").addClass("div-dialog-content-active");
  260. // $(".div-dialog-content").show();
  261. $(".modal-overlay").addClass("modal-overlay-visible");
  262. });
  263. //点击遮罩事件
  264. $(".modal-overlay").on("click", function(){
  265. $(".modal-overlay").removeClass("modal-overlay-visible");
  266. $(".div-dialog-content").removeClass("div-dialog-content-active");
  267. $(".xuanfu").show();
  268. });
  269. $(".my-article-icon").on('click', function(){
  270. $(".modal-overlay").removeClass("modal-overlay-visible");
  271. $(".div-dialog-content").removeClass("div-dialog-content-active");
  272. $(".xuanfu").show();
  273. openWebview("myArticle.html", {
  274. patient: patient,
  275. patientName: patientName,
  276. pCodes: pCodes,
  277. referrer: referrer
  278. });
  279. });
  280. $(".new-article-icon").on('click', function(){
  281. $(".modal-overlay").removeClass("modal-overlay-visible");
  282. $(".div-dialog-content").removeClass("div-dialog-content-active");
  283. $(".xuanfu").show();
  284. openWebview("addArticle.html", {hospitalName:docInfo.hospitalName,currentUserRole:docInfo.hospital});
  285. });
  286. $(".cancel-icon").on('click', function(){
  287. $(".modal-overlay").removeClass("modal-overlay-visible");
  288. $(".div-dialog-content").removeClass("div-dialog-content-active");
  289. $(".xuanfu").show();
  290. })
  291. $("body").on('tap', ".article-info", function(){
  292. var code = $(this).attr("data-article-code");
  293. var title = $(this).attr('data-title');
  294. if(isAdmin){
  295. openWebviewExtras("../../home/html/jianjiaotuisong-xiangqing.html",{articleId:code});
  296. }else{
  297. openWebview("article-info.html", {
  298. articleId: code,
  299. patient: patient,
  300. patientName: patientName,
  301. pCodes: pCodes,
  302. showHandleBar: true,
  303. referrer: referrer
  304. });
  305. }
  306. return false;
  307. }).on('tap','div.collect', function(){
  308. if(isfromAdmin){
  309. mui.toast("观察者模式无法收藏健康文章");
  310. }else{
  311. var $this = $(this);
  312. var status = $this.attr("data-status");
  313. var code = $this.attr("data-code");
  314. if(status == 0){
  315. collectionArticle(code,$this);
  316. }else{
  317. unCollectionArticle(code,$this);
  318. }
  319. }
  320. }).on('tap','div.share', function(){
  321. if(isfromAdmin){
  322. mui.toast("观察者模式无法分享健康文章");
  323. return false;
  324. }
  325. var $this = $(this);
  326. var code = $this.attr("data-code");
  327. var title = $this.attr("data-title");
  328. if(isAdmin){
  329. openWebviewExtras("../../home/html/tuisong_duixiang.html",{articleId:code});
  330. }else{
  331. if(!patient){
  332. if(isfromAdmin){
  333. mui.toast("观察者模式无法发送健康文章");
  334. }else{
  335. if(pCodes){
  336. dialog({
  337. title: '<div><div class="c-f18 c-17b3ec c-t-left">发送给</div><div class="mt5 c-f14 c-t-left c-909090">'+pCodes.length+'人</div></div>',
  338. content: '<div><div class="c-f16 c-323232 c-t-left mb10">《'+title+'》</div><input id="messageInput" class="c-f14 pl10" placeholder="给居民留言..."/></div>',
  339. okValue: '立即发送',
  340. cancelValue: '我再看看',
  341. cancel: function () {
  342. return;
  343. },
  344. ok: function() {
  345. send(code);
  346. }
  347. }).showModal();
  348. return false;
  349. }else{
  350. openWebview("xuanzejumin_more.html", {
  351. article: code,
  352. articleTitle: title,
  353. origin: 'jiaoyu'
  354. });
  355. }
  356. }
  357. }else{
  358. showDialog(code,title,patientName);
  359. }
  360. }
  361. });
  362. template.helper("setContent", function(str){
  363. var reg=/<[^<>]+>/g;
  364. str = str.replace(reg, '');
  365. return str;
  366. });
  367. template.helper("getArticleImage", function(str){
  368. if(str){
  369. if(str.indexOf("../") > -1){
  370. return ""; //原福州代码中返回的相对路径
  371. }
  372. var url = getImgUrl(str);
  373. return "<img src='"+url+"'>";
  374. }
  375. return "";
  376. });
  377. template.helper("formatDate", function(str){
  378. if(str){
  379. return str.substr(0,19)
  380. }else{
  381. return "";
  382. }
  383. });
  384. window.addEventListener('reload', function(){
  385. getArticleList(true);
  386. })
  387. }
  388. function initTabScroller(){
  389. //阻尼系数
  390. var deceleration = mui.os.ios?0.003:0.0009;
  391. mui('.mui-scroll-wrapper').scroll({
  392. bounce: false,
  393. indicators: true, //是否显示滚动条
  394. deceleration:deceleration
  395. });
  396. }
  397. function initScroller(){
  398. if(scrollers.length == 0) {
  399. $.each(document.querySelectorAll('.mui-slider-group .mui-scroll-wrapper'), function(index, pullRefreshEl) {
  400. page.push(0);
  401. loaded.push("false");
  402. var pullRefresh = mui(pullRefreshEl).pullRefresh({
  403. down: {
  404. callback: function(){
  405. getArticleList(true);
  406. this.endPulldownToRefresh();
  407. }
  408. },
  409. up: {
  410. callback: function(){
  411. var self = this;
  412. setTimeout(function(){
  413. getArticleList(false);
  414. // self.endPullupToRefresh();
  415. }, 500);
  416. }
  417. }
  418. });
  419. scrollers.push(pullRefresh);
  420. })
  421. }
  422. }
  423. function backToManbingPage(wv, selfId){
  424. var targetId = "zhongdiangenzong";
  425. if(wv.id == targetId){
  426. setTimeout(function(){
  427. plus.webview.getWebviewById(selfId).close();
  428. }, 300);
  429. }else{
  430. var opener = wv.opener();
  431. if(wv.id != selfId){
  432. wv.close();
  433. }
  434. backToManbingPage(opener, selfId);
  435. }
  436. }
  437. //设置页面监听
  438. window.addEventListener("refresh", function(){
  439. getArticleList(true);
  440. });