myArticle.js 7.9 KB

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