article-list.js 16 KB

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