index.vue 13 KB

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