index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  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. let userId = uni.getStorageSync('userInfo')?JSON.parse(uni.getStorageSync('userInfo')).userId:''
  176. getMenu({currentPage:1,pageSize:5,userId}).then(res=>{
  177. if(res.state == 'Success'){
  178. res.content.records.map((item,index)=>{
  179. if(index == 0){
  180. this.singleType = item
  181. }else{
  182. this.typeList.push(item)
  183. }
  184. })
  185. }
  186. })
  187. },
  188. // 获取banner
  189. getBanner(){
  190. getBanner({type:2}).then(res=>{
  191. if(res.state == 'Success'){
  192. this.bannerList = res.content.records
  193. }
  194. })
  195. },
  196. getTab(){
  197. getTab().then(res=>{
  198. if(res.state == 'Success'){
  199. for (const key in res.content) {
  200. if (Object.hasOwnProperty.call(res.content, key)) {
  201. this.tabList.push({
  202. value:Number(key),
  203. label:res.content[key]
  204. })
  205. }
  206. }
  207. this.tab = this.tabList[0].value
  208. this.getItem(this.tabList[0].value)
  209. }
  210. })
  211. },
  212. //获取社区分类列表
  213. getItem(communityId){
  214. getItem({communityId,currentPage:1,pageSize:2,state:2}).then(res=>{
  215. if(res.state == 'Success'){
  216. this.communityList = res.content.records
  217. }
  218. })
  219. },
  220. studyGoodsByUser(){
  221. this.status = 'loading'
  222. studyGoodsByUser(this.query).then(res=>{
  223. if(res.state == 'Success'){
  224. let list = []
  225. let list1 = []
  226. res.content.records.map((item,index)=>{
  227. if(index%2){
  228. list1.push(item)
  229. }else{
  230. list.push(item)
  231. }
  232. })
  233. this.list = this.list.concat(list)
  234. this.list1 = this.list1.concat(list1)
  235. let total = this.list.length+this.list1.length
  236. if(total>=res.content.total){
  237. this.status = 'noMore'
  238. }else{
  239. this.status = 'more'
  240. this.query.currentPage++
  241. }
  242. }
  243. })
  244. },
  245. // 获取测试结果
  246. getResult(){
  247. let userId = uni.getStorageSync('userInfo')?JSON.parse(uni.getStorageSync('userInfo')).userId:''
  248. getResult({userId}).then(r=>{
  249. if(!r.state == 'Success'||!r.content.resultMsg){
  250. uni.reLaunch({
  251. url:'/study/test'
  252. })
  253. }
  254. })
  255. }
  256. },
  257. created() {
  258. this.getMenu()
  259. this.getBanner()
  260. this.getTab()
  261. if(uni.getStorageSync('userInfo')){
  262. this.getResult()
  263. this.userId = JSON.parse(uni.getStorageSync('userInfo')).userId
  264. }
  265. }
  266. }
  267. </script>
  268. <style lang="scss" >
  269. .study {
  270. background: #FFFFFF;
  271. padding: 20rpx;
  272. .type-box{
  273. display: flex;
  274. justify-content: space-between;
  275. .left{
  276. width: 224rpx;
  277. }
  278. .right{
  279. display: flex;
  280. flex-wrap: wrap;
  281. justify-content: space-between;
  282. align-content: space-between;
  283. padding-left: 20rpx;
  284. .type-item{
  285. .icon{
  286. width: 224rpx;
  287. height: 124rpx;
  288. border-radius: 16rpx;
  289. vertical-align: bottom;
  290. }
  291. }
  292. }
  293. .type-item{
  294. position: relative;
  295. .glass{
  296. position: absolute;
  297. bottom: 0%;
  298. left: 0%;
  299. width: 100%;
  300. height: 72rpx;
  301. padding-left: 16rpx;
  302. box-sizing: border-box;
  303. border-radius:0 0 16rpx 16rpx;
  304. background: linear-gradient(180deg, rgba(0,188,255,0) 0%, var(--colour) 100%);
  305. .title{
  306. font-weight: bold;
  307. color: #FFFFFF;
  308. font-size: 24rpx;
  309. margin-top: 8rpx;
  310. }
  311. .type{
  312. font-weight: 400;
  313. color: #FFFFFF;
  314. font-size: 16rpx;
  315. margin-top: 6rpx;
  316. }
  317. }
  318. .icon{
  319. width: 224rpx;
  320. height: 268rpx;
  321. border-radius: 16rpx;
  322. vertical-align: bottom;
  323. }
  324. }
  325. }
  326. .swiper {
  327. height: 272rpx;
  328. border-radius: 16rpx;
  329. margin-top: 28rpx;
  330. .swiper-item {
  331. width: 100%;
  332. height: 100%;
  333. border-radius: 16rpx;
  334. object-fit: cover;
  335. }
  336. }
  337. .more-title{
  338. display: flex;
  339. justify-content: space-between;
  340. align-items: center;
  341. .more-box{
  342. display: flex;
  343. align-items: center;
  344. font-size: 24rpx;
  345. color: #AAAAAA;
  346. .more{
  347. width: 20rpx;
  348. height: 20rpx;
  349. display: block;
  350. margin-left: 6rpx;
  351. }
  352. }
  353. }
  354. .type-title{
  355. font-weight: bold;
  356. color: #222222;
  357. font-size: 32rpx;
  358. margin: 30rpx 0 20rpx;
  359. }
  360. .tab-box{
  361. display: flex;
  362. align-items: flex-start;
  363. .tab{
  364. flex-shrink: 0;
  365. padding: 10rpx 24rpx;
  366. color: #AAAAAA;
  367. background: #EEEEEE;
  368. font-size: 28rpx;
  369. margin-right: 20rpx;
  370. border-radius: 30rpx;
  371. }
  372. .tab.active{
  373. color: #3B83FF;
  374. background: #CEE0FF;
  375. }
  376. }
  377. .list{
  378. display: flex;
  379. justify-content: space-between;
  380. flex-wrap: wrap;
  381. .item{
  382. box-shadow: 0rpx 0rpx 24rpx 2rpx rgba(0,0,0,0.08);
  383. border-radius: 16rpx;
  384. width: 344rpx;
  385. height: 424rpx;
  386. margin-top: 20rpx;
  387. display: flex;
  388. flex-direction: column;
  389. .info{
  390. padding: 20rpx;
  391. flex: 1;
  392. display: flex;
  393. flex-direction: column;
  394. justify-content: space-between;
  395. .title{
  396. color: #222222;
  397. font-size: 24rpx;
  398. width: 100%;
  399. display: -webkit-box;
  400. -webkit-box-orient: vertical;
  401. -webkit-line-clamp: 2; /* 显示的最大行数 */
  402. overflow: hidden;
  403. }
  404. .user-info{
  405. display: flex;
  406. align-items: center;
  407. margin-top: 20rpx;
  408. .head{
  409. width: 40rpx;
  410. height: 40rpx;
  411. border-radius: 50%;
  412. }
  413. .user-name{
  414. color: #AAAAAA;
  415. font-size: 20rpx;
  416. margin-left: 12rpx;
  417. }
  418. }
  419. }
  420. }
  421. }
  422. .zs-list {
  423. display: flex;
  424. flex-wrap: wrap;
  425. justify-content: space-between;
  426. .left {
  427. }
  428. .right {
  429. }
  430. .store-item{
  431. box-shadow: 0rpx 0rpx 24rpx 2rpx rgba(0,0,0,0.08);
  432. border-radius: 16rpx;
  433. width: 344rpx;
  434. margin-top: 20rpx;
  435. .info{
  436. padding: 20rpx;
  437. .title{
  438. color: #222222;
  439. font-size: 24rpx;
  440. width: 100%;
  441. display: -webkit-box;
  442. -webkit-box-orient: vertical;
  443. -webkit-line-clamp: 2; /* 显示的最大行数 */
  444. overflow: hidden;
  445. }
  446. .user-info{
  447. display: flex;
  448. align-items: center;
  449. margin-top: 20rpx;
  450. .head{
  451. width: 40rpx;
  452. height: 40rpx;
  453. border-radius: 50%;
  454. }
  455. .user-name{
  456. color: #AAAAAA;
  457. font-size: 20rpx;
  458. margin-left: 12rpx;
  459. }
  460. }
  461. }
  462. }
  463. }
  464. }
  465. </style>