index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  1. <template>
  2. <view class="core">
  3. <!-- nav -->
  4. <u-navbar leftIconSize="0" :placeholder="true" bgColor="#ffffff">
  5. <view class="u-nav-slot" slot="left">
  6. <text>商城</text>
  7. </view>
  8. </u-navbar>
  9. <!-- 固定顶部搜索、分类 -->
  10. <view class="fixed-top">
  11. <!-- 搜索 -->
  12. <view class="fixed-top-search flex">
  13. <view class="fixed-top-search__input flex">
  14. <u--input placeholder="请输入关键词进行搜索" border="none" prefixIcon="search" prefixIconStyle="font-size: 22px;color: #909399" />
  15. <view class="fixed-top-search__input__btn">搜索</view>
  16. </view>
  17. <image src="../../static/core/core_block.png" mode="scaleToFill" />
  18. </view>
  19. <view class="fixed-top-classify">
  20. <u-tabs @change="changeClassify" :scrollable="true" :list="classifyList" lineWidth="20" lineHeight="2"
  21. lineColor="#FF8D0B" :activeStyle="{
  22. color: '#333',
  23. transform: 'scale(1.1)'
  24. }" :inactiveStyle="{
  25. color: '#999',
  26. transform: 'scale(1.1)'
  27. }" itemStyle="padding-left: 15px; padding-right: 15px; height: 44px; text-align: center;">
  28. </u-tabs>
  29. </view>
  30. </view>
  31. <view class="core-none"></view>
  32. <!-- 轮播 -->
  33. <view class="core-swiper">
  34. <swiper class="core-swiper-centent" circular :indicator-dots="true" :autoplay="true" :interval="3000" indicator-active-color="#fff">
  35. <swiper-item class="swiper-item" v-for="(item, index) in swiperList" :key="index">
  36. <image :src="item.picUrl" mode=""></image>
  37. </swiper-item>
  38. </swiper>
  39. </view>
  40. <!-- 二级分类 -->
  41. <view class="core-category">
  42. <swiper class="core-category-swiper" :autoplay="false">
  43. <swiper-item class="swiper-item" v-for="(item, index) in classifyIndex == 0 ? classifyListFilter : classifyList[classifyIndex].list" :key="index">
  44. <view class="swiper-item__content" v-for="(items, indexs) in item" :key="indexs">
  45. <image :src="items.picUrl" mode="aspectFit"></image>
  46. <view class="name">{{ items.name }}</view>
  47. </view>
  48. </swiper-item>
  49. </swiper>
  50. </view>
  51. <!-- 标签商品 -->
  52. <view class="tag-goods" v-for="(item, index) in exclusiveSingle" :key="index">
  53. <view class="tag-goods-content">
  54. <view class="tag-goods-content-nav flex">
  55. <view class="tag-goods-content-nav__left flex">
  56. <image src="../../static/core/core_tag.png" mode=""></image>
  57. <view class="title">{{ item.name }}</view>
  58. <image src="../../static/core/core_tag.png" mode=""></image>
  59. </view>
  60. <view class="tag-goods-content-nav__right flex">
  61. <view class="title">更多</view>
  62. <image src="../../static/core/core_right.png" mode=""></image>
  63. </view>
  64. </view>
  65. <view class="tag-goods-content-list">
  66. <view class="tag-goods-content-list-item flex" v-for="(items, indexs) in item.data" :key="indexs">
  67. <view class="image flex">
  68. <image :src="items.picUrl" mode="aspectFit"></image>
  69. </view>
  70. <view class="title">{{ items.exchangePrice }}盲豆</view>
  71. </view>
  72. </view>
  73. </view>
  74. </view>
  75. <!-- 商品列表 -->
  76. <view class="core-goods">
  77. <view class="core-goods-list flex">
  78. <view class="core-goods-list-item flex" v-for="(item, index) in list" :key="index" @click="toGoodsDetail(item)">
  79. <view class="image-wrap flex">
  80. <image :src="item.picUrl" mode="aspectFit"></image>
  81. </view>
  82. <view class="content">
  83. <view class="content-title ells-one">{{ item.title }}</view>
  84. <view class="content-coin flex">
  85. <view class="content-coin__left flex">
  86. <image src="../../static/public/goods_coin.png" mode=""></image>
  87. <view class="num">×{{ item.exchangePrice }}</view>
  88. </view>
  89. <view class="content-coin__right" v-if="item.originPrice">原价:{{ item.originPrice }}</view>
  90. </view>
  91. <view class="content-price">¥{{ $numberFormat(item.value) }}</view>
  92. </view>
  93. </view>
  94. <view class="core-goods-list-item"></view>
  95. </view>
  96. </view>
  97. <custom-tab-bar :activeValue="'core'" />
  98. </view>
  99. </template>
  100. <script>
  101. import env from '../../config/env.js'
  102. import CustomTabBar from '../../components/custom-tab-bar/custom-tab-bar.vue'
  103. import $http from '@/utils/request.js'
  104. export default {
  105. components: {
  106. CustomTabBar,
  107. },
  108. data() {
  109. return {
  110. imgTop: [],
  111. goods: [],
  112. exclusive: [],
  113. exclusiveSingle: [],
  114. pageNum: 1,
  115. total: 0,
  116. list: [],
  117. /////////
  118. classifyList: [], // 分类列表
  119. classifyIndex: 0, // 分类选中下标
  120. classifyListFilter: [],
  121. swiperList: [], // 轮播图
  122. };
  123. },
  124. onLoad() {
  125. this.pageList()
  126. this.getExclusive()
  127. this.getClassify()
  128. this.getSwiper()
  129. },
  130. methods: {
  131. pageList() {
  132. this.pageNum = 1
  133. this.total = 0
  134. this.list = []
  135. this.getList()
  136. },
  137. // 获取分类
  138. getClassify() {
  139. $http.post('/api/v1/mp/user/exchange/category/listTree', {}).then(res => {
  140. if(res.code == 0){
  141. let interval = 10
  142. this.classifyList = res && res.rows
  143. this.classifyList.forEach(item => {
  144. item.picUrl = env.filePublic + item.picUrl.split(',')[0] + '?imageView2/2/w/340'
  145. item.goodsCategoryList.forEach(ele => {
  146. ele.picUrl = env.filePublic + ele.picUrl.split(',')[0] + '?imageView2/2/w/340'
  147. })
  148. item.list = []
  149. if(item.goodsCategoryList.length > interval) {
  150. let num = Math.ceil(item.goodsCategoryList.length / interval)
  151. let arr = []
  152. let a = 0
  153. let stop = interval
  154. for(let i = 1; i <= num; i++) {
  155. arr = item.goodsCategoryList.slice(a, stop)
  156. a = i * interval
  157. stop = stop + interval
  158. }
  159. } else {
  160. item.list.push(item.goodsCategoryList)
  161. }
  162. })
  163. if(this.classifyList.length > interval) {
  164. let num = Math.ceil(this.classifyList.length / interval)
  165. let arr = []
  166. let a = 0
  167. let stop = interval
  168. for(let i = 1; i <= num; i++) {
  169. arr = this.classifyList.slice(a, stop)
  170. a = i * interval
  171. stop = stop + interval
  172. this.classifyListFilter.push(arr)
  173. }
  174. } else {
  175. this.classifyListFilter =[ [ ...this.classifyList ] ]
  176. }
  177. this.classifyList.unshift({ name: '全部' })
  178. }
  179. })
  180. },
  181. //轮播图
  182. getSwiper() {
  183. $http.post(`/api/v1/mp/user/exchange/banner/list`, {
  184. noToken: true,
  185. location: "top"
  186. }).then(res => {
  187. res.data.forEach(item => item.picUrl = env.filePublic + item.picUrl.split(',')[0])
  188. this.swiperList = res.data
  189. })
  190. },
  191. // 标签商品
  192. async getExclusive() {
  193. let resData = await $http.post(`/api/v1/mp/user/exchange/activity/list`, {
  194. noToken: true
  195. })
  196. let goodsList = []
  197. for (let item of resData.data) {
  198. let resDatas = await $http.post(`/api/v1/mp/user/exchange/goods/list?pageNum=1&pageSize=4`, {
  199. noToken: true,
  200. tagIds: item.tagId
  201. })
  202. goodsList.push({
  203. data: resDatas.rows,
  204. name: item.name,
  205. tagId: item.tagId
  206. })
  207. }
  208. goodsList.forEach(item => {
  209. item.data.forEach(items => {
  210. items.picUrl = env.filePublic + items.picUrl.split(',')[0] + '?imageView2/2/w/340'
  211. })
  212. })
  213. this.exclusiveSingle = goodsList
  214. },
  215. // 商品列表
  216. getList() {
  217. uni.showLoading({
  218. title: '加载中'
  219. });
  220. let data = {
  221. categoryId: this.categoryId,
  222. tagIds: this.tagIds,
  223. ...this.coinNum,
  224. noToken: true
  225. }
  226. $http.post(`/api/v1/mp/user/exchange/goods/list?pageNum=${this.pageNum}&pageSize=20`,data).then(
  227. res => {
  228. uni.hideLoading();
  229. if (res.code == 0) {
  230. console.log("res: ",res);
  231. res.rows.forEach(item => {
  232. let picUrlArr = item.picUrl.split(',')
  233. item.picUrl = env.filePublic + picUrlArr[0] + '?imageView2/2/w/340'
  234. })
  235. this.total = res.total
  236. this.list = this.list.concat(res.rows)
  237. }
  238. }).catch(() => {
  239. uni.hideLoading();
  240. })
  241. },
  242. // 切换分类
  243. changeClassify(e) {
  244. console.log(e);
  245. this.classifyIndex = e.index
  246. console.log(this.classifyIndex);
  247. },
  248. // 跳转点击事件
  249. toCoreRange(type, data, name) {
  250. if (type == "link") {
  251. uni.navigateTo({
  252. url: `/packageOperate/webview/index?url=${ data }`,
  253. })
  254. } else {
  255. uni.navigateTo({
  256. url: `/packageGoods/core/index?type=${ type }&data=${ data }&name=${ name }`,
  257. })
  258. }
  259. },
  260. toGoodsDetail(item) {
  261. uni.navigateTo({
  262. url: `/packageGoods/goods/detail?id=${ item.goodsId }`
  263. })
  264. },
  265. },
  266. onReachBottom() {
  267. // 判断是否有数据
  268. if (this.total > this.pageNum * 20) {
  269. setTimeout(() => {
  270. ++this.pageNum
  271. this.getList()
  272. }, 500)
  273. } else {
  274. uni.$u.toast('已经到底了')
  275. }
  276. },
  277. onShareAppMessage(res) {
  278. return {
  279. title: '盲票,玩的就是有趣',
  280. path: '/pages/index/index',
  281. // imageUrl:'../../static/icon/lucky_bg.png',
  282. }
  283. }
  284. }
  285. </script>
  286. <style lang="scss" scoped>
  287. .core {
  288. background-color: #fff;
  289. &-none {
  290. height: 240rpx;
  291. }
  292. }
  293. // 固定搜索、分类
  294. .fixed-top {
  295. position: fixed;
  296. z-index: 100;
  297. width: 100%;
  298. background-color: #fff;
  299. // 搜索
  300. &-search {
  301. justify-content: space-between;
  302. padding: 14rpx 30rpx 34rpx;
  303. &__input {
  304. position: relative;
  305. flex: 1;
  306. height: 84rpx;
  307. padding-left: 46rpx;
  308. background: #F4F5F6;
  309. border-radius: 20rpx;
  310. &__btn {
  311. position: absolute;
  312. right: 0;
  313. width: 110rpx;
  314. height: 76rpx;
  315. line-height: 76rpx;
  316. font-size: 34rpx;
  317. text-align: center;
  318. font-weight: bold;
  319. color: #FFC062;
  320. background-color: #333333;
  321. border-radius: 18rpx;
  322. }
  323. }
  324. image {
  325. width: 52rpx;
  326. height: 52rpx;
  327. margin-left: 50rpx;
  328. }
  329. }
  330. // 分类
  331. &-classify {
  332. padding-bottom: 20rpx;
  333. }
  334. }
  335. // 轮播
  336. .core-swiper {
  337. margin-bottom: 20rpx;
  338. &-centent {
  339. height: 330rpx;
  340. .swiper-item {
  341. width: 100%;
  342. height: 100%;
  343. image {
  344. width: 100%;
  345. height: 100%;
  346. }
  347. }
  348. }
  349. }
  350. // 二级分类
  351. .core-category {
  352. width: 100%;
  353. height: 360rpx;
  354. margin-bottom: 34rpx;
  355. &-swiper {
  356. width: 100%;
  357. height: 100%;
  358. .swiper-item {
  359. width: 100%;
  360. height: 100%;
  361. display: flex;
  362. flex-wrap: wrap;
  363. &__content {
  364. display: flex;
  365. align-items: center;
  366. flex-direction: column;
  367. justify-content: space-between;
  368. width: 20%;
  369. height: 50%;
  370. image {
  371. width: 90%;
  372. height: 70%;
  373. }
  374. }
  375. }
  376. }
  377. }
  378. // 标签商品
  379. .tag-goods {
  380. border-top: 2px solid #191919;
  381. border-bottom: 2px solid #191919;
  382. padding: 4rpx 0;
  383. margin-bottom: 34rpx;
  384. &-content {
  385. background-color: #191919;
  386. padding: 26rpx 32rpx;
  387. &-nav {
  388. justify-content: space-between;
  389. height: 40rpx;
  390. margin-bottom: 34rpx;
  391. &__left {
  392. image {
  393. width: 40rpx;
  394. height: 30rpx;
  395. }
  396. .title {
  397. font-family: YouSheBiaoTiHei;
  398. font-weight: 400;
  399. font-size: 40rpx;
  400. color: #FFFFFF;
  401. padding: 0 36rpx;
  402. }
  403. }
  404. &__right {
  405. .title {
  406. font-family: YouSheBiaoTiHei;
  407. font-weight: 400;
  408. color: #FFFFFF;
  409. margin-right: 12rpx;
  410. }
  411. image {
  412. width: 22rpx;
  413. height: 20rpx;
  414. }
  415. }
  416. }
  417. &-list {
  418. display: flex;
  419. height: 260rpx;
  420. overflow-x: auto;
  421. &-item {
  422. flex-direction: column;
  423. margin-right: 14rpx;
  424. .image {
  425. width: 220rpx;
  426. height: 200rpx;
  427. background: #FFFFFF;
  428. box-shadow: 0px 0px 4px 0px rgba(100, 100, 100, 0.13);
  429. border-radius: 4rpx;
  430. margin-bottom: 24rpx;
  431. image {
  432. width: 100%;
  433. height: 100%;
  434. }
  435. }
  436. .title {
  437. text-align: center;
  438. line-height: 28rpx;
  439. color: #FFFFFF;
  440. }
  441. }
  442. }
  443. }
  444. }
  445. // 商品列表
  446. .core-goods {
  447. padding: 0 34rpx;
  448. &-list {
  449. width: 100%;
  450. justify-content: space-between;
  451. flex-wrap: wrap;
  452. &-item {
  453. flex-direction: column;
  454. justify-content: flex-start;
  455. width: 48%;
  456. // height: 520rpx;
  457. padding-bottom: 36rpx;
  458. background: #FFFFFF;
  459. box-shadow: 0px 0px 3px 0px rgba(100, 100, 100, 0.1);
  460. border-radius: 16rpx;
  461. margin-bottom: 30rpx;
  462. .image-wrap {
  463. width: 100%;
  464. height: 320rpx;
  465. margin-bottom: 18rpx;
  466. image {
  467. width: 100%;
  468. height: 100%;
  469. }
  470. }
  471. .content {
  472. width: 100%;
  473. padding: 0 22rpx;
  474. &-title {
  475. height: 28rpx;
  476. font-size: 28rpx;
  477. line-height: 28rpx;
  478. font-weight: bold;
  479. margin-bottom: 40rpx;
  480. }
  481. &-coin {
  482. height: 30rpx;
  483. font-size: 24rpx;
  484. justify-content: flex-start;
  485. margin-bottom: 34rpx;
  486. &__left {
  487. margin-right: 24rpx;
  488. image {
  489. width: 34rpx;
  490. height: 30rpx;
  491. }
  492. }
  493. &__right {
  494. color: #666666;
  495. text-decoration: line-through;
  496. }
  497. }
  498. &-price {
  499. font-size: 24rpx;
  500. color: #666666;
  501. }
  502. }
  503. }
  504. &-item:last-child {
  505. box-shadow: none;
  506. }
  507. }
  508. }
  509. </style>
  510. <style lang="scss" scoped>
  511. .u-nav-slot {
  512. text {
  513. font-size: 32rpx;
  514. }
  515. }
  516. </style>