myArticle.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. var page = 0,
  2. pagesize = 10;
  3. var $tabs = $('#tabs'),
  4. $panels = $('.c-panels'),//切换选项卡
  5. $list = $('#dest_list'),//选项卡内容
  6. $notext = $('#no_result_wrap'),//没有样式
  7. $scroll = $('#iScroll');//内容展示
  8. var teamInfo,
  9. docInfo,
  10. teamCode,//团队code
  11. categoryLevel="",//级别id
  12. categoryId="",//类别id
  13. isAuthentication="",
  14. startDate="",
  15. firstLevelCategoryId ="",
  16. endDate="",
  17. hospitalName="",
  18. currentUserRole="";
  19. // 获取登录相关信息
  20. var getBaseInfo = function() {
  21. // 登录的相关信息
  22. currentUserRole = JSON.parse(plus.storage.getItem('docInfo')).hospital
  23. return currentUserRole;
  24. }
  25. var getHospitalName = function() {
  26. // 登录的相关信息
  27. hospitalName = JSON.parse(plus.storage.getItem('docInfo')).hospitalName
  28. return hospitalName;
  29. }
  30. /*刷新事件*/
  31. window.addEventListener("reloadPage", function refresh(e) {
  32. refreshPage();
  33. });
  34. function refreshPage(){
  35. $('#dest_list').empty();
  36. categoryId = ""; //类别id
  37. isAuthentication = "";
  38. startDate = "";
  39. endDate = "";
  40. //将所有顶部的选项置为默认置
  41. $("#showHeader li").removeClass("list-selected");
  42. $("#showHeader ul li:first-child").addClass("list-selected");
  43. $("#tabs .j-tag:eq(0)").text("全部分类");
  44. $("#tabs .j-tag:eq(1)").text("认证状态");
  45. $("#tabs .j-tag:eq(2)").text("全部时间");
  46. queryListData(true);
  47. }
  48. function queryHeaderData(){
  49. sendPost("/third/jkEdu/Article/getCategoryByName",{name:'健康文章'}, null, function(res){
  50. if(res.status == 200){
  51. var html = template('tag_tmpl',{data:res.data})
  52. $('#showHeader').html(html)
  53. firstLevelCategoryId = res.data.cid;
  54. queryListData(true);
  55. }
  56. },'get')
  57. }
  58. function queryListData(isInit){
  59. if(isInit){
  60. page = 0;
  61. }
  62. var params ={
  63. firstLevelCategoryId: firstLevelCategoryId,
  64. secondLevelCategoryId: categoryId,
  65. isAuthentication: isAuthentication,//文章是否认证
  66. insertTimeStart: startDate,
  67. insertTimeEnd: endDate,
  68. currentUserRole: currentUserRole,
  69. iDisplayStart: page,
  70. iDisplayLength: pagesize,
  71. currentUserRoleLevel: 4,
  72. roleType:1,
  73. isMyArticle: true
  74. }
  75. sendPost("/doctor/jkEdu/article/queryArticleAPPList",params, function(){
  76. plus.nativeUI.closeWaiting();
  77. fun&&fun.call(this,false)
  78. mui.toast("获取数据失败!");
  79. }, function(res){
  80. plus.nativeUI.closeWaiting();
  81. if(res.status == 200){
  82. if(isInit && res.data.aaData.length == 0){
  83. $notext.show();
  84. $scroll.hide();
  85. return;
  86. }else{
  87. $notext.hide();
  88. $scroll.show();
  89. var html = template('li_tmpl',{list:res.data.aaData});
  90. if(isInit){
  91. mui('.mui-scroll-wrapper').scroll().scrollTo(0,0,300);
  92. $("#dest_list").empty().append(html);
  93. }else{
  94. $("#dest_list").append(html);
  95. }
  96. if(res.data.aaData.length < pagesize){
  97. mui(".mui-scroll-wrapper").pullRefresh().endPullupToRefresh(true);
  98. }else{
  99. page ++;
  100. mui(".mui-scroll-wrapper").pullRefresh().endPullupToRefresh(false);
  101. }
  102. }
  103. }else{
  104. mui.toast(res.msg);
  105. }
  106. },'get')
  107. }
  108. template.helper('setSex',function(item){
  109. if(item == 1){
  110. return '男'
  111. }else{
  112. return '女'
  113. }
  114. })
  115. //该上月份最后一天
  116. function lastDate(date){
  117. var arr = date.split('-');
  118. var year = arr[0];
  119. var month = arr[1]*1-1;
  120. if(month<1){
  121. month = 12;
  122. year = year - 1;
  123. }
  124. var day = new Date(year,month,0).getDate();
  125. return day;
  126. }
  127. //近一周
  128. function beforeWeek(date,num){
  129. var d = new Date();
  130. d.setDate(date.getDate() - num);
  131. return d.format('yyyy-MM-dd');
  132. }
  133. //近几个月前
  134. function beforeMonth(date,num){
  135. var d = new Date();
  136. d.setMonth(date.getMonth() - num);
  137. return d.format('yyyy-MM-dd');
  138. }
  139. function bindEvents() {
  140. $tabs.on('click','.sanp-flex',function() {
  141. var index = $(this).index(),
  142. $panel = $panels.find('.c-panel').eq(index);
  143. $panel.siblings().hide();
  144. if($panel.css('display')=='none') {
  145. $panel.show();
  146. } else {
  147. $panel.hide();
  148. }
  149. })
  150. template.helper("getImgUrl", function(str){
  151. if(str){
  152. return getImgUrl(str);
  153. }else{
  154. return "";
  155. }
  156. });
  157. template.helper("formatDate", function(updateTime){
  158. if(updateTime){
  159. return updateTime.substr(0,19)
  160. }else{
  161. return "";
  162. }
  163. });
  164. $panels.on('click','li',function() {
  165. var $panel = $(this).closest('.c-panel');
  166. $(this).siblings().removeClass('list-selected');
  167. $(this).addClass('list-selected');
  168. $panel.hide();
  169. $('.j-tag').eq($panel.index()).text($(this).find('a').text())
  170. if($panel.index() ==0){ categoryId = $(this).attr('category-id');categoryLevel = $(this).attr('category-level') }
  171. if($panel.index() ==1){ isAuthentication = $(this).attr('data-id') }
  172. if($panel.index() ==2){
  173. var num = $(this).attr('data-id'),
  174. now = new Date();
  175. endDate = now.format('yyyy-MM-dd')+" 23:59:59";
  176. if(num == 1){
  177. startDate = beforeWeek(now,7) + " 00:00:00";
  178. }else if(num == 2){
  179. startDate = beforeMonth(now,1) + " 00:00:00";
  180. }else if(num == 3){
  181. startDate = beforeMonth(now,6) + " 00:00:00";
  182. }else if(num == 4){
  183. startDate = beforeMonth(now,12) + " 00:00:00";
  184. }else{
  185. startDate = '';
  186. endDate = '';
  187. }
  188. }
  189. queryListData(true);
  190. })
  191. $('#dest_list').on('tap','li.article-li',function(){
  192. var articleId = $(this).attr('data-id');
  193. mui.openWindow({
  194. id: "articleDetail",
  195. url: "articleDetail.html",
  196. extras: {
  197. articleId:articleId
  198. }
  199. })
  200. })
  201. //点击跳转
  202. $('#dest_list').on('tap','.tuisong-common',function(e){
  203. e.stopPropagation();
  204. var $this = $(this);
  205. var articleId = $this.attr("data-code");
  206. var articleTitle = $this.attr("data-title");
  207. mui.openWindow({
  208. id: "xuanzejumin_more",
  209. url: "xuanzejumin_more.html",
  210. extras: {
  211. article:articleId,origin:'jiaoyu',articleTitle:articleTitle
  212. }
  213. })
  214. })
  215. $('#dest_list').on('tap','.edit-common',function(e){
  216. e.stopPropagation();
  217. var $this = $(this);
  218. var articleId = $this.attr("data-id");
  219. mui.openWindow({
  220. id: "article-edit",
  221. url: "article-edit.html",
  222. extras: {
  223. articleId:articleId
  224. }
  225. })
  226. })
  227. $('#search_btn').click(function(){
  228. mui.openWindow({
  229. id: "articleSearch",
  230. url: "articleSearch.html",
  231. extras: {
  232. //必需的数据
  233. firstLevelCategoryId:firstLevelCategoryId,
  234. currentUserRole:currentUserRole,
  235. currentUserRoleLevel:4
  236. }
  237. })
  238. })
  239. //新增按钮事件
  240. $(".div-add-btn").on("click",function(){
  241. //现在固定显示咨询可以选择类型,不做三师等的判断
  242. mui.openWindow({
  243. id: "addArticle",
  244. url: "addArticle.html",
  245. extras: {
  246. firstLevelCategoryId:firstLevelCategoryId,//文章一级分类id
  247. currentUserRole:currentUserRole,
  248. hospitalName:hospitalName
  249. }
  250. })
  251. });
  252. }
  253. function initscroller(){
  254. //阻尼系数
  255. var deceleration = mui.os.ios?0.003:0.0009;
  256. mui('.mui-scroll-wrapper').scroll({
  257. bounce: false,
  258. indicators: true, //是否显示滚动条
  259. deceleration:deceleration
  260. });
  261. mui('.mui-scroll-wrapper').pullRefresh({
  262. down: {
  263. callback: function(){
  264. queryListData(true);
  265. this.endPulldownToRefresh();
  266. }
  267. },
  268. up: {
  269. callback: function(){
  270. var self = this;
  271. setTimeout(function(){
  272. queryListData(false);
  273. self.endPullupToRefresh();
  274. }, 500);
  275. }
  276. }
  277. })
  278. }
  279. new Promise(function(resolve, reject) {
  280. mui.plusReady(function() {
  281. resolve(true);
  282. })
  283. }).then(function(resolve, reject) {
  284. plus.nativeUI.showWaiting();
  285. //请求头部数据
  286. queryHeaderData();
  287. currentUserRole = getBaseInfo();
  288. hospitalName = getHospitalName();
  289. initscroller();
  290. bindEvents();
  291. });