index.vue 12 KB

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