list.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  1. const requestUrlConfig = {
  2. keyword: coreServer + "/commodity/search/query/article",
  3. labelId: coreServer + "/commodity/search/query/article/label",
  4. typeId: coreServer + "/commodity/search/query/article/type"
  5. };
  6. const articleList = new Vue({
  7. el: '#ArticleContent',
  8. mixins: [cmSysVitaMixins,searchMixins],
  9. filters: {
  10. keywordSlice: function (keyword) {
  11. return keyword.length > 6 ? keyword.slice(0, 6) + '…' : keyword;
  12. }
  13. },
  14. data: {
  15. loginStatus: false,
  16. listLoading: true,
  17. requestFlag: true,
  18. noMore: false,
  19. params: {
  20. size: 8,
  21. num: 1,
  22. typeId: '',
  23. labelId: '',
  24. keyword: '',
  25. status: 1,
  26. startDate: '',
  27. endDate: '',
  28. productFlag: 1, // 是否统计关键词 1 统计 0 不统计
  29. linkageFlag: 0, // 关键词来源是否为用户搜索 0 是 1 不是
  30. sortType: 1 // 最新 最早
  31. },
  32. listData: [],
  33. listRecord: 0,
  34. productRecord: 0,
  35. productList: [],
  36. pageInput: '1',
  37. keyword: '',
  38. requestType: '', // 请求链接类型keyword | labelId | typeId
  39. featuredList: [], // 精选推荐列表
  40. dialogVisible: true, // 弹窗
  41. searchKeys: "", // 搜索词
  42. newsList: [],
  43. isLoading:false
  44. },
  45. computed: {
  46. pageTotal: function () {
  47. var total = Math.ceil(this.listRecord / this.params.size);
  48. return total > 0 ? total : 1;
  49. },
  50. showPageBtn: function () {
  51. var total = Math.ceil(this.listRecord / this.params.size);
  52. total = total > 0 ? total : 1;
  53. var index = this.params.num, arr = [];
  54. if (total <= 6) {
  55. for (var i = 1; i <= total; i++) {
  56. arr.push(i);
  57. }
  58. return arr;
  59. }
  60. if (index <= 3) return [1, 2, 3, 4, 5, 0, total];
  61. if (index >= total - 2) return [1, 0, total - 4, total - 3, total - 2, total - 1, total];
  62. return [1, 0, index - 2, index - 1, index, index + 1, index + 2, 0, total];
  63. }
  64. },
  65. watch: {},
  66. created: function () {
  67. // 判断登录状态
  68. var self = this;
  69. if (globalUserData.token) {
  70. this.loginStatus = true;
  71. }
  72. this.cmSysParams.pageType = 18;
  73. this.cmSysParams.pageLabel = getUrlParam("keyword") ? getUrlParam("keyword") : $('.newTitle').text();
  74. this.$nextTick(function () {
  75. self.initQueryParam();
  76. self.initBase();
  77. });
  78. self.initAuthInputComplete();
  79. this.getNewList()
  80. },
  81. methods: {
  82. initAuthInputComplete() {
  83. new AutoComplete({
  84. el: '.auto-input',
  85. callback: async function (keyword) {
  86. try {
  87. const res = await PublicApi.fetchQueryKeywordList({keyword: keyword});
  88. if (!res.data) return [];
  89. return res.data.map(item => item.keyword);
  90. } catch (e) {
  91. console.log(e);
  92. }
  93. },
  94. itemClick: function (keyword) {
  95. window.location.href = '/info/search-1.html?keyword=' + keyword + '&linkageFlag=1';
  96. }
  97. });
  98. },
  99. // 初始化链接参数
  100. initQueryParam() {
  101. if (isPC) {
  102. this.params.size = getUrlParam("pageSize") ? getUrlParam("pageSize") * 1 : 8;
  103. this.params.num = $("#pageNum").val() ? $("#pageNum").val() * 1 : 1;
  104. } else {
  105. this.params.size = 8;
  106. this.params.num = 1;
  107. }
  108. this.keyword = getUrlParam("keyword") ? getUrlParam("keyword") : '';
  109. this.params.linkageFlag = getUrlParam('linkageFlag') ? getUrlParam('linkageFlag') : 0
  110. this.params.keyword = this.keyword;
  111. },
  112. //初始化页面
  113. initBase: function () {
  114. this.params.typeId = $("#typeId").val() * 1;
  115. this.params.labelId = $("#labelId").val() * 1;
  116. if (!this.params.typeId) {
  117. $(".content").addClass("sea-top");
  118. }
  119. if (this.params.typeId) {
  120. this.requestType = 'typeId'
  121. } else if (this.params.labelId) {
  122. this.requestType = 'labelId'
  123. } else if (this.params.keyword) {
  124. this.requestType = 'keyword'
  125. $('#topSearch .keyword').val(this.params.keyword);
  126. $('.tip-bar').css('padding-bottom', 0);
  127. }
  128. this.requestAction(this.requestType);
  129. this.initPageReset();
  130. this.initSortControl();
  131. this.fetchProductList();
  132. },
  133. // 发起文章列表请求
  134. requestAction: function (type) {
  135. var requestAction = {
  136. 'typeId': this.initWithTypeId,
  137. 'labelId': this.initWithLabelId,
  138. 'keyword': this.initWithKeyword,
  139. };
  140. requestAction[type]();
  141. },
  142. // 文章分类查询列表
  143. initWithTypeId: function () {
  144. var params = {
  145. id: this.params.typeId,
  146. pageSize: this.params.size,
  147. pageNum: this.params.num,
  148. sortType: this.params.sortType
  149. }
  150. this.getArticleList(requestUrlConfig['typeId'], params);
  151. },
  152. //文章标签查询文章列表
  153. initWithLabelId: function () {
  154. var params = {
  155. id: this.params.labelId,
  156. pageSize: this.params.size,
  157. pageNum: this.params.num
  158. }
  159. this.getArticleList(requestUrlConfig['labelId'], params);
  160. },
  161. // 关键词查询文章列表
  162. initWithKeyword: function () {
  163. var params = {
  164. keyword: this.params.keyword,
  165. pageSize: this.params.size,
  166. pageNum: this.params.num,
  167. status: this.params.status,
  168. productFlag: this.params.productFlag, // 是否统计关键词 1 统计 2 不统计
  169. linkageFlag: this.params.linkageFlag // 关键词来源是否为用户搜索 0 是 1 不是
  170. }
  171. this.getArticleList(requestUrlConfig['keyword'], params);
  172. },
  173. // 弹窗缩放
  174. handlerPopup() {
  175. if (!this.dialogVisible) {
  176. this.dialogVisible = !this.dialogVisible;
  177. }
  178. },
  179. // 高亮关键词
  180. highlightKeyword: function (str) {
  181. return str.replace(new RegExp(this.keyword, 'g'), '<span style="color: #FF5B00">' + this.keyword + '</span>')
  182. },
  183. // 获取文章列表
  184. getArticleList: function (url, params, isSelect) {
  185. var self = this;
  186. $.getJSON(url, params, function (r) {
  187. if (r.code === 0 && r.data) {
  188. var result = JSON.parse(r.data);
  189. self.listRecord = result.total;
  190. var resultData = [];
  191. result.items.map(function (item) {
  192. resultData.push({
  193. id: item.articleId,
  194. title: item.title,
  195. image: item.image,
  196. intro: item.intro,
  197. typeId: item.typeId,
  198. type: item.typeText,
  199. labelIds: item.labelIds.replace(/[^[\d|\S]]*/g, ',').split(","),
  200. labels: item.labelText.replace(/[^[\d|\S]]*/g, ',').split(","),
  201. pv: item.pv,
  202. publisher: item.publisher,
  203. publishDate: item.publishDate
  204. });
  205. });
  206. // 处理标题和描述
  207. resultData = resultData.map(function (item) {
  208. item.title = self.highlightKeyword(item.title);
  209. item.intro = self.highlightKeyword(item.intro);
  210. return item
  211. });
  212. if (isPC) {
  213. self.listData = resultData
  214. } else {
  215. if (isSelect) {
  216. self.listData = resultData
  217. return
  218. }
  219. self.listData = self.listData.concat(resultData);
  220. }
  221. }
  222. self.listLoading = false;
  223. self.requestFlag = true;
  224. })
  225. },
  226. // 搜索
  227. onSearchEnter: function () {
  228. if (this.keyword === '') {
  229. $.confirm({
  230. useBootstrap: false,
  231. boxWidth: (isPC ? '300px' : '70%'),
  232. title: '提示',
  233. content: '请输入文章关键字!',
  234. closeIcon: true,
  235. animation: 'opacity',
  236. closeAnimation: 'opacity',
  237. animateFromElement: false,
  238. buttons: {
  239. close: {
  240. text: '确定',
  241. btnClass: 'btn-confirm'
  242. }
  243. }
  244. });
  245. return;
  246. }
  247. var query = param({
  248. keyword: this.keyword,
  249. })
  250. window.location.href = '/info/search-1.html?' + query;
  251. },
  252. // 页码跳转
  253. toPagination: function (pageNum) {
  254. if (pageNum <= this.pageTotal) {
  255. var params = {pageNum: pageNum};
  256. window.location.href = updateUrlParam(params);
  257. }
  258. },
  259. // 页码链接处理
  260. paginationUrl: function (pageNum) {
  261. var path = window.location.href;
  262. var paramsArr = window.location.pathname.split(".")[0].split("-");
  263. var pageId = paramsArr.length >= 1 ? paramsArr[1] : '';
  264. if (paramsArr[0].indexOf('/info/search') >= 0) {
  265. var search = window.location.search;
  266. path = '/info/search-' + pageNum + '.html' + search;
  267. } else if (paramsArr[0].indexOf('/info/center') >= 0) {
  268. path = '/info/center-' + pageId + '-' + pageNum + '.html';
  269. } else if (paramsArr[0].indexOf('/info/label') >= 0) {
  270. path = '/info/label-' + pageId + '-' + pageNum + '.html';
  271. }
  272. return path;
  273. },
  274. // 页面修改
  275. checkNum: function () {
  276. if (this.pageInput > this.pageTotal) {
  277. this.pageInput = this.pageTotal;
  278. } else if (this.pageInput < 1) {
  279. this.pageInput = 1;
  280. }
  281. },
  282. // 获取产品列表
  283. fetchProductList: function () {
  284. var self = this;
  285. ProductApi.GetProductSearchList({
  286. keyword: this.params.keyword,
  287. productFlag: 0, // 是否统计关键词 1 统计 0 不统计
  288. linkageFlag: 0 // 关键词来源是否为用户搜索 0 是 1 不是
  289. }, function (res) {
  290. res = JSON.parse(res.data);
  291. self.productRecord = res.total;
  292. if (res.total > 8) {
  293. self.productList = res.items.slice(0, 6);
  294. } else {
  295. self.productList = res.items.slice(0, 8);
  296. }
  297. })
  298. },
  299. // 初始化排序控件
  300. initSortControl: function () {
  301. var self = this;
  302. initFilterSort({
  303. el: '#searchSortControl',
  304. confirm(result) {
  305. console.log('确定')
  306. self.listLoading = true;
  307. self.requestFlag = false;
  308. self.listData = [];
  309. self.listRecord = 0;
  310. self.params.status = result.status;
  311. self.params.num = 1;
  312. self.requestAction(self.requestType);
  313. },
  314. })
  315. },
  316. onPageScroll: debounce(function () {
  317. var scrollTop = $('body').scrollTop();
  318. var documentHeight = $(document).height();
  319. var windowHeight = $('body').height();
  320. // alert(scrollTop + windowHeight == documentHeight)
  321. if (scrollTop > 600) {
  322. $('#scrollTop').show();
  323. } else {
  324. $('#scrollTop').hide();
  325. }
  326. // if (scrollTop + windowHeight + 100 > documentHeight) {
  327. // 此处是滚动条到底部时候触发的事件,在这里写要加载的数据,或者是拉动滚动条的操作
  328. // if (this.params.num < this.pageTotal) { // 获取列表数据
  329. // if (this.requestFlag) {
  330. // this.params.num = this.params.num + 1;
  331. // this.requestAction(this.requestType);
  332. // }
  333. // } else { //到底了
  334. // this.noMore = true;
  335. // $('footer').removeClass("noneImportant");
  336. // }
  337. // }
  338. }),
  339. //获取更多数据
  340. handleMore() {
  341. if (this.params.num < this.pageTotal) { // 获取列表数据
  342. if (this.requestFlag) {
  343. this.params.num = this.params.num + 1;
  344. this.requestAction(this.requestType);
  345. }
  346. } else { //到底了
  347. this.noMore = true;
  348. $('footer').removeClass("noneImportant");
  349. }
  350. },
  351. // 页面样式初始化
  352. initPageReset: function () {
  353. if (!isPC) {
  354. $('footer').addClass("noneImportant");
  355. //移动端上垃加载更多
  356. $('body').on('scroll', this.onPageScroll);
  357. }
  358. },
  359. // 文章列表切换 最新 最早
  360. selectListNew(e) {
  361. this.params.sortType = e
  362. this.params.size = 8
  363. this.params.num = 1
  364. let params = {
  365. id: this.params.typeId,
  366. pageSize: 8,
  367. pageNum: 1,
  368. sortType: this.params.sortType
  369. }
  370. this.getArticleList(requestUrlConfig['typeId'], params, true)
  371. },
  372. hanldDetails(id) {
  373. window.open('/news/details.html?id=' + id);
  374. },
  375. getNewList() {
  376. PublicApi.GetHomeInit({source: 1}, ({data}) => {
  377. if (isPC) {
  378. this.newsList = data.annlist
  379. } else {
  380. this.newsList = data.annlist.slice(0, 1)
  381. }
  382. });
  383. },
  384. // 供应商广告图统计
  385. setAdvStatistics ($event) {
  386. BeautyArchiveApi.GetStatisticsAddPv({type: 5, authorId: $event.id}, () => {
  387. console.log("供应商广告图点击统计成功")
  388. })
  389. if ($event.jumpLink) {
  390. window.open($event.jumpLink)
  391. }
  392. },
  393. openFullScreen1() {
  394. const _self = this
  395. const loading = this.$loading({
  396. lock: true,
  397. text: '',
  398. spinner: 'el-icon-loading',
  399. background: 'rgba(0, 0, 0, 0.2)'
  400. });
  401. setTimeout(() => {
  402. _self.isLoading = true;
  403. loading.close();
  404. }, 500);
  405. },
  406. },
  407. mounted () {
  408. this.openFullScreen1()
  409. }
  410. });
  411. function initFilterSort(option = {}) {
  412. var sortControl = $(option.el);
  413. var sortItem = sortControl.find('.search__sort_select li');
  414. var sotrCurrent = sortControl.find('.search__sort_current');
  415. $(window).on('click', function (el) {
  416. if (sortControl.has(el.target).length > 0) return;
  417. sortControl.removeClass('active');
  418. })
  419. sortControl.on('click', function () {
  420. $(this).toggleClass('active');
  421. })
  422. sortItem.on('click', function (el) {
  423. $(this).addClass('selected').siblings('li').removeClass('selected');
  424. var status = parseInt($(this).attr('data-type'));
  425. console.log(status)
  426. sotrCurrent.text($(this).text());
  427. option.confirm && option.confirm({status: status});
  428. })
  429. }