123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451 |
- const requestUrlConfig = {
- keyword: coreServer + "/commodity/search/query/article",
- labelId: coreServer + "/commodity/search/query/article/label",
- typeId: coreServer + "/commodity/search/query/article/type"
- };
- const articleList = new Vue({
- el: '#ArticleContent',
- mixins: [cmSysVitaMixins,searchMixins],
- filters: {
- keywordSlice: function (keyword) {
- return keyword.length > 6 ? keyword.slice(0, 6) + '…' : keyword;
- }
- },
- data: {
- loginStatus: false,
- listLoading: true,
- requestFlag: true,
- noMore: false,
- params: {
- size: 8,
- num: 1,
- typeId: '',
- labelId: '',
- keyword: '',
- status: 1,
- startDate: '',
- endDate: '',
- productFlag: 1, // 是否统计关键词 1 统计 0 不统计
- linkageFlag: 0, // 关键词来源是否为用户搜索 0 是 1 不是
- sortType: 1 // 最新 最早
- },
- listData: [],
- listRecord: 0,
- productRecord: 0,
- productList: [],
- pageInput: '1',
- keyword: '',
- requestType: '', // 请求链接类型keyword | labelId | typeId
- featuredList: [], // 精选推荐列表
- dialogVisible: true, // 弹窗
- searchKeys: "", // 搜索词
- newsList: [],
- isLoading:false
- },
- computed: {
- pageTotal: function () {
- var total = Math.ceil(this.listRecord / this.params.size);
- return total > 0 ? total : 1;
- },
- showPageBtn: function () {
- var total = Math.ceil(this.listRecord / this.params.size);
- total = total > 0 ? total : 1;
- var index = this.params.num, arr = [];
- if (total <= 6) {
- for (var i = 1; i <= total; i++) {
- arr.push(i);
- }
- return arr;
- }
- if (index <= 3) return [1, 2, 3, 4, 5, 0, total];
- if (index >= total - 2) return [1, 0, total - 4, total - 3, total - 2, total - 1, total];
- return [1, 0, index - 2, index - 1, index, index + 1, index + 2, 0, total];
- }
- },
- watch: {},
- created: function () {
- // 判断登录状态
- var self = this;
- if (globalUserData.token) {
- this.loginStatus = true;
- }
- this.cmSysParams.pageType = 18;
- this.cmSysParams.pageLabel = getUrlParam("keyword") ? getUrlParam("keyword") : $('.newTitle').text();
- this.$nextTick(function () {
- self.initQueryParam();
- self.initBase();
- });
- self.initAuthInputComplete();
- this.getNewList()
- },
- methods: {
- initAuthInputComplete() {
- new AutoComplete({
- el: '.auto-input',
- callback: async function (keyword) {
- try {
- const res = await PublicApi.fetchQueryKeywordList({keyword: keyword});
- if (!res.data) return [];
- return res.data.map(item => item.keyword);
- } catch (e) {
- console.log(e);
- }
- },
- itemClick: function (keyword) {
- window.location.href = '/info/search-1.html?keyword=' + keyword + '&linkageFlag=1';
- }
- });
- },
- // 初始化链接参数
- initQueryParam() {
- if (isPC) {
- this.params.size = getUrlParam("pageSize") ? getUrlParam("pageSize") * 1 : 8;
- this.params.num = $("#pageNum").val() ? $("#pageNum").val() * 1 : 1;
- } else {
- this.params.size = 8;
- this.params.num = 1;
- }
- this.keyword = getUrlParam("keyword") ? getUrlParam("keyword") : '';
- this.params.linkageFlag = getUrlParam('linkageFlag') ? getUrlParam('linkageFlag') : 0
- this.params.keyword = this.keyword;
- },
- //初始化页面
- initBase: function () {
- this.params.typeId = $("#typeId").val() * 1;
- this.params.labelId = $("#labelId").val() * 1;
- if (!this.params.typeId) {
- $(".content").addClass("sea-top");
- }
- if (this.params.typeId) {
- this.requestType = 'typeId'
- } else if (this.params.labelId) {
- this.requestType = 'labelId'
- } else if (this.params.keyword) {
- this.requestType = 'keyword'
- $('#topSearch .keyword').val(this.params.keyword);
- $('.tip-bar').css('padding-bottom', 0);
- }
- this.requestAction(this.requestType);
- this.initPageReset();
- this.initSortControl();
- this.fetchProductList();
- },
- // 发起文章列表请求
- requestAction: function (type) {
- var requestAction = {
- 'typeId': this.initWithTypeId,
- 'labelId': this.initWithLabelId,
- 'keyword': this.initWithKeyword,
- };
- requestAction[type]();
- },
- // 文章分类查询列表
- initWithTypeId: function () {
- var params = {
- id: this.params.typeId,
- pageSize: this.params.size,
- pageNum: this.params.num,
- sortType: this.params.sortType
- }
- this.getArticleList(requestUrlConfig['typeId'], params);
- },
- //文章标签查询文章列表
- initWithLabelId: function () {
- var params = {
- id: this.params.labelId,
- pageSize: this.params.size,
- pageNum: this.params.num
- }
- this.getArticleList(requestUrlConfig['labelId'], params);
- },
- // 关键词查询文章列表
- initWithKeyword: function () {
- var params = {
- keyword: this.params.keyword,
- pageSize: this.params.size,
- pageNum: this.params.num,
- status: this.params.status,
- productFlag: this.params.productFlag, // 是否统计关键词 1 统计 2 不统计
- linkageFlag: this.params.linkageFlag // 关键词来源是否为用户搜索 0 是 1 不是
- }
- this.getArticleList(requestUrlConfig['keyword'], params);
- },
- // 弹窗缩放
- handlerPopup() {
- if (!this.dialogVisible) {
- this.dialogVisible = !this.dialogVisible;
- }
- },
- // 高亮关键词
- highlightKeyword: function (str) {
- return str.replace(new RegExp(this.keyword, 'g'), '<span style="color: #FF5B00">' + this.keyword + '</span>')
- },
- // 获取文章列表
- getArticleList: function (url, params, isSelect) {
- var self = this;
- $.getJSON(url, params, function (r) {
- if (r.code === 0 && r.data) {
- var result = JSON.parse(r.data);
- self.listRecord = result.total;
- var resultData = [];
- result.items.map(function (item) {
- resultData.push({
- id: item.articleId,
- title: item.title,
- image: item.image,
- intro: item.intro,
- typeId: item.typeId,
- type: item.typeText,
- labelIds: item.labelIds.replace(/[^[\d|\S]]*/g, ',').split(","),
- labels: item.labelText.replace(/[^[\d|\S]]*/g, ',').split(","),
- pv: item.pv,
- publisher: item.publisher,
- publishDate: item.publishDate
- });
- });
- // 处理标题和描述
- resultData = resultData.map(function (item) {
- item.title = self.highlightKeyword(item.title);
- item.intro = self.highlightKeyword(item.intro);
- return item
- });
- if (isPC) {
- self.listData = resultData
- } else {
- if (isSelect) {
- self.listData = resultData
- return
- }
- self.listData = self.listData.concat(resultData);
- }
- }
- self.listLoading = false;
- self.requestFlag = true;
- })
- },
- // 搜索
- onSearchEnter: function () {
- if (this.keyword === '') {
- $.confirm({
- useBootstrap: false,
- boxWidth: (isPC ? '300px' : '70%'),
- title: '提示',
- content: '请输入文章关键字!',
- closeIcon: true,
- animation: 'opacity',
- closeAnimation: 'opacity',
- animateFromElement: false,
- buttons: {
- close: {
- text: '确定',
- btnClass: 'btn-confirm'
- }
- }
- });
- return;
- }
- var query = param({
- keyword: this.keyword,
- })
- window.location.href = '/info/search-1.html?' + query;
- },
- // 页码跳转
- toPagination: function (pageNum) {
- if (pageNum <= this.pageTotal) {
- var params = {pageNum: pageNum};
- window.location.href = updateUrlParam(params);
- }
- },
- // 页码链接处理
- paginationUrl: function (pageNum) {
- var path = window.location.href;
- var paramsArr = window.location.pathname.split(".")[0].split("-");
- var pageId = paramsArr.length >= 1 ? paramsArr[1] : '';
- if (paramsArr[0].indexOf('/info/search') >= 0) {
- var search = window.location.search;
- path = '/info/search-' + pageNum + '.html' + search;
- } else if (paramsArr[0].indexOf('/info/center') >= 0) {
- path = '/info/center-' + pageId + '-' + pageNum + '.html';
- } else if (paramsArr[0].indexOf('/info/label') >= 0) {
- path = '/info/label-' + pageId + '-' + pageNum + '.html';
- }
- return path;
- },
- // 页面修改
- checkNum: function () {
- if (this.pageInput > this.pageTotal) {
- this.pageInput = this.pageTotal;
- } else if (this.pageInput < 1) {
- this.pageInput = 1;
- }
- },
- // 获取产品列表
- fetchProductList: function () {
- var self = this;
- ProductApi.GetProductSearchList({
- keyword: this.params.keyword,
- productFlag: 0, // 是否统计关键词 1 统计 0 不统计
- linkageFlag: 0 // 关键词来源是否为用户搜索 0 是 1 不是
- }, function (res) {
- res = JSON.parse(res.data);
- self.productRecord = res.total;
- if (res.total > 8) {
- self.productList = res.items.slice(0, 6);
- } else {
- self.productList = res.items.slice(0, 8);
- }
- })
- },
- // 初始化排序控件
- initSortControl: function () {
- var self = this;
- initFilterSort({
- el: '#searchSortControl',
- confirm(result) {
- console.log('确定')
- self.listLoading = true;
- self.requestFlag = false;
- self.listData = [];
- self.listRecord = 0;
- self.params.status = result.status;
- self.params.num = 1;
- self.requestAction(self.requestType);
- },
- })
- },
- onPageScroll: debounce(function () {
- var scrollTop = $('body').scrollTop();
- var documentHeight = $(document).height();
- var windowHeight = $('body').height();
- // alert(scrollTop + windowHeight == documentHeight)
- if (scrollTop > 600) {
- $('#scrollTop').show();
- } else {
- $('#scrollTop').hide();
- }
- // if (scrollTop + windowHeight + 100 > documentHeight) {
- // 此处是滚动条到底部时候触发的事件,在这里写要加载的数据,或者是拉动滚动条的操作
- // if (this.params.num < this.pageTotal) { // 获取列表数据
- // if (this.requestFlag) {
- // this.params.num = this.params.num + 1;
- // this.requestAction(this.requestType);
- // }
- // } else { //到底了
- // this.noMore = true;
- // $('footer').removeClass("noneImportant");
- // }
- // }
- }),
- //获取更多数据
- handleMore() {
- if (this.params.num < this.pageTotal) { // 获取列表数据
- if (this.requestFlag) {
- this.params.num = this.params.num + 1;
- this.requestAction(this.requestType);
- }
- } else { //到底了
- this.noMore = true;
- $('footer').removeClass("noneImportant");
- }
- },
- // 页面样式初始化
- initPageReset: function () {
- if (!isPC) {
- $('footer').addClass("noneImportant");
- //移动端上垃加载更多
- $('body').on('scroll', this.onPageScroll);
- }
- },
- // 文章列表切换 最新 最早
- selectListNew(e) {
- this.params.sortType = e
- this.params.size = 8
- this.params.num = 1
- let params = {
- id: this.params.typeId,
- pageSize: 8,
- pageNum: 1,
- sortType: this.params.sortType
- }
- this.getArticleList(requestUrlConfig['typeId'], params, true)
- },
- hanldDetails(id) {
- window.open('/news/details.html?id=' + id);
- },
- getNewList() {
- PublicApi.GetHomeInit({source: 1}, ({data}) => {
- if (isPC) {
- this.newsList = data.annlist
- } else {
- this.newsList = data.annlist.slice(0, 1)
- }
- });
- },
- // 供应商广告图统计
- setAdvStatistics ($event) {
- BeautyArchiveApi.GetStatisticsAddPv({type: 5, authorId: $event.id}, () => {
- console.log("供应商广告图点击统计成功")
- })
- if ($event.jumpLink) {
- window.open($event.jumpLink)
- }
- },
- openFullScreen1() {
- const _self = this
- const loading = this.$loading({
- lock: true,
- text: '',
- spinner: 'el-icon-loading',
- background: 'rgba(0, 0, 0, 0.2)'
- });
- setTimeout(() => {
- _self.isLoading = true;
- loading.close();
- }, 500);
- },
- },
- mounted () {
- this.openFullScreen1()
- }
- });
- function initFilterSort(option = {}) {
- var sortControl = $(option.el);
- var sortItem = sortControl.find('.search__sort_select li');
- var sotrCurrent = sortControl.find('.search__sort_current');
- $(window).on('click', function (el) {
- if (sortControl.has(el.target).length > 0) return;
- sortControl.removeClass('active');
- })
- sortControl.on('click', function () {
- $(this).toggleClass('active');
- })
- sortItem.on('click', function (el) {
- $(this).addClass('selected').siblings('li').removeClass('selected');
- var status = parseInt($(this).attr('data-type'));
- console.log(status)
- sotrCurrent.text($(this).text());
- option.confirm && option.confirm({status: status});
- })
- }
|