recommendation.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. var recommendation = new Vue({
  2. el: "#Recommendation",
  3. mixins: [cmSysVitaMixins,searchMixins],
  4. data: {
  5. status: {
  6. 'isDocument': 0, // 文件
  7. 'isSelected': 1, // 精选
  8. 'isNotice': 2, // 公告
  9. },
  10. state: null,
  11. params: {
  12. size: 10,
  13. num: 1,
  14. typeId: '',
  15. labelId: '',
  16. keyword: '',
  17. status: 1,
  18. startDate: '',
  19. endDate: '',
  20. productFlag: 1, // 是否统计关键词 1 统计 0 不统计
  21. linkageFlag: 0, // 关键词来源是否为用户搜索 0 是 1 不是
  22. selectDataRoutes: 1 // 最新 最早
  23. },
  24. listData: [],
  25. articlerecommendationData: [],
  26. listRecord: 0,
  27. productRecord: 0,
  28. productList: [],
  29. pageInput: '1',
  30. keyword: '',
  31. isRossShow: false,
  32. stateObj: {},
  33. noMore: true,
  34. },
  35. computed: {
  36. pageTotal: function () {
  37. let total = Math.ceil(this.listRecord / this.params.size);
  38. return total > 0 ? total : 1;
  39. },
  40. showPageBtn: function () {
  41. let total = Math.ceil(this.listRecord / this.params.size);
  42. total = total > 0 ? total : 1;
  43. let index = Number(this.params.num), arr = [];
  44. if (total <= 6) {
  45. for (let i = 1; i <= total; i++) {
  46. arr.push(i);
  47. }
  48. return arr;
  49. }
  50. if (index <= 3) return [1, 2, 3, 4, 5, 0, total];
  51. if (index >= total - 2) return [1, 0, total - 4, total - 3, total - 2, total - 1, total];
  52. return [1, 0, index - 2, index - 1, index, index + 1, index + 2, 0, total];
  53. },
  54. },
  55. watch: {
  56. 'window.location.pathname': {
  57. handler() {
  58. const query = window.location.search.split('?')[1]
  59. this.state = this.status[query]
  60. },
  61. deep: true,
  62. immediate: true
  63. }
  64. },
  65. filters: {
  66. filterDate(str) {
  67. return str.substring(0, 11)
  68. },
  69. },
  70. mounted() {
  71. this.openFullScreen1()
  72. this.initData()
  73. },
  74. methods: {
  75. openFullScreen1() {
  76. const _self = this
  77. const loading = this.$loading({
  78. lock: true,
  79. text: '',
  80. spinner: 'el-icon-loading',
  81. background: 'rgba(0, 0, 0, 0.2)'
  82. });
  83. setTimeout(() => {
  84. _self.isLoading = true;
  85. loading.close();
  86. }, 500);
  87. },
  88. initData() {
  89. if (this.state === 2) {
  90. this.getNewList()
  91. } else {
  92. this.getArticlerecommendation(this.state)
  93. }
  94. },
  95. getArticlerecommendation: function (id, num) {
  96. var _self = this;
  97. if (isPC) {
  98. let paramsArr = window.location.pathname.split(".")[0].split("-");
  99. this.params.num = paramsArr[2]
  100. $.getJSON("/info/articlerecommendation/" + id + "/" + this.params.num, {}, function (r) {
  101. if (r.code === 0 && r.data) {
  102. _self.stateObj = r.data
  103. _self.articlerecommendationData = r.data.results;
  104. _self.listRecord = r.data.totalRecord
  105. }
  106. });
  107. } else {
  108. this.params.num = num || '1'
  109. $.getJSON("/info/articlerecommendation/" + id + "/" + this.params.num, {}, function (r) {
  110. console.log(r.data)
  111. if (r.code === 0 && r.data) {
  112. _self.stateObj = r.data
  113. _self.articlerecommendationData = [..._self.articlerecommendationData, ...r.data.results];
  114. _self.listRecord = r.data.totalRecord
  115. }
  116. });
  117. }
  118. },
  119. getNewList(num) {
  120. if (isPC) {
  121. let paramsArr = window.location.pathname.split(".")[0].split("-");
  122. this.params.num = paramsArr[2]
  123. const params = {
  124. pageSize: this.params.size,
  125. pageNum: this.params.num
  126. }
  127. PublicApi.GetNewsList(params, ({data}) => {
  128. this.listRecord = data.totalRecord
  129. this.listData = data.results
  130. })
  131. } else {
  132. this.params.num = num || '1'
  133. const params = {
  134. pageSize: this.params.size,
  135. pageNum: this.params.num
  136. }
  137. PublicApi.GetNewsList(params, ({data}) => {
  138. this.listRecord = data.totalRecord
  139. this.listData = [...this.listData, ...data.results]
  140. })
  141. }
  142. },
  143. //获取更多数据
  144. handleMore (num) {
  145. if (this.state===2) {
  146. if (this.params.num < this.pageTotal) { // 获取列表数据
  147. this.params.num = num
  148. this.getNewList(num);
  149. } else { //到底了
  150. this.noMore = false;
  151. }
  152. } else {
  153. this.params.num = num;
  154. this.getArticlerecommendation(this.state, num)
  155. if (num === this.stateObj.totalPage) {
  156. this.noMore = false;
  157. }
  158. }
  159. },
  160. // 页码链接处理
  161. paginationUrl (pageNum) {
  162. let path = window.location.href;
  163. const query = window.location.search
  164. let paramsArr = window.location.pathname.split(".")[0].split("-");
  165. let pageId = paramsArr.length >= 1 ? paramsArr[1] : '';
  166. path = '/info/articlerecommendation-' + pageId + '-' + pageNum + '.html';
  167. return path + query;
  168. },
  169. // 页面修改
  170. checkNum: function () {
  171. if (this.pageInput > this.pageTotal) {
  172. this.pageInput = this.pageTotal;
  173. } else if (this.pageInput < 1) {
  174. this.pageInput = 1;
  175. }
  176. },
  177. //页面跳转
  178. changeLink() {
  179. console.log(this.pageInput)
  180. if (this.state === 1) {
  181. window.location.href = '/info/articlerecommendation-1-' + this.pageInput + '.html?isSelected'
  182. } else {
  183. window.location.href = '/info/articlerecommendation-0-' + this.pageInput + '.html?isDocument'
  184. }
  185. },
  186. // 过滤标签
  187. filterTab(str) {
  188. return str.replace(/<[^>]+>/g, '')
  189. },
  190. // 数组
  191. filterArr(str) {
  192. return str.split(',')
  193. },
  194. // 链接跳转
  195. handleTramp(id) {
  196. if (this.state === 2) {
  197. window.location.href = '/news/details.html?id=' + id
  198. } else {
  199. window.location.href = '/info/detail-' + id + '-1.html'
  200. }
  201. },
  202. // 文件链接跳转
  203. handleFileUrl(id) {
  204. window.location.href = `/product-${id}.html?tabsIndex=4`
  205. // const fileUrl = url.split('?')[0]
  206. // let index = fileUrl.lastIndexOf('.');
  207. // let suffix = fileUrl.substring(index);
  208. // if (suffix === '.doc' || suffix === '.ppt' || suffix === '.pptx' || suffix === '.docx') {
  209. // window.open('https://view.officeapps.live.com/op/view.aspx?src=' + encodeURIComponent(url), '_black') // 下载
  210. // } else {
  211. // window.open(fileUrl, '_blank')
  212. // }
  213. }
  214. }
  215. })