index.vue 11 KB

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