index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  1. <template>
  2. <view class="study">
  3. <view class="type-box">
  4. <view class="left">
  5. <view class="type-item" @click="handleType(singleType.id,singleType.secondaryImg)">
  6. <view class="glass" :style="{'--colour':singleType.colour}">
  7. <view class="title">
  8. {{singleType.columnName}}
  9. </view>
  10. <view class="type">
  11. {{singleType.columnMsg}}
  12. </view>
  13. </view>
  14. <image class="icon" :src="singleType.columnImg" mode="center"></image>
  15. </view>
  16. </view>
  17. <view class="right">
  18. <view class="type-item" v-for="item in typeList" :key="item.id" @click="handleType(item.id,item.secondaryImg)">
  19. <view class="glass" :style="{'--colour':item.colour}">
  20. <view class="title">
  21. {{item.columnName}}
  22. </view>
  23. <view class="type">
  24. {{item.columnMsg}}
  25. </view>
  26. </view>
  27. <image class="icon" :src="item.columnImg" mode="center"></image>
  28. </view>
  29. </view>
  30. </view>
  31. <swiper class="swiper" @change="swiperChange" :indicator-dots="true" circular :autoplay="true"
  32. :interval="3000" :duration="1000">
  33. <swiper-item v-for="(item,index) in bannerList" :key="index">
  34. <image class="swiper-item" mode="" :src="item.bannerImg">
  35. </image>
  36. </swiper-item>
  37. </swiper>
  38. <view class="type-title more-title">
  39. 互动社区
  40. <view class="more-box" @click="jump">
  41. <view>
  42. 更多
  43. </view>
  44. <image class="more" src="../static/jiantou-icon.png" mode=""></image>
  45. </view>
  46. </view>
  47. <scroll-view class="tab-box" enable-flex scroll-x >
  48. <view class="tab" :class="[tab == item.value?'active':'']" v-for="(item,index) in tabList" :key="index" @click="handleTab(item.value)">
  49. {{item.label}}
  50. </view>
  51. </scroll-view>
  52. <view class="list">
  53. <view class="item" v-for="item in communityList" :key="item.tabId" @click="goDetail(item)">
  54. <zs-img :src="item.coverImg" width="344rpx" height="256rpx"></zs-img>
  55. <view class="info">
  56. <view class="title">
  57. {{item.communityTitle}}
  58. </view>
  59. <view class="user-info">
  60. <image class="head" :src="require('@/static/logo.png')||item.publishLogo" mode=""></image>
  61. <view class="user-name">
  62. {{item.publishUser|| "官方"}}
  63. </view>
  64. </view>
  65. </view>
  66. </view>
  67. </view>
  68. <view class="type-title">
  69. 精选推荐
  70. </view>
  71. <!-- 列表 -->
  72. <zs-list class="store-box" mt="0" @load="loadMore" :status="status">
  73. <view class="left">
  74. <view class="store-item" v-for="(item,index) in list" :key="index" @click="goGoodsDetail(item.goodsId)">
  75. <zs-img :src="item.goodsImg" width="344rpx" height="256rpx" mode="widthFix"></zs-img>
  76. <view class="info">
  77. <view class="title">
  78. {{item.goodsName}}
  79. </view>
  80. <view class="user-info">
  81. <image class="head" :src="item.logoPath"></image>
  82. <view class="user-name">
  83. {{item.shopName}}
  84. </view>
  85. </view>
  86. </view>
  87. </view>
  88. </view>
  89. <view class="right">
  90. <view class="store-item" v-for="(item,index) in list1" :key="index" @click="goGoodsDetail(item.goodsId)">
  91. <zs-img :src="item.goodsImg" width="344rpx" height="256rpx" mode="widthFix"></zs-img>
  92. <view class="info">
  93. <view class="title">
  94. {{item.goodsName}}
  95. </view>
  96. <view class="user-info">
  97. <image class="head" :src="item.logoPath" mode=""></image>
  98. <view class="user-name">
  99. {{item.shopName}}
  100. </view>
  101. </view>
  102. </view>
  103. </view>
  104. </view>
  105. </zs-list>
  106. </view>
  107. </template>
  108. <script>
  109. import {getMenu,getTab,getItem,studyGoodsByUser,getResult} from '@/api/study.js';
  110. import {getBanner} from '@/api/common.js'
  111. export default {
  112. data() {
  113. return {
  114. status: 'more',
  115. singleType:{
  116. columnName: "",
  117. columnMsg: "",
  118. columnImg: "",
  119. },
  120. typeList:[],
  121. list: [],
  122. list1: [],
  123. communityList:[],
  124. bannerList:[],
  125. tab:0,
  126. tabList:[],
  127. userId:'',
  128. query:{userId:this.userId,currentPage:1,pageSize:10}
  129. }
  130. },
  131. methods: {
  132. // swiper变动
  133. swiperChange(val) {
  134. },
  135. handleType(id,img){
  136. uni.navigateTo({
  137. url:'/study/type?id='+id,
  138. success(res) {
  139. res.eventChannel.emit('img', img)
  140. }
  141. })
  142. },
  143. jump(){
  144. console.log(this.tab);
  145. uni.navigateTo({
  146. url:'/study/community/index?id='+this.tab
  147. })
  148. },
  149. // 点击社区tab
  150. handleTab(tab){
  151. this.tab = tab
  152. this.getItem(tab)
  153. },
  154. // 去社区
  155. goDetail(item){
  156. uni.navigateTo({
  157. url:'/study/community/detail?id='+item.tabId,
  158. success: function(res) {
  159. // 通过eventChannel向被打开页面传送数据
  160. res.eventChannel.emit('detail', item)
  161. }
  162. })
  163. },
  164. // 去商品详情
  165. goGoodsDetail(id){
  166. uni.navigateTo({
  167. url:'/study/studyGoodsDetail?id='+id
  168. })
  169. },
  170. loadMore() {
  171. this.studyGoodsByUser()
  172. },
  173. // 获取顶部栏目
  174. getMenu(){
  175. getMenu({currentPage:1,pageSize:5,userId:this.userId}).then(res=>{
  176. if(res.state == 'Success'){
  177. res.content.records.map((item,index)=>{
  178. if(index == 0){
  179. this.singleType = item
  180. }else{
  181. this.typeList.push(item)
  182. }
  183. })
  184. }
  185. })
  186. },
  187. // 获取banner
  188. getBanner(){
  189. getBanner({type:2}).then(res=>{
  190. if(res.state == 'Success'){
  191. this.bannerList = res.content.records
  192. }
  193. })
  194. },
  195. getTab(){
  196. getTab().then(res=>{
  197. if(res.state == 'Success'){
  198. for (const key in res.content) {
  199. if (Object.hasOwnProperty.call(res.content, key)) {
  200. this.tabList.push({
  201. value:Number(key),
  202. label:res.content[key]
  203. })
  204. }
  205. }
  206. this.tab = this.tabList[0].value
  207. this.getItem(this.tabList[0].value)
  208. }
  209. })
  210. },
  211. //获取社区分类列表
  212. getItem(communityId){
  213. getItem({communityId,currentPage:1,pageSize:2,state:2}).then(res=>{
  214. if(res.state == 'Success'){
  215. this.communityList = res.content.records
  216. }
  217. })
  218. },
  219. studyGoodsByUser(){
  220. this.status = 'loading'
  221. studyGoodsByUser(this.query).then(res=>{
  222. if(res.state == 'Success'){
  223. let list = []
  224. let list1 = []
  225. res.content.records.map((item,index)=>{
  226. if(index%2){
  227. list1.push(item)
  228. }else{
  229. list.push(item)
  230. }
  231. })
  232. this.list = this.list.concat(list)
  233. this.list1 = this.list1.concat(list1)
  234. let total = this.list.length+this.list1.length
  235. if(total>=res.content.total){
  236. this.status = 'noMore'
  237. }else{
  238. this.status = 'more'
  239. this.query.currentPage++
  240. }
  241. }
  242. })
  243. },
  244. // 获取测试结果
  245. getResult(){
  246. let userId = uni.getStorageSync('userInfo')?JSON.parse(uni.getStorageSync('userInfo')).userId:''
  247. getResult({userId}).then(r=>{
  248. if(!r.state == 'Success'||!r.content.resultMsg){
  249. uni.reLaunch({
  250. url:'/study/test'
  251. })
  252. }
  253. })
  254. }
  255. },
  256. created() {
  257. this.getMenu()
  258. this.getBanner()
  259. this.getTab()
  260. if(uni.getStorageSync('userInfo')){
  261. this.getResult()
  262. this.userId = JSON.parse(uni.getStorageSync('userInfo')).userId
  263. }
  264. }
  265. }
  266. </script>
  267. <style lang="scss" >
  268. .study {
  269. background: #FFFFFF;
  270. padding: 20rpx;
  271. .type-box{
  272. display: flex;
  273. justify-content: space-between;
  274. .left{
  275. width: 224rpx;
  276. }
  277. .right{
  278. display: flex;
  279. flex-wrap: wrap;
  280. justify-content: space-between;
  281. align-content: space-between;
  282. padding-left: 20rpx;
  283. .type-item{
  284. .icon{
  285. width: 224rpx;
  286. height: 124rpx;
  287. border-radius: 16rpx;
  288. vertical-align: bottom;
  289. }
  290. }
  291. }
  292. .type-item{
  293. position: relative;
  294. .glass{
  295. position: absolute;
  296. bottom: 0%;
  297. left: 0%;
  298. width: 100%;
  299. height: 72rpx;
  300. padding-left: 16rpx;
  301. box-sizing: border-box;
  302. border-radius:0 0 16rpx 16rpx;
  303. background: linear-gradient(180deg, rgba(0,188,255,0) 0%, var(--colour) 100%);
  304. .title{
  305. font-weight: bold;
  306. color: #FFFFFF;
  307. font-size: 24rpx;
  308. margin-top: 8rpx;
  309. }
  310. .type{
  311. font-weight: 400;
  312. color: #FFFFFF;
  313. font-size: 16rpx;
  314. margin-top: 6rpx;
  315. }
  316. }
  317. .icon{
  318. width: 224rpx;
  319. height: 268rpx;
  320. border-radius: 16rpx;
  321. vertical-align: bottom;
  322. }
  323. }
  324. }
  325. .swiper {
  326. height: 272rpx;
  327. border-radius: 16rpx;
  328. margin-top: 28rpx;
  329. .swiper-item {
  330. width: 100%;
  331. height: 100%;
  332. border-radius: 16rpx;
  333. object-fit: cover;
  334. }
  335. }
  336. .more-title{
  337. display: flex;
  338. justify-content: space-between;
  339. align-items: center;
  340. .more-box{
  341. display: flex;
  342. align-items: center;
  343. font-size: 24rpx;
  344. color: #AAAAAA;
  345. .more{
  346. width: 20rpx;
  347. height: 20rpx;
  348. display: block;
  349. margin-left: 6rpx;
  350. }
  351. }
  352. }
  353. .type-title{
  354. font-weight: bold;
  355. color: #222222;
  356. font-size: 32rpx;
  357. margin: 30rpx 0 20rpx;
  358. }
  359. .tab-box{
  360. display: flex;
  361. align-items: flex-start;
  362. .tab{
  363. flex-shrink: 0;
  364. padding: 10rpx 24rpx;
  365. color: #AAAAAA;
  366. background: #EEEEEE;
  367. font-size: 28rpx;
  368. margin-right: 20rpx;
  369. border-radius: 30rpx;
  370. }
  371. .tab.active{
  372. color: #3B83FF;
  373. background: #CEE0FF;
  374. }
  375. }
  376. .list{
  377. display: flex;
  378. justify-content: space-between;
  379. flex-wrap: wrap;
  380. .item{
  381. box-shadow: 0rpx 0rpx 24rpx 2rpx rgba(0,0,0,0.08);
  382. border-radius: 16rpx;
  383. width: 344rpx;
  384. height: 424rpx;
  385. margin-top: 20rpx;
  386. display: flex;
  387. flex-direction: column;
  388. .info{
  389. padding: 20rpx;
  390. flex: 1;
  391. display: flex;
  392. flex-direction: column;
  393. justify-content: space-between;
  394. .title{
  395. color: #222222;
  396. font-size: 24rpx;
  397. width: 100%;
  398. display: -webkit-box;
  399. -webkit-box-orient: vertical;
  400. -webkit-line-clamp: 2; /* 显示的最大行数 */
  401. overflow: hidden;
  402. }
  403. .user-info{
  404. display: flex;
  405. align-items: center;
  406. margin-top: 20rpx;
  407. .head{
  408. width: 40rpx;
  409. height: 40rpx;
  410. border-radius: 50%;
  411. }
  412. .user-name{
  413. color: #AAAAAA;
  414. font-size: 20rpx;
  415. margin-left: 12rpx;
  416. }
  417. }
  418. }
  419. }
  420. }
  421. .zs-list {
  422. display: flex;
  423. flex-wrap: wrap;
  424. justify-content: space-between;
  425. .left {
  426. }
  427. .right {
  428. }
  429. .store-item{
  430. box-shadow: 0rpx 0rpx 24rpx 2rpx rgba(0,0,0,0.08);
  431. border-radius: 16rpx;
  432. width: 344rpx;
  433. margin-top: 20rpx;
  434. .info{
  435. padding: 20rpx;
  436. .title{
  437. color: #222222;
  438. font-size: 24rpx;
  439. width: 100%;
  440. display: -webkit-box;
  441. -webkit-box-orient: vertical;
  442. -webkit-line-clamp: 2; /* 显示的最大行数 */
  443. overflow: hidden;
  444. }
  445. .user-info{
  446. display: flex;
  447. align-items: center;
  448. margin-top: 20rpx;
  449. .head{
  450. width: 40rpx;
  451. height: 40rpx;
  452. border-radius: 50%;
  453. }
  454. .user-name{
  455. color: #AAAAAA;
  456. font-size: 20rpx;
  457. margin-left: 12rpx;
  458. }
  459. }
  460. }
  461. }
  462. }
  463. }
  464. </style>