index.vue 12 KB

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