index.vue 13 KB

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