index.vue 13 KB

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