index.vue 13 KB

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