jiankangjiaoyu.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. // 基本信息(包括userAgent)
  2. var baseInfo = null,
  3. //滚动条
  4. scroller1=null,
  5. // 基础环境信息(包括当前webview)
  6. baseEnv = null,
  7. patient = null,
  8. patientName ="";
  9. //搜索输入框
  10. var $searchInput = $(".search-input"),
  11. //文章列表
  12. $articleList = $(".mui-table-view");
  13. var self;
  14. var mscrolls = [];
  15. var pagesize = 10;
  16. // 获取登录相关信息
  17. var getBaseInfo = function() {
  18. // 登录的相关信息
  19. var userAgent = JSON.parse(plus.storage.getItem("userAgent"))
  20. return {
  21. userAgent: userAgent
  22. }
  23. },
  24. // 获取基础环境信息
  25. getBaseEnvPromise = function () {
  26. var env = {
  27. webview: plus&&plus.webview.currentWebview()
  28. };
  29. var self = plus.webview.currentWebview();
  30. mui.back = function(){
  31. var opener = self.opener();
  32. if(opener.id=='p2dzixun'){
  33. mui.fire(opener, 'update');
  34. } else if(opener.id == 'fuwujilu') {
  35. mui.fire(opener, 'refresh');
  36. }
  37. self.close();
  38. }
  39. return Promise.resolve().then(function(res) {
  40. return env;
  41. });
  42. },
  43. refreshPage = function(){
  44. baseInfo = getBaseInfo();
  45. var index = $('.mui-control-item.mui-active').index();
  46. var view = $('.mui-table-view').eq(index);
  47. view.empty();
  48. var scroll = mscrolls[index];
  49. if(scroll) {
  50. scroll.pulldownLoading();
  51. }
  52. },
  53. collectionArticle=function(code,$this){
  54. plus.nativeUI.showWaiting();
  55. var params = {};
  56. params.article=code;
  57. sendPost("/doctor/health/edu/collectionArticle",params,function(res){
  58. plus.nativeUI.closeWaiting();
  59. if(res.msg){
  60. plus.nativeUI.toast(res.msg);
  61. }else{
  62. plus.nativeUI.toast("收藏失败!");
  63. }
  64. },function(res){
  65. plus.nativeUI.closeWaiting();
  66. if(res.status==200){
  67. $this.attr("data-status", 1);
  68. $this.find("img").attr("src", "../images/shoucang_pre.png");
  69. var span = $this.find("span");
  70. var collectNum = parseInt(span.html());
  71. span.html(collectNum+1);
  72. plus.nativeUI.toast("收藏成功");
  73. }else{
  74. if(res.msg){
  75. plus.nativeUI.toast(res.msg);
  76. }else{
  77. plus.nativeUI.toast("收藏失败!");
  78. }
  79. }
  80. })
  81. },
  82. unCollectionArticle=function(code,$this){
  83. plus.nativeUI.showWaiting();
  84. var params = {};
  85. params.article=code;
  86. sendPost("/doctor/health/edu/uncollectionArticle",params,function(res){
  87. plus.nativeUI.closeWaiting();
  88. if(res.msg){
  89. plus.nativeUI.toast(res.msg);
  90. }else{
  91. plus.nativeUI.toast("取消收藏失败!");
  92. }
  93. },function(res){
  94. plus.nativeUI.closeWaiting();
  95. if(res.status==200){
  96. $this.attr("data-status", 0);
  97. $this.find("img").attr("src", "../images/shoucang_button.png");
  98. var span = $this.find("span");
  99. var collectNum = parseInt(span.html());
  100. span.html(collectNum-1);
  101. plus.nativeUI.toast("取消收藏成功");
  102. }else{
  103. if(res.msg){
  104. plus.nativeUI.toast(res.msg);
  105. }else{
  106. plus.nativeUI.toast("取消收藏失败!");
  107. }
  108. }
  109. })
  110. },
  111. //事件绑定
  112. bindEvents = function(){
  113. $(".header-link").on("click",'.shoucang-btn',function(){
  114. openWebviewExtras("my_store.html",{patient:patient,patientName:self.patientName});
  115. })
  116. .on("click",'.search-btn',function(){
  117. openWebviewExtras("search_article.html",{type:0,patient:patient,patientName:self.patientName});
  118. })
  119. $articleList.on('tap','li .article-info',function() {
  120. var code = $(this).attr("data-article-code");
  121. var title = $(this).attr('data-title');
  122. openWebviewExtras("article.html",{article:code,patient:patient,patientName:self.patientName});
  123. return false;
  124. }).on('tap','div.collect', function(){
  125. var $this = $(this);
  126. var status = $this.attr("data-status");
  127. var code = $this.attr("data-code");
  128. if(status == 0){
  129. collectionArticle(code,$this);
  130. }else{
  131. unCollectionArticle(code,$this);
  132. }
  133. }).on('tap','div.share', function(){
  134. var $this = $(this);
  135. var code = $this.attr("data-code");
  136. var title = $this.attr("data-title");
  137. if(!patient){
  138. openWebviewExtras("xuanzejumin_more.html",{article:code,origin:'jiaoyu',articleTitle:title,patientName:self.patientName});
  139. }else{
  140. showDialog(code,title,patientName);
  141. }
  142. });
  143. $('.mui-control-item').on('tap',function() {
  144. var index = $(this).index();
  145. var scroll = mscrolls[index];
  146. var view = $('.mui-table-view').eq(index);
  147. var isEmpty = view.find('li').length==0;
  148. if(scroll && isEmpty) {
  149. scroll.pullupLoading();
  150. }
  151. });
  152. $('#recordsLink').on('tap',function() {
  153. // openWebviewExtras("fasongjilu.html");
  154. openWebviewExtras("myArticle.html");
  155. });
  156. document.querySelector('.mui-slider').addEventListener('slide', function(event) {
  157. $('.mui-control-item').eq(event.detail.slideNumber).trigger('tap');
  158. });
  159. /*刷新事件*/
  160. window.addEventListener("refresh", function refresh(e) {
  161. refreshPage();
  162. });
  163. },
  164. loadListPromise = function(wheaType,page) {
  165. return new Promise(function(resolve, reject) {
  166. sendPost("/doctor/health/edu/list",{
  167. patient: patient || "",
  168. wheaType: wheaType,
  169. page: page,
  170. pagesize: pagesize
  171. },function(res){
  172. if(res.msg){
  173. mui.toast(res.msg);
  174. }else{
  175. mui.toast("加载失败!");
  176. }
  177. },function(res){
  178. if(res.status==200){
  179. resolve(res.list)
  180. }else{
  181. if(res.msg){
  182. mui.toast(res.msg);
  183. }else{
  184. mui.toast("加载失败!");
  185. }
  186. }
  187. })
  188. });
  189. },
  190. initScroll = function () {
  191. //循环初始化所有下拉刷新,上拉加载。
  192. if(mscrolls.length == 0) {
  193. $.each(document.querySelectorAll('.mui-slider-group .mui-scroll-wrapper'), function(index, pullRefreshEl) {
  194. var page = 1;
  195. var wheaType= $(this).closest('.mui-slider-item').attr('data-type')||"";
  196. var pullRefresh = mui(pullRefreshEl).pullRefresh({
  197. down: {
  198. callback: function() {
  199. page = 1;
  200. var self = this;
  201. var ul = self.element.querySelector('.mui-table-view');
  202. var $scrollEl = $(ul).closest('.mui-scroll');
  203. var $noResult = $scrollEl.find('.no-result');
  204. $noResult.hide();
  205. loadListPromise(wheaType,page)
  206. .then(function(list) {
  207. plus.nativeUI.closeWaiting();
  208. if(list && list.length) {
  209. page++;
  210. setTimeout(function() {
  211. var html = template('articleimgLi',{list: list});
  212. $(ul).html(html);
  213. self.endPulldownToRefresh(list.length < pagesize);
  214. }, 1000);
  215. } else {
  216. if(page == 1) {
  217. $noResult.show();
  218. self.endPulldownToRefresh(true);
  219. }
  220. self.endPulldownToRefresh();
  221. }
  222. })
  223. .catch(function(e) {
  224. console && console.error(e)
  225. })
  226. }
  227. },
  228. up: {
  229. callback: function() {
  230. var self = this;
  231. var ul = self.element.querySelector('.mui-table-view');
  232. var $scrollEl = $(ul).closest('.mui-scroll');
  233. var $noResult = $scrollEl.find('.no-result');
  234. loadListPromise(wheaType,page)
  235. .then(function(list) {
  236. if(list && list.length) {
  237. page++;
  238. setTimeout(function() {
  239. var html = template('articleimgLi',{list: list});
  240. $(ul).append(html);
  241. self.endPullupToRefresh(list.length < pagesize);
  242. }, 1000);
  243. } else {
  244. if(page == 1) {
  245. $noResult.show();
  246. }
  247. self.endPullupToRefresh(true);
  248. }
  249. })
  250. .catch(function(e) {
  251. console && console.error(e)
  252. })
  253. }
  254. }
  255. });
  256. mscrolls.push(pullRefresh)
  257. });
  258. }
  259. },
  260. send = function(article){
  261. var params = {};
  262. params.code =article;
  263. params.patient=patient;
  264. //params.teamCode=1;
  265. params.attachedContent = $.trim($('#messageInput').val());
  266. plus.nativeUI.showWaiting();
  267. sendPost("/doctor/jkEdu/article/doctorSendArticleToPatients",params,sendError,function(res){
  268. if(res.status == 200){
  269. mui.toast("发送成功!");
  270. var $this = $("[data-code="+article+"]");
  271. $this.append('<div class="sent-flag"><span class="c-fff c-f14 ml10">已发送</span></div>');
  272. var num = $this.find(".send_count").text();
  273. $this.find(".send_count").text(parseInt(num)+1);
  274. }else{
  275. sendError(res);
  276. }
  277. plus.nativeUI.closeWaiting();
  278. });
  279. },
  280. sendError = function (res){
  281. plus.nativeUI.closeWaiting();
  282. if(res.msg){
  283. mui.toast(res.msg);
  284. }else{
  285. mui.toast("发送失败!");
  286. }
  287. },
  288. sendSuccess = function (res){
  289. plus.nativeUI.closeWaiting();
  290. if(res.status==200){
  291. mui.toast("发送成功!");
  292. var view = plus.webview.getWebviewById("jiankangjiaoyu");
  293. if(view){
  294. mui.fire(view,"refresh");
  295. }
  296. view=plus.webview.getWebviewById("article");
  297. if(view){
  298. mui.fire(view,"refresh");
  299. openWebviewExtras("article.html",{article:article,patient:patient,patientName:self.patientName});
  300. }else{
  301. openWebviewExtras("jiankangjiaoyu.html",{patient:patient,patientName:self.patientName});
  302. }
  303. }else{
  304. sendError(res);
  305. }
  306. },
  307. showDialog = function (article,title,patientName) {
  308. dialog({
  309. 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>',
  310. content: '<div><div class="c-f16 c-323232 c-t-left mb10">《'+title+'》</div><input id="messageInput" class="c-f14 pl10" placeholder="给居民留言..."/></div>',
  311. okValue: '立即发送',
  312. cancelValue: '我再看看',
  313. cancel: function () {
  314. return;
  315. },
  316. ok: function() {
  317. send(article);
  318. }
  319. }).showModal();
  320. };
  321. // 页面业务处理流程开始
  322. new Promise(function(resolve, reject) {
  323. // TODO 临时放开
  324. //resolve(true);
  325. mui.plusReady(function() {
  326. // hrefhrefplus已经准备好,可以往下执行
  327. resolve(true);
  328. });
  329. }).then(function() {
  330. // 获取基础环境信息
  331. return getBaseEnvPromise().then(function(env) {
  332. baseEnv = env;
  333. }).then(function() {
  334. // 获取登录基本信息
  335. baseInfo = getBaseInfo();
  336. var self = plus.webview.currentWebview();
  337. patient = self.patient;
  338. patientName = self.patientName;
  339. initScroll();
  340. // 绑定页面事件
  341. bindEvents();
  342. var openerId = self.opener().id;
  343. if(openerId=="home2.html") { // 首页进入
  344. $('#recordsLink').show();
  345. }
  346. $('.mui-control-item.mui-active').trigger('tap');
  347. })
  348. }).catch(function(e) {
  349. plus.nativeUI.closeWaiting();
  350. console && console.error(e);
  351. });
  352. template.helper("setPhoto", function(p) {
  353. return getImgUrl(p);
  354. });