index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  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.realPrice}}
  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.realPrice}}
  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:this.userId,currentPage:1,pageSize:10,belongType:2},
  125. background:false
  126. }
  127. },
  128. methods: {
  129. gotoPage(url){
  130. uni.navigateTo({
  131. url: url
  132. });
  133. },
  134. handleTest(){
  135. uni.navigateTo({
  136. url:'/study/test'
  137. })
  138. },
  139. // swiper变动
  140. swiperChange(val) {
  141. },
  142. handleType(id,{img,name}){
  143. uni.navigateTo({
  144. url:'/study/type?id='+id,
  145. success(res) {
  146. res.eventChannel.emit('img', img, name)
  147. }
  148. })
  149. },
  150. jump(){
  151. uni.navigateTo({
  152. url:'/study/community/index?id='+this.tab
  153. })
  154. },
  155. // 点击社区tab
  156. handleTab(tab){
  157. this.tab = tab
  158. this.getItem(tab)
  159. },
  160. // 去社区
  161. goDetail(item){
  162. uni.navigateTo({
  163. url:'/study/community/detail?id='+item.tabId,
  164. success: function(res) {
  165. // 通过eventChannel向被打开页面传送数据
  166. res.eventChannel.emit('detail', item)
  167. }
  168. })
  169. },
  170. // 去商品详情
  171. goGoodsDetail(id){
  172. uni.navigateTo({
  173. url:'/study/studyGoodsDetail?id='+id
  174. })
  175. },
  176. loadMore() {
  177. this.studyGoodsByUser()
  178. },
  179. // 获取顶部栏目
  180. getMenu(){
  181. let userId = uni.getStorageSync('userInfo')?JSON.parse(uni.getStorageSync('userInfo')).userId:''
  182. getMenu({currentPage:1,pageSize:5,userId,belongType:2}).then(res=>{
  183. if(res.state == 'Success'){
  184. this.typeList = res.content.records
  185. // const redRoad = this.typeList.find(item=>item.columnName == '红色革命');
  186. // // 把红色革命放到列表的第一个
  187. // if(redRoad){
  188. // this.typeList = this.typeList.filter(item=>item.columnName != '红色革命')
  189. // this.typeList.unshift(redRoad)
  190. // }
  191. }
  192. })
  193. },
  194. // 获取banner
  195. getBanner(){
  196. getBanner({type:2}).then(res=>{
  197. if(res.state == 'Success'){
  198. this.bannerList = res.content.records
  199. }
  200. })
  201. },
  202. getTab(){
  203. getTab().then(res=>{
  204. if(res.state == 'Success'){
  205. for (const key in res.content) {
  206. if (Object.hasOwnProperty.call(res.content, key)) {
  207. this.tabList.push({
  208. value:Number(key),
  209. label:res.content[key]
  210. })
  211. }
  212. }
  213. this.tab = this.tabList[0].value
  214. this.getItem(this.tabList[0].value)
  215. }
  216. })
  217. },
  218. //获取社区分类列表
  219. getItem(communityId){
  220. getItem({communityId,currentPage:1,pageSize:2,state:2}).then(res=>{
  221. if(res.state == 'Success'){
  222. this.communityList = res.content.records
  223. }
  224. })
  225. },
  226. studyGoodsByUser(){
  227. this.status = 'loading'
  228. studyGoodsByUser(this.query).then(res=>{
  229. if(res.state == 'Success'){
  230. let list = []
  231. let list1 = []
  232. res.content.records.map((item,index)=>{
  233. if(index%2){
  234. list1.push(item)
  235. }else{
  236. list.push(item)
  237. }
  238. })
  239. this.list = this.list.concat(list)
  240. this.list1 = this.list1.concat(list1)
  241. let total = this.list.length+this.list1.length
  242. if(total>=res.content.total){
  243. this.status = 'noMore'
  244. }else{
  245. this.status = 'more'
  246. this.query.currentPage++
  247. }
  248. }
  249. })
  250. },
  251. // 获取测试结果
  252. getResult(){
  253. let userId = uni.getStorageSync('userInfo')?JSON.parse(uni.getStorageSync('userInfo')).userId:''
  254. getResult({userId}).then(r=>{
  255. if(!r.state == 'Success'||!r.content.resultMsg){
  256. uni.reLaunch({
  257. url:'/study/test'
  258. })
  259. }
  260. })
  261. }
  262. },
  263. created() {
  264. this.getMenu()
  265. this.getBanner()
  266. this.getTab()
  267. if(uni.getStorageSync('userInfo')){
  268. this.getResult()
  269. this.userId = JSON.parse(uni.getStorageSync('userInfo')).userId
  270. }
  271. },
  272. onPageScroll(e) {
  273. if(e.scrollTop >= 50){
  274. this.background = true
  275. this.headerTitle = '慧研学'
  276. }else{
  277. this.background = false
  278. this.headerTitle = ''
  279. }
  280. },
  281. }
  282. </script>
  283. <style lang="scss" >
  284. .study {
  285. background: #F9F9F9;
  286. padding: 0 20rpx;
  287. .top-box{
  288. .bg{
  289. width: 750rpx;
  290. height: 480rpx;
  291. position: relative;
  292. left: -20rpx;
  293. border-radius: 0 0 5% 5%;
  294. }
  295. .type-box{
  296. display: flex;
  297. align-items: center;
  298. width: 710rpx;
  299. height: 228rpx;
  300. border-radius: 16rpx 16rpx 16rpx 16rpx;
  301. background: #FFFFFF;
  302. margin-top: -80rpx;
  303. position: relative;
  304. z-index: 2;
  305. .type-item{
  306. flex: 1;
  307. text-align: center;
  308. .icon{
  309. width: 80rpx;
  310. height: 80rpx;
  311. border-radius: 50%;
  312. }
  313. .label{
  314. font-weight: bold;
  315. font-size: 24rpx;
  316. color: #222222;
  317. margin-top: 15rpx;
  318. }
  319. }
  320. }
  321. }
  322. .swiper {
  323. height: 272rpx;
  324. border-radius: 16rpx;
  325. margin-top: 28rpx;
  326. .swiper-item {
  327. width: 100%;
  328. height: 100%;
  329. border-radius: 16rpx;
  330. object-fit: cover;
  331. }
  332. }
  333. .more-title{
  334. display: flex;
  335. justify-content: space-between;
  336. align-items: center;
  337. .more-box{
  338. display: flex;
  339. align-items: center;
  340. font-size: 24rpx;
  341. color: #AAAAAA;
  342. .more{
  343. width: 20rpx;
  344. height: 20rpx;
  345. display: block;
  346. margin-left: 6rpx;
  347. }
  348. }
  349. }
  350. .type-title{
  351. font-weight: bold;
  352. color: #222222;
  353. font-size: 32rpx;
  354. margin: 30rpx 0 20rpx;
  355. }
  356. .tab-box{
  357. display: flex;
  358. align-items: flex-start;
  359. .tab{
  360. flex-shrink: 0;
  361. padding: 10rpx 24rpx;
  362. margin-top: 28rpx;
  363. color: #AAAAAA;
  364. background: #EEEEEE;
  365. font-size: 28rpx;
  366. margin-right: 20rpx;
  367. border-radius: 8rpx;
  368. }
  369. .tab.active{
  370. color: #222222;
  371. // background: #CEE0FF;
  372. }
  373. }
  374. .list{
  375. display: flex;
  376. justify-content: space-between;
  377. flex-wrap: wrap;
  378. .item{
  379. box-shadow: 0rpx 0rpx 24rpx 2rpx rgba(0,0,0,0.08);
  380. border-radius: 16rpx;
  381. width: 344rpx;
  382. height: 566rpx;
  383. margin-top: 20rpx;
  384. display: flex;
  385. flex-direction: column;
  386. .info{
  387. padding: 20rpx;
  388. height: auto;
  389. flex: 1;
  390. display: flex;
  391. flex-direction: column;
  392. justify-content: space-between;
  393. .title{
  394. color: #222222;
  395. font-size: 28rpx;
  396. height: 76rpx;
  397. width: 100%;
  398. font-weight: bold;
  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: 24rpx;
  416. // 超出部分变成...
  417. display: -webkit-box;
  418. -webkit-box-orient: vertical;
  419. -webkit-line-clamp: 1;
  420. overflow: hidden;
  421. text-overflow: ellipsis;
  422. // margin-left: 12rpx;
  423. }
  424. }
  425. .price-box{
  426. display: flex;
  427. justify-content: space-between;
  428. align-items: center;
  429. margin-top: 12rpx;
  430. .left{
  431. display: flex;
  432. align-items: flex-end;
  433. .unit{
  434. font-size: 24rpx;
  435. color: $uni-color-primary;
  436. font-weight: bold;
  437. }
  438. .price{
  439. font-size: 32rpx;
  440. color: $uni-color-primary;
  441. font-weight: bold;
  442. }
  443. .old-price{
  444. font-size: 20rpx;
  445. color: #AAAAAA;
  446. text-decoration: line-through;
  447. margin-left: 10rpx;
  448. }
  449. }
  450. .right{
  451. font-size: 20rpx;
  452. color: #AAAAAA;
  453. }
  454. }
  455. }
  456. }
  457. }
  458. .zs-list {
  459. display: flex;
  460. flex-wrap: wrap;
  461. justify-content: space-between;
  462. .left {
  463. }
  464. .right {
  465. }
  466. .store-item{
  467. box-shadow: 0rpx 0rpx 24rpx 2rpx rgba(0,0,0,0.08);
  468. border-radius: 16rpx;
  469. width: 344rpx;
  470. height: 566rpx;
  471. margin-top: 20rpx;
  472. display: flex;
  473. flex-direction: column;
  474. .info{
  475. padding: 20rpx;
  476. flex: 1;
  477. display: flex;
  478. flex-direction: column;
  479. justify-content: space-between;
  480. .title{
  481. color: #222222;
  482. font-size: 28rpx;
  483. height: 76rpx;
  484. width: 100%;
  485. font-weight: bold;
  486. display: -webkit-box;
  487. -webkit-box-orient: vertical;
  488. -webkit-line-clamp: 2; /* 显示的最大行数 */
  489. overflow: hidden;
  490. }
  491. .user-info{
  492. display: flex;
  493. align-items: center;
  494. margin-top: 20rpx;
  495. .head{
  496. width: 40rpx;
  497. height: 40rpx;
  498. border-radius: 50%;
  499. }
  500. .user-name{
  501. color: #AAAAAA;
  502. font-size: 24rpx;
  503. overflow: hidden;
  504. text-overflow: ellipsis;
  505. display: -webkit-box;
  506. -webkit-box-orient: vertical;
  507. -webkit-line-clamp: 1;
  508. // margin-left: 12rpx;
  509. }
  510. }
  511. .price-box{
  512. display: flex;
  513. justify-content: space-between;
  514. align-items: center;
  515. margin-top: 12rpx;
  516. .left{
  517. display: flex;
  518. align-items: flex-end;
  519. .unit{
  520. font-size: 24rpx;
  521. color: $uni-color-primary;
  522. font-weight: bold;
  523. }
  524. .price{
  525. font-size: 32rpx;
  526. color: $uni-color-primary;
  527. font-weight: bold;
  528. }
  529. .old-price{
  530. font-size: 20rpx;
  531. color: #AAAAAA;
  532. text-decoration: line-through;
  533. margin-left: 10rpx;
  534. }
  535. }
  536. .right{
  537. font-size: 20rpx;
  538. color: #AAAAAA;
  539. }
  540. }
  541. }
  542. }
  543. }
  544. }
  545. </style>