contentList.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <template>
  2. <view>
  3. <view class="top-fixed">
  4. <view class="search-box ddflex">
  5. <view class="search-input ddflex fflex">
  6. <image src="/static/images/ssico.png"></image>
  7. <input @confirm="searchFn" confirm-type="search" @input="searchFn" v-model="searchVal" class="fflex"
  8. placeholder="请输入关键词" />
  9. </view>
  10. </view>
  11. <view class="rec-association" v-if="cateList.length>0" style="">
  12. <view class="dflex">
  13. <view class="rec-association-nav fflex">
  14. <scroll-view scroll-x="true" class="rec-association-scroll ddflex">
  15. <view :class="'rec-association-scroll-item tover '+(cIndex == index?'rec-association-scroll-item-active':'')" @click="getCon(item,index)" v-for="item,index in cateList" :key="index">{{item.name}}</view>
  16. </scroll-view>
  17. <view class="rec-association-nav-m"></view>
  18. </view>
  19. </view>
  20. </view>
  21. </view>
  22. <view :style="cateList.length>0?'height: 180rpx;':'height: 100rpx;'"></view>
  23. <view class="box">
  24. <!-- <view class="title dflex">{{title}}</view> -->
  25. <view class="rec" v-if="contentList.length>0">
  26. <navigator :url="'/topic/content/content?id=' + item.id" hover-class="none" class="li dflex" v-for="(item,index) in contentList" :key="index">
  27. <view class="flex">
  28. <view class="rec-tit tovers">{{item.title}}</view>
  29. <view class="dflex">
  30. <!-- <view class="author ddflex"><image src="../../static/pages/images/zbgw.png" mode="aspectFill"></image>欧衡</view> -->
  31. <view class="rec-time">{{item.createDate}}</view>
  32. </view>
  33. </view>
  34. <image :src="item.pic" mode="aspectFill" class="rec-img"></image>
  35. </navigator>
  36. </view>
  37. <view class="nodata" v-if="!contentList||contentList.length==0">
  38. <image :src="picUrlss+'empty_zb.png'"></image>
  39. <text>暂无资讯</text>
  40. </view>
  41. </view>
  42. </view>
  43. </template>
  44. <script>
  45. const req = require('../../utils/request.js');
  46. const api = require('../../utils/api.js');
  47. const util = require('../../utils/util.js');
  48. const app = getApp();
  49. export default {
  50. data() {
  51. return {
  52. picUrlss: req.public.picUrls,
  53. title: '',
  54. swiperCurrent: 0,
  55. bannerList: [],
  56. form: {
  57. page: 1,
  58. limit: 10
  59. },
  60. contentList: [],
  61. isLoad: true,
  62. code:null,
  63. cid:null,
  64. cateList:[],
  65. cIndex:0,
  66. searchVal:''
  67. };
  68. },
  69. async onLoad(options) {
  70. this.title = options.title;
  71. this.code = options.code;
  72. uni.setNavigationBarTitle({
  73. title: options.title
  74. })
  75. if(this.code)
  76. await this.getCate()
  77. this.getContentList();
  78. },
  79. onShow() {
  80. },
  81. onReachBottom(){
  82. this.form.page++;
  83. this.getContentList();
  84. },
  85. methods: {
  86. async getCon(item,index){
  87. this.cIndex = index;
  88. this.cid = item.id
  89. this.form.page = 1
  90. this.isLoad = true;
  91. this.getContentList();
  92. },
  93. // 获取分类
  94. getCate(){
  95. return new Promise((r,j)=>{
  96. req.getRequest('/api/content/category/list',{parentCode: this.code},res=>{
  97. this.cateList = res;
  98. // 如果有二级分类,清处code和noCode
  99. if(this.cateList&&this.cateList.length>0){
  100. this.cid = res[0].id
  101. this.code = null
  102. }
  103. r()
  104. })
  105. })
  106. },
  107. //为您推荐
  108. getContentList() {
  109. if (!this.isLoad) return false;
  110. this.isLoad = false;
  111. let form = this.form;
  112. form.code = this.code;
  113. // 如果有二级分类用分类id查
  114. if(this.cid){
  115. form.cid = this.cid
  116. }
  117. if(this.searchVal) form.title = this.searchVal
  118. else form.title = ''
  119. if(req.getStorage("shareId")){
  120. form.shareSaleNo = req.getStorage("shareId")
  121. }
  122. req.getRequest('/api/content/list', form,res => {
  123. res = res?res:[]
  124. if (res && res.length == 10) {
  125. this.isLoad = true;
  126. }
  127. if (this.form.page > 1) {
  128. res = this.contentList.concat(res);
  129. }
  130. this.contentList = res;
  131. });
  132. },
  133. searchFn(){
  134. this.form.page = 1
  135. this.isLoad = true;
  136. this.getContentList();
  137. }
  138. }
  139. };
  140. </script>
  141. <style>
  142. @import "./contentList.css";
  143. </style>