recommendation.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. var recommendation = new Vue({
  2. el: "#Recommendation",
  3. mixins: [cmSysVitaMixins],
  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.initData()
  72. },
  73. methods: {
  74. initData() {
  75. if (this.state === 2) {
  76. this.getNewList()
  77. } else {
  78. this.getArticlerecommendation(this.state)
  79. }
  80. },
  81. getArticlerecommendation: function (id, num) {
  82. var _self = this;
  83. if (isPC) {
  84. let paramsArr = window.location.pathname.split(".")[0].split("-");
  85. this.params.num = paramsArr[2]
  86. $.getJSON("/info/articlerecommendation/" + id + "/" + this.params.num, {}, function (r) {
  87. if (r.code === 0 && r.data) {
  88. _self.stateObj = r.data
  89. _self.articlerecommendationData = r.data.results;
  90. _self.listRecord = r.data.totalRecord
  91. }
  92. });
  93. } else {
  94. this.params.num = num || '1'
  95. $.getJSON("/info/articlerecommendation/" + id + "/" + this.params.num, {}, function (r) {
  96. console.log(r.data)
  97. if (r.code === 0 && r.data) {
  98. _self.stateObj = r.data
  99. _self.articlerecommendationData = [..._self.articlerecommendationData, ...r.data.results];
  100. _self.listRecord = r.data.totalRecord
  101. }
  102. });
  103. }
  104. },
  105. getNewList(num) {
  106. if (isPC) {
  107. let paramsArr = window.location.pathname.split(".")[0].split("-");
  108. this.params.num = paramsArr[2]
  109. const params = {
  110. pageSize: this.params.size,
  111. pageNum: this.params.num
  112. }
  113. PublicApi.GetNewsList(params, ({data}) => {
  114. this.listRecord = data.totalRecord
  115. this.listData = data.results
  116. })
  117. } else {
  118. this.params.num = num || '1'
  119. const params = {
  120. pageSize: this.params.size,
  121. pageNum: this.params.num
  122. }
  123. PublicApi.GetNewsList(params, ({data}) => {
  124. this.listRecord = data.totalRecord
  125. this.listData = [...this.listData, ...data.results]
  126. })
  127. }
  128. },
  129. //获取更多数据
  130. handleMore (num) {
  131. if (this.state===2) {
  132. if (this.params.num < this.pageTotal) { // 获取列表数据
  133. this.params.num = num
  134. this.getNewList(num);
  135. } else { //到底了
  136. this.noMore = false;
  137. }
  138. } else {
  139. this.params.num = num;
  140. this.getArticlerecommendation(this.state, num)
  141. if (num === this.stateObj.totalPage) {
  142. this.noMore = false;
  143. }
  144. }
  145. },
  146. // 页码链接处理
  147. paginationUrl (pageNum) {
  148. let path = window.location.href;
  149. const query = window.location.search
  150. let paramsArr = window.location.pathname.split(".")[0].split("-");
  151. let pageId = paramsArr.length >= 1 ? paramsArr[1] : '';
  152. path = '/info/articlerecommendation-' + pageId + '-' + pageNum + '.html';
  153. return path + query;
  154. },
  155. // 页面修改
  156. checkNum: function () {
  157. if (this.pageInput > this.pageTotal) {
  158. this.pageInput = this.pageTotal;
  159. } else if (this.pageInput < 1) {
  160. this.pageInput = 1;
  161. }
  162. },
  163. //页面跳转
  164. changeLink() {
  165. console.log(this.pageInput)
  166. if (this.state === 1) {
  167. window.location.href = '/info/articlerecommendation-1-' + this.pageInput + '.html?isSelected'
  168. } else {
  169. window.location.href = '/info/articlerecommendation-0-' + this.pageInput + '.html?isDocument'
  170. }
  171. },
  172. // 过滤标签
  173. filterTab(str) {
  174. return str.replace(/<[^>]+>/g, '')
  175. },
  176. // 数组
  177. filterArr(str) {
  178. return str.split(',')
  179. },
  180. // 链接跳转
  181. handleTramp(id) {
  182. if (this.state === 2) {
  183. window.location.href = '/news/details.html?id=' + id
  184. } else {
  185. window.location.href = '/info/detail-' + id + '-1.html'
  186. }
  187. },
  188. // 文件链接跳转
  189. handleFileUrl(id) {
  190. window.location.href = `/product-${id}.html?tabsIndex=4`
  191. // const fileUrl = url.split('?')[0]
  192. // let index = fileUrl.lastIndexOf('.');
  193. // let suffix = fileUrl.substring(index);
  194. // if (suffix === '.doc' || suffix === '.ppt' || suffix === '.pptx' || suffix === '.docx') {
  195. // window.open('https://view.officeapps.live.com/op/view.aspx?src=' + encodeURIComponent(url), '_black') // 下载
  196. // } else {
  197. // window.open(fileUrl, '_blank')
  198. // }
  199. }
  200. }
  201. })