exchange.vue 6.8 KB

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