article-list.js 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. "use strict";
  2. var articleList = new Vue({
  3. el: '#articleList',
  4. data: {
  5. name: 'supplier-article-list',
  6. refreshType: '',
  7. hidden: '',
  8. visibilityChange: '',
  9. listRecord: 0,
  10. shopId: GLOBAL_SHOP_ID || 0,
  11. listQuery: {
  12. articleId: '',
  13. title: '',
  14. publisher: '',
  15. auditStatus: '',
  16. status: '',
  17. onlineStatus: '',
  18. typeId: '',
  19. pageNum: 1,
  20. pageSize: 10
  21. },
  22. pageInput: 1,
  23. pageTotal: 0,
  24. articleList: [],
  25. articleTypeList: []
  26. },
  27. computed: {
  28. pageTotal: function pageTotal() {
  29. var total = Math.ceil(this.listRecord / this.listQuery.pageSize);
  30. return total > 0 ? total : 1;
  31. },
  32. showPageBtn: function showPageBtn() {
  33. var total = Math.ceil(this.listRecord / this.listQuery.pageSize);
  34. total = total > 0 ? total : 1;
  35. var index = this.listQuery.pageNum,
  36. arr = [];
  37. if (total <= 6) {
  38. for (var i = 1; i <= total; i++) {
  39. arr.push(i);
  40. }
  41. return arr;
  42. }
  43. if (index <= 3) return [1, 2, 3, 4, 5, 0, total];
  44. if (index >= total - 2) return [1, 0, total - 4, total - 3, total - 2, total - 1, total];
  45. return [1, 0, index - 2, index - 1, index, index + 1, index + 2, 0, total];
  46. }
  47. },
  48. filters: {
  49. // 时间格式化
  50. formatDate: function formatDate(date) {
  51. if (!date) return '---';
  52. return dateFormat(new Date(date));
  53. }
  54. },
  55. created: function created() {
  56. this.getArticleList();
  57. this.fetchArticleCatagory();
  58. },
  59. mounted: function mounted() {
  60. window.name = this.name;
  61. // this.bindWindowHiddenOrVis();
  62. $('.navLayout').find('.navList').removeClass("on").find('.con').hide().find('a').removeClass("on");
  63. $('.navLayout').find('.navList').eq(2).addClass("on").find('.con').show().find('a').eq(0).addClass("on");
  64. },
  65. methods: {
  66. // 获取文章列表
  67. getArticleList: function getArticleList() {
  68. var that = this;
  69. this.listQuery.shopId = this.shopId;
  70. SupplierApi.GetArticleList(this.listQuery, function (res) {
  71. // console.log(res);
  72. if (res.code === 0) {
  73. that.listRecord = res.data.total;
  74. that.articleList = res.data.list;
  75. that.pageTotal = res.data.pages;
  76. } else {
  77. CAIMEI.Alert(res.msg, '确定', false);
  78. }
  79. });
  80. },
  81. //表格操作按钮点击
  82. clickOption: function clickOption(article, type) {
  83. var handles = {
  84. 1: this.toEdit,
  85. 2: this.changeStatus,
  86. 3: this.toDetail,
  87. 4: this.handleDelete
  88. };
  89. handles[type](article);
  90. },
  91. //跳转编辑页面
  92. toEdit: function toEdit(article) {
  93. localStorage.setItem('articleId', article.articleId);
  94. window.open('/supplier/article/edit.html');
  95. },
  96. //修改状态
  97. changeStatus: function changeStatus(article) {
  98. var newStatus = 1;
  99. if (article.status === 1) {
  100. newStatus = 0;
  101. }
  102. SupplierApi.ArticleStatusChange({
  103. articleId: article.articleId,
  104. shopId: this.shopId,
  105. status: newStatus
  106. }, function (res) {
  107. if (res.code === 0) {
  108. // 不刷新数据更新
  109. article.status = newStatus;
  110. const tip = newStatus ? '文章已发布' : '文章已存入草稿箱';
  111. CAIMEI.dialog(tip);
  112. } else {
  113. CAIMEI.dialog('修改文章状态失败!');
  114. }
  115. });
  116. },
  117. //查看
  118. toDetail: function toDetail(article) {
  119. if (article.auditStatus !== 2) return CAIMEI.dialog('请等待审核通过后查看!');
  120. if (article.onlineStatus !== 2) return CAIMEI.dialog('请等待文章上线后查看!');
  121. if (!article.status) return CAIMEI.dialog('请发布后查看!');
  122. window.open('/info/detail-' + article.articleId + '-1.html');
  123. },
  124. // 跳转添加文章页面
  125. handleAddArticle: function handleAddArticle() {
  126. window.open('/supplier/article/edit.html');
  127. },
  128. // 查询文章列表
  129. handleSearchList: function handleSearchList() {
  130. this.listQuery.pageNum = 1;
  131. this.getArticleList();
  132. },
  133. // 获取文章列表
  134. fetchArticleCatagory: function fetchArticleCatagory() {
  135. var that = this;
  136. SupplierApi.ArticleCategory({}, function (res) {
  137. if (res.code === 0) {
  138. that.articleTypeList = res.data;
  139. } else {
  140. CAIMEI.Alert(res.msg, '确定', false);
  141. }
  142. });
  143. },
  144. //删除确认
  145. handleDelete: function handleDelete(article) {
  146. var that = this;
  147. var params = {
  148. content: '确认删除改文章?',
  149. cancelBtnText: '取消',
  150. confitmBtnText: '删除',
  151. closeIcon:true
  152. };
  153. CAIMEI.Popup(params, function () {
  154. that.articleDelete(article);
  155. });
  156. },
  157. // 删除文章
  158. articleDelete: function articleDelete(article) {
  159. var that = this;
  160. SupplierApi.ArticleRemove({
  161. articleId: article.articleId
  162. }, function (res) {
  163. if (res.code === 0) {
  164. that.getArticleList();
  165. CAIMEI.dialog('删除文章成功!');
  166. } else {
  167. CAIMEI.dialog('删除文章失败!');
  168. }
  169. });
  170. },
  171. //页码跳转
  172. toPagination: function toPagination(pageNum) {
  173. if (pageNum <= this.pageTotal) {
  174. this.listQuery.pageNum = pageNum; // console.log('页码跳转');
  175. this.getArticleList();
  176. $('html ,body').animate({scrollTop: 0}, 400, 'linear'); // 页面置顶
  177. }
  178. },
  179. // 输入框设置页码
  180. checkNum: function checkNum() {
  181. if (this.pageInput > this.pageTotal) {
  182. this.pageInput = this.pageTotal;
  183. } else if (this.pageInput < 1) {
  184. this.pageInput = 1;
  185. }
  186. },
  187. bindWindowHiddenOrVis: function bindWindowHiddenOrVis() {
  188. // 设置隐藏属性和改变可见属性的事件的名称
  189. if (typeof document.hidden !== "undefined") {
  190. // Opera 12.10 and Firefox 18 and later support
  191. this.hidden = "hidden";
  192. this.visibilityChange = "visibilitychange";
  193. } else if (typeof document.msHidden !== "undefined") {
  194. this.hidden = "msHidden";
  195. this.visibilityChange = "msvisibilitychange";
  196. } else if (typeof document.webkitHidden !== "undefined") {
  197. this.hidden = "webkitHidden";
  198. this.visibilityChange = "webkitvisibilitychange";
  199. } // 如果浏览器不支持addEventListener 或 Page Visibility API 给出警告
  200. if (typeof document.addEventListener === "undefined" || typeof document[this.hidden] === "undefined") {
  201. console.log("This demo requires a browser, such as Google Chrome or Firefox, that supports the Page Visibility API.");
  202. } else {
  203. // 处理页面可见属性的改变
  204. document.addEventListener(this.visibilityChange, this.handleVisibilityChange, false);
  205. }
  206. },
  207. // 如果页面是展示状态 && 需要刷新列表,则刷新列表
  208. handleVisibilityChange: function handleVisibilityChange() {
  209. var that = this;
  210. this.refreshType = window.localStorage.getItem('refreshType');
  211. if (document[that.hidden]) {
  212. console.log(this.refreshType);
  213. console.log('article list page is show');
  214. if (this.refreshType) {
  215. that.listQuery.pageNum = 1;
  216. window.localStorage.removeItem('refreshType');
  217. that.getArticleList();
  218. }
  219. }
  220. }
  221. }
  222. });