beauty-archive.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. var isPC = $(window).width() > 768;
  2. var clientWidth = $(window).width() ;
  3. $(window).on('resize', function () {
  4. var change = $(window).width() > 768;
  5. clientWidth = $(window).width();
  6. if (isPC === change) return;
  7. window.location.reload();
  8. });
  9. //美业资料库列表
  10. var beautyArchive = new Vue({
  11. el: '#beautyArchive',
  12. data: {
  13. listLoading: false,
  14. total: 0, // 商品总数
  15. totalPage: 0,// 分页数
  16. jumpPageSize: '',
  17. listQuery: {
  18. keyword: '', //查询关键词
  19. productType: 0, //商品类型 0 全部 1 仪器 2 产品
  20. pageNum: 1,
  21. pageSize: 10
  22. },
  23. keyword: '',
  24. productList: [], //商品列表
  25. hasNextPage: false,
  26. showPageBtn: 6,
  27. openSearch: false, //开启搜索
  28. currentTab: 0,
  29. tabList: [{
  30. id: 0,
  31. name: '全部'
  32. }, {
  33. id: 1,
  34. name: '产品'
  35. }, {
  36. id: 2,
  37. name: '仪器'
  38. }]
  39. },
  40. watch: {
  41. keyword: function (val) {
  42. if (val) return;
  43. this.openSearch = false;
  44. this.listQuery.keyword = '';
  45. this.getList();
  46. }
  47. },
  48. mounted() {
  49. this.getList();
  50. },
  51. computed: {
  52. loadingText: function () {
  53. return this.hasNextPage ? '上滑加载更多' : '没有更多了';
  54. },
  55. pagination: function () {
  56. var index = this.listQuery.pageNum, arr = [];
  57. if (this.totalPage <= 6) {
  58. for (var i = 1; i <= this.totalPage; i++) {
  59. arr.push(i);
  60. }
  61. return arr;
  62. }
  63. if (index <= 3) {
  64. return [1, 2, 3, 4, 5, 0, this.totalPage];
  65. }
  66. if (index >= this.totalPage - 2) {
  67. return [1, 0, this.totalPage - 4, this.totalPage - 3, this.totalPage - 2, this.totalPage - 1, this.totalPage];
  68. }
  69. return [1, 0, index - 2, index - 1, index, index + 1, index + 2, 0, this.totalPage];
  70. }
  71. },
  72. filters: {
  73. productType: function (val) {
  74. if (val === 1) {
  75. return '产品';
  76. }
  77. if (val === 2) {
  78. return '仪器';
  79. }
  80. return '未知';
  81. }
  82. },
  83. methods: {
  84. //页码跳转
  85. toPagination: function (pageNum) {
  86. if (pageNum > this.totalPage || pageNum <= 0) {
  87. return this.jumpPageSize = '';
  88. }
  89. this.listQuery.pageNum = parseInt(pageNum);
  90. this.getList(); //获取列表
  91. },
  92. //获取商品列表
  93. getList: function () {
  94. const _that = this;
  95. _that.listLoading = true;
  96. BeautyArchiveApi.GetArchiveProduct(this.listQuery, function (res) {
  97. if (res.code !== 0) return console.log('请求失败');
  98. _that.hasNextPage = res.data.hasNextPage;
  99. _that.listQuery.pageNum = res.data.pageNum;
  100. _that.listQuery.pageSize = res.data.pageSize;
  101. _that.total = res.data.totalRecord;
  102. _that.totalPage = res.data.totalPage;
  103. if (isPC) {
  104. _that.productList = res.data.results;
  105. } else {
  106. _that.productList = _that.productList.concat(res.data.results);
  107. }
  108. _that.listLoading = false;
  109. _that.windowScroll();
  110. })
  111. },
  112. //tab切换
  113. tabClick: function (productType, index) {
  114. this.currentTab = index;
  115. this.listQuery.pageNum = 1;
  116. this.listQuery.productType = productType;
  117. this.productList = [];
  118. this.getList();
  119. },
  120. // 高亮文字
  121. formatTitle: function(val){
  122. var reg = new RegExp(this.listQuery.keyword, 'g');
  123. var str = '<span>' + this.listQuery.keyword + '</span>';
  124. return val.replace(reg, str);
  125. },
  126. //搜索
  127. handleSearch: function (keyword) {
  128. this.listQuery.keyword = keyword;
  129. this.listQuery.pageNum = 1;
  130. this.productList = [];
  131. this.openSearch = true;
  132. this.getList();
  133. console.log(this.listQuery.keyword);
  134. },
  135. //跳转到商品详情
  136. handleToDetail: function (product) {
  137. var url = '';
  138. if(!product.archiveId) {
  139. window.location.href = '/404.html'
  140. }
  141. if (product.redirectType === 1) {
  142. url = '/product-' + product.productId +'-'+globalUserData.userId+ '.html?open=caimei365';
  143. } else if (product.redirectType === 2) {
  144. url = '/document/archive-detail.html' + '?id=' + product.archiveId;
  145. } else {
  146. return;
  147. }
  148. window.open(url, '_blank');
  149. },
  150. //打开新窗口
  151. openWindow: function (url) {
  152. window.open(url, '_blank');
  153. },
  154. //窗口滚动事件
  155. windowScroll: function () {
  156. if (isPC) return;
  157. var _that = this;
  158. $(function () {
  159. $(window).scroll(function () {
  160. clearTimeout(window.scrollTimer);
  161. window.scrollTimer = setTimeout(function () {
  162. var scorllTop = $(window).scrollTop();
  163. var contentHeight = $('body').height();
  164. var clientHeight = $(window).height();
  165. if (contentHeight - scorllTop - 10 <= clientHeight) {
  166. if(!_that.hasNextPage) return;
  167. _that.listQuery.pageNum ++;
  168. _that.getList();
  169. }
  170. }, 200);
  171. });
  172. });
  173. }
  174. }
  175. });