Information.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. <template>
  2. <view class="bg">
  3. <view class="head">
  4. <view class="search" style="margin-top: 10rpx;background: #F6F6F6;">
  5. <u-search bgColor='#F6F6F6' placeholder="请输入关键词"
  6. :showAction='false' @custom="searchList" v-model="searchword"></u-search>
  7. <view @click="searchList" class="searchBtn">搜索</view>
  8. <!-- <u-search @custom="searchList" placeholder="请输入关键词" v-model="searchword"></u-search> -->
  9. </view>
  10. <view class="margintb w750" >
  11. <view v-if="list1.length>0" class="w700">
  12. <u-tabs :current="tabCurrent" :list="list1" @change="tabsChange"></u-tabs>
  13. </view>
  14. <view @click="openMuen">
  15. <u--image width="40rpx" height="40rpx" src="/static/market/iconx__caidan1.png" ></u--image>
  16. </view>
  17. </view>
  18. <view class="list2">
  19. <view @click="changeType(index)"
  20. :class="item.plain ?'btnview': 'checkbtnview'"
  21. v-for="(item,index) in list2" :key="index">
  22. {{ item.name }}
  23. </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>
  32. </template>
  33. <script>
  34. import videoList from '@/pages/components/videoList.vue'
  35. import wenzhanList from '@/pages/components/wenzhanList.vue'
  36. import * as util from '@/pages/util/util.js'
  37. import {getMenuListByOpen,getArticleByOpen} from '@/http/api/common.js'
  38. export default {
  39. components: {
  40. videoList,
  41. wenzhanList,
  42. },
  43. data() {
  44. return {
  45. currentview:'wenzhanList',
  46. list1:[],
  47. list2:[],
  48. tabCurrent:0,
  49. pageNum:1,
  50. searchword:'',
  51. curNowid:'',
  52. curNowsubid:'',
  53. jiazaitext:'加载更多',
  54. newsList:[],
  55. loadingType:false,
  56. }
  57. },
  58. onReachBottom() {
  59. this.loadmore()
  60. },
  61. onUnload(){
  62. },
  63. async onLoad() {
  64. },
  65. async onShow(){
  66. let curNowdata = uni.getStorageSync('curNowdata')
  67. if (curNowdata&&curNowdata!='') {
  68. curNowdata = JSON.parse(curNowdata)
  69. this.curNowid = curNowdata?.curNowid || ''
  70. this.curNowsubid = curNowdata?.curNowsubid || ''
  71. this.tabCurrent = this.list1.findIndex(v => v.id == this.curNowid) || 0
  72. }else{
  73. this.tabCurrent = 0
  74. }
  75. await this.initData()
  76. uni.setStorageSync('curNowdata','')
  77. },
  78. methods: {
  79. async searchList(){
  80. // if (this.searchword == '') {
  81. // return
  82. // }
  83. //每次切换页签初始化请求页签
  84. this.pageNum = 1
  85. this.newsList = []
  86. //获取页签
  87. await this.getArticleList()
  88. },
  89. async initData(){
  90. //获取文章分类和数据
  91. let res = await getMenuListByOpen()
  92. if (res.data.code == 200 ) {
  93. this.list1 = res.data.data
  94. this.list1.push({
  95. name:'互动天地',
  96. id:'互动天地',
  97. })
  98. let defaultData = this.list1[0]//默认选中第一项
  99. if (this.curNowid!='') {
  100. console.log('this.curNowid',this.curNowid);
  101. //如果是从菜单选中跳过来的
  102. defaultData = this.list1.find(v => v.id == this.curNowid)
  103. // this.tabCurrent = this.list1.findIndex(v => v.id == this.curNowid) || 0
  104. }
  105. this.tabsChange(defaultData)
  106. }
  107. },
  108. //tab第一级页签选择
  109. tabsChange(e) {
  110. console.log('22222',e);
  111. if (e && e?.index) {
  112. this.tabCurrent = e.index
  113. }else{
  114. if (this.curNowid!='') {
  115. this.tabCurrent = this.list1.findIndex(v => v.id == this.curNowid) || 0
  116. }
  117. }
  118. if (e.id == '互动天地') {
  119. let curNowdata = {
  120. curNowid :this.curNowid,
  121. curNowsubid :this.curNowsubid
  122. }
  123. uni.setStorageSync('curNowdata',JSON.stringify(curNowdata));
  124. uni.navigateTo({
  125. url: '/pages/home/exchange'
  126. });
  127. return
  128. }
  129. //当前选中的id 存下来
  130. this.curNowid = e.id
  131. //切页签置空搜索
  132. this.searchword = ''
  133. if (e && e?.columnMenuSubList) {
  134. this.list2 = e.columnMenuSubList.map(v => {
  135. return {
  136. plain:true,
  137. ...v
  138. }
  139. })
  140. let defaultData = 0//默认选中第一项
  141. if (this.curNowsubid!='') {
  142. //如果是从菜单选中跳过来的
  143. defaultData = this.list2.findIndex(v => v.id == this.curNowsubid)
  144. }
  145. //默认获取第一项分类数据
  146. this.changeType(defaultData<0?0:defaultData)
  147. }else{
  148. util.toastFunc('获取分类失败')
  149. }
  150. },
  151. //第二级 子页签选择
  152. async changeType(index) {
  153. this.list2.forEach(item => {
  154. item.plain = true
  155. });
  156. this.list2[index].plain = false
  157. //当前选中的子页签id 存下来
  158. this.curNowsubid = this.list2[index].id
  159. if (this.list2[index].name == '视频资讯') {
  160. this.currentview = 'videoList'
  161. }else{
  162. this.currentview = 'wenzhanList'
  163. }
  164. //每次切换页签初始化请求页签
  165. this.pageNum = 1
  166. this.newsList = []
  167. //获取页签
  168. await this.getArticleList()
  169. },
  170. async getArticleList(){
  171. if (this.loadingType) {
  172. //加载中禁止重复加载
  173. return
  174. }
  175. this.loadingType=true
  176. let data = {
  177. subId:this.curNowsubid,
  178. pageNum:this.pageNum,
  179. titleLike:this.searchword,
  180. pageSize:10,
  181. }
  182. let res = await getArticleByOpen(data)
  183. if (res.data.code == 200) {
  184. let newrows = res.data.data?.rows || []
  185. this.newsList.push(...newrows)
  186. if(this.newsList.length!=res.data.data.total){
  187. this.jiazaitext="加载更多"
  188. }else{
  189. this.jiazaitext="已经到底"
  190. }
  191. }
  192. this.loadingType=false
  193. },
  194. //加载更多
  195. loadmore(){
  196. console.log('下拉加载',this.jiazaitext);
  197. if (this.jiazaitext=="加载更多") {
  198. this.pageNum=this.pageNum+1
  199. this.jiazaitext="加载中..."
  200. this.getArticleList()
  201. }
  202. },
  203. openMuen(){
  204. let curNowdata = {
  205. curNowid :this.curNowid,
  206. curNowsubid :this.curNowsubid
  207. }
  208. uni.setStorageSync('curNowdata',JSON.stringify(curNowdata) );
  209. uni.navigateTo({
  210. url: '/pages/home/allview?curNowid='+this.curNowid+'&curNowsubid='+this.curNowsubid
  211. });
  212. }
  213. }
  214. }
  215. </script>
  216. <style>
  217. .bg{
  218. background-color: #F6F6F6;
  219. width: 100vw;
  220. height: 100vh;
  221. }
  222. .head{
  223. display: flex;
  224. flex-direction: column;
  225. align-items: center;
  226. justify-content: center;
  227. background: #FFFFFF;
  228. opacity: 1;
  229. height: 340rpx;
  230. margin-bottom: 32rpx;
  231. }
  232. .u-notice-bar{
  233. width: 90vw;
  234. margin: 0 auto;
  235. }
  236. .u-search{
  237. width: 702rpx;
  238. margin: 0 auto;
  239. }
  240. .margintb{
  241. margin: 16rpx 0;
  242. display: flex;
  243. align-items: center;
  244. }
  245. .list2{
  246. display: flex;
  247. justify-content: flex-start;
  248. width: 90vw;
  249. overflow-x: auto;
  250. scroll-snap-type: x mandatory;
  251. scroll-padding: 50rpx; /* 为滚动容器提供内边距,确保内容不会紧贴边缘 */
  252. }
  253. .content{
  254. width: 100vw;
  255. background-color: #FFFFFF;
  256. padding: 30rpx 0 30rpx 0;
  257. }
  258. .box{
  259. display: flex;
  260. margin: 20rpx auto;
  261. justify-content: flex-start;
  262. width: 90vw;
  263. height: 160rpx;
  264. }
  265. .box_img{
  266. width: 224rpx;
  267. height: 150rpx;
  268. border-radius: 16rpx;
  269. background-color: #999999;
  270. }
  271. .box_right{
  272. margin-left: 10rpx;
  273. display: flex;
  274. flex-direction: column;
  275. justify-content: space-evenly;
  276. }
  277. .box_title{
  278. width: 454rpx;
  279. height: 80rpx;
  280. font-size: 28rpx;
  281. font-weight: bold;
  282. color: #333333;
  283. line-height: 40rpx;
  284. display: -webkit-box;
  285. word-break: break-all;
  286. text-overflow: ellipsis;
  287. overflow: hidden;
  288. -webkit-box-orient: vertical;
  289. -webkit-line-clamp:2;
  290. }
  291. .box_type{
  292. display: flex;
  293. justify-content: space-between;
  294. font-size: 28rpx;
  295. font-weight: 400;
  296. color: #999999;
  297. line-height: 40rpx;
  298. }
  299. .checkbtnview{
  300. width: 160rpx;
  301. height: 64rpx;
  302. background: #DEEEFC;
  303. border-radius: 40rpx 40rpx 40rpx 40rpx;
  304. opacity: 1;
  305. font-size: 28rpx;
  306. font-weight: 400;
  307. color: #46A6FF;
  308. line-height: 64rpx;
  309. text-align: center;
  310. margin-right: 20rpx;
  311. flex: 0 0 auto;
  312. scroll-snap-align: start;
  313. }
  314. .btnview{
  315. width: 160rpx;
  316. height: 64rpx;
  317. background: #F1F1F1;
  318. border-radius: 40rpx 40rpx 40rpx 40rpx;
  319. opacity: 1;
  320. font-size: 28rpx;
  321. font-weight: 400;
  322. color: #999;
  323. line-height: 64rpx;
  324. text-align: center;
  325. margin-right: 20rpx;
  326. flex: 0 0 auto;
  327. scroll-snap-align: start;
  328. }
  329. .loadmore{
  330. height:200rpx;
  331. text-align: center;
  332. font-size: 28rpx;
  333. font-weight: 400;
  334. color: #999;
  335. padding-top: 24rpx;
  336. }
  337. </style>