exchange.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. <template>
  2. <view class="bg">
  3. <view class="head">
  4. <view v-if="list1.length>0" class="margintb">
  5. <u-tabs :current="tabCurrent" :list="list1" @click="tabsChange"></u-tabs>
  6. </view>
  7. <view class="search" style="margin-top: 10rpx;background: #F6F6F6;">
  8. <u-search bgColor='#F6F6F6' placeholder="请输入关键词"
  9. :showAction='false'
  10. @custom="searchList" v-model="searchword"></u-search>
  11. <view @click="searchList" class="searchBtn">搜索</view>
  12. </view>
  13. </view>
  14. <view>
  15. <exchangeItem :info="info" ></exchangeItem>
  16. </view>
  17. <view class="plbox">
  18. <view class="pl">{{total + ' '}}条互动</view>
  19. <view class="pl">{{mytotal + ' '}}我参与的</view>
  20. <view class="subsection" >
  21. <view :class="curNow==0?'checksub':'nocheck'" @click="sectionChange(0)">最新</view>
  22. <view :class="curNow==1?'checksub':'nocheck'" @click="sectionChange(1)">热门</view>
  23. </view>
  24. </view>
  25. <videoList v-if="currentview == 'videoList'" :listdata="newsList"></videoList>
  26. <wenzhanList v-if="currentview == 'wenzhanList'" :listdata="newsList"></wenzhanList>
  27. <view class="loadmore" @click="loadmore()" >
  28. {{jiazaitext}}
  29. </view>
  30. <view style="height:100rpx"></view>
  31. </view>
  32. </template>
  33. <script>
  34. import exchangeItem from '@/pages/components/exchange-item.vue'
  35. import videoList from '@/pages/components/videoList.vue'
  36. import wenzhanList from '@/pages/components/wenzhanList.vue'
  37. import * as util from '@/pages/util/util.js'
  38. import {moduleBySeven,getMenuListByOpen,joinCountByMe,contentPage} from '@/http/api/common.js'
  39. export default {
  40. components: {
  41. videoList,
  42. exchangeItem,
  43. wenzhanList
  44. },
  45. data() {
  46. return {
  47. info:[],
  48. currentview:'wenzhanList',
  49. list1:[],
  50. list2:[],
  51. tabCurrent:0,
  52. pageNum:1,
  53. searchword:'',
  54. curNowid:'',
  55. curNowsubid:'',
  56. jiazaitext:'加载更多',
  57. newsList:[],
  58. num:999,
  59. curNow:0,
  60. total:0,
  61. mytotal:0,
  62. subsectionlist: [
  63. {
  64. name: '热门'
  65. },
  66. {
  67. name: '最新'
  68. }
  69. ],
  70. loadingType:false,
  71. }
  72. },
  73. onReachBottom() {
  74. this.loadmore()
  75. },
  76. onLoad(e) {
  77. this.getmoduleBySeven()
  78. this.initData()
  79. },
  80. methods: {
  81. sectionChange(index) {
  82. console.log(index);
  83. this.curNow = index;
  84. //每次切换页签初始化请求页签
  85. this.pageNum = 1
  86. this.newsList = []
  87. this.getArticleList()
  88. },
  89. async getmoduleBySeven(){
  90. //获取模块7
  91. let res = await moduleBySeven()
  92. if (res.data.code == 200) {
  93. this.info = res.data.data.contentVoList
  94. }
  95. },
  96. async searchList(){
  97. // if (this.searchword == '') {
  98. // return
  99. // }
  100. //每次切换页签初始化请求页签
  101. this.pageNum = 1
  102. this.newsList = []
  103. //获取页签
  104. await this.getArticleList()
  105. },
  106. async initData(){
  107. //获取文章分类和数据
  108. let res = await getMenuListByOpen()
  109. if (res.data.code == 200 ) {
  110. this.list1 = res.data.data
  111. let defaultData = this.list1[0]//默认选中第一项
  112. if (this.curNowid!='') {
  113. //如果是从菜单选中跳过来的
  114. defaultData = this.list1.find(v => v.id == this.curNowid)
  115. this.tabCurrent = this.list1.findIndex(v => v.id == this.curNowid)
  116. }
  117. this.tabsChange(defaultData)
  118. }
  119. },
  120. //tab第一级页签选择
  121. tabsChange(e) {
  122. //当前选中的id 存下来
  123. this.curNowid = e.id
  124. //切页签置空搜索
  125. this.searchword = ''
  126. //每次切换页签初始化请求页签
  127. this.pageNum = 1
  128. this.newsList = []
  129. if (e && e?.columnMenuSubList) {
  130. this.list2 = e.columnMenuSubList.map(v => {
  131. return {
  132. plain:true,
  133. ...v
  134. }
  135. })
  136. if (this.list2[0].name == '视频资讯') {
  137. this.currentview = 'videoList'
  138. }else{
  139. this.currentview = 'wenzhanList'
  140. }
  141. //直接获取模块列表
  142. this.getArticleList()
  143. }else{
  144. util.toastFunc('获取分类失败')
  145. }
  146. },
  147. async getArticleList(){
  148. if (this.loadingType) {
  149. //加载中禁止重复加载
  150. return
  151. }
  152. this.loadingType=true
  153. let data = {
  154. columnId:this.curNowid,
  155. pageNum:this.pageNum,
  156. titleLike:this.searchword,
  157. pageSize:10,
  158. }
  159. // 1=热门回答;2=最新回答;3=带解答?暂时改成我的提问
  160. let res = await contentPage(data,this.curNow==0?'2':'1')
  161. if (res.data.code == 200) {
  162. //总条数
  163. this.total = res.data.data?.total
  164. // 我参与的
  165. if (uni.getStorageSync('AppAuthorization')) {
  166. let res2 = await joinCountByMe()
  167. this.mytotal = res2?.data?.data || 0
  168. }
  169. let newrows = res.data.data?.rows || []
  170. this.newsList.push(...newrows)
  171. if(this.newsList.length!=res.data.data.total){
  172. this.jiazaitext="加载更多"
  173. }else{
  174. this.jiazaitext="已经到底"
  175. }
  176. }
  177. this.loadingType=false
  178. },
  179. //加载更多
  180. loadmore(){
  181. console.log('下拉加载',this.jiazaitext);
  182. if (this.jiazaitext=="加载更多") {
  183. this.pageNum=this.pageNum+1
  184. this.jiazaitext="加载中..."
  185. this.getArticleList()
  186. }
  187. },
  188. }
  189. }
  190. </script>
  191. <style>
  192. .bg{
  193. background-color: #F6F6F6;
  194. width: 100vw;
  195. height: 100vh;
  196. }
  197. .head{
  198. display: flex;
  199. flex-direction: column;
  200. align-items: center;
  201. justify-content: center;
  202. background: #FFFFFF;
  203. opacity: 1;
  204. height: 240rpx;
  205. }
  206. .u-notice-bar{
  207. width: 90vw;
  208. margin: 0 auto;
  209. }
  210. .u-search{
  211. width: 90vw;
  212. }
  213. .margintb{
  214. margin: 16rpx 0;
  215. }
  216. .list2{
  217. display: flex;
  218. justify-content: space-around;
  219. width: 90vw;
  220. }
  221. .content{
  222. width: 100vw;
  223. background-color: #FFFFFF;
  224. padding: 30rpx 0 30rpx 0;
  225. }
  226. .loadmore{
  227. height:200rpx;
  228. text-align: center;
  229. font-size: 28rpx;
  230. font-weight: 400;
  231. color: #999;
  232. padding-top: 24rpx;
  233. }
  234. .plbox{
  235. width: 750rpx;
  236. background: #FFF;
  237. display: flex;
  238. justify-content: space-evenly;
  239. align-items: center;
  240. padding-top: 24rpx;
  241. }
  242. .pl{
  243. width: 170rpx;
  244. height: 45rpx;
  245. font-size: 28rpx;
  246. font-weight: 400;
  247. color: #666;
  248. line-height: 36rpx;
  249. }
  250. </style>