index.vue 12 KB

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