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