index.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <template>
  2. <view class="content">
  3. <u-swiper height="250" @click="clickBanner" :list="imageTopList"></u-swiper>
  4. <view class="t1">
  5. <u-image height="40" src="/static/t1.png"></u-image>
  6. </view>
  7. <!-- 商品 -->
  8. <view class="goods">
  9. <view v-for="(item,index) in goodsList" :key="index" v-if="goodsList.length&&item.list.length">
  10. <u-section :title="item.type.name" font-size="35" line-color="#01c9b2" sub-title="更多" @click="toGoods(item.type)"></u-section>
  11. <view class="goods-list">
  12. <uni-coods :goldLimit="item.type.goldLimit" :list="item.list"></uni-coods>
  13. </view>
  14. </view>
  15. <view v-if="goodsList.length==0">
  16. <u-empty icon-size="60" :text="noDataText" mode="list"></u-empty>
  17. </view>
  18. </view>
  19. <!-- 购物车 -->
  20. <uni-cart-fix :dragPic="dragPic"></uni-cart-fix>
  21. </view>
  22. </template>
  23. <script>
  24. import {
  25. getGoodsClass,
  26. getGoodsList
  27. } from '@/api/goods.js'
  28. import {bannerList} from '@/api/banner.js'
  29. export default {
  30. components: {
  31. },
  32. data() {
  33. return {
  34. noDataText: '正在加载...',
  35. imageTopList:[],
  36. goodsList:[], // 商品
  37. goodsType:[], // 商品分类
  38. dragPic: '/static/cart.png', // 购物车图标
  39. }
  40. },
  41. onLoad() {
  42. this.pageInit()
  43. },
  44. onUnload() {
  45. uni.$off('addCart')
  46. },
  47. // 下拉刷新
  48. onPullDownRefresh() {
  49. console.log('refresh')
  50. this.pageInit()
  51. setTimeout(function () {
  52. uni.stopPullDownRefresh()
  53. }, 200)
  54. },
  55. methods: {
  56. pageInit(){
  57. this.getbannerList()
  58. this.goodsList = []
  59. getGoodsClass({}).then(res => {
  60. console.log(res)
  61. if(res.status == 200){
  62. this.goodsType = res.data
  63. this.goodsType.map((item,index) => {
  64. this.getGoods(item,index)
  65. })
  66. }else{
  67. this.goodsList = []
  68. this.noDataText = '暂无商品'
  69. }
  70. })
  71. },
  72. // 点击banner
  73. clickBanner(index){
  74. let row = this.imageTopList[index]
  75. console.log(index,row)
  76. if(row.jumpType !== 'NONE'){
  77. // 跳外网地址
  78. if(row.jumpUrl.indexOf('http') == 0){
  79. }
  80. // 跳小程序页面
  81. if(row.jumpUrl.indexOf('/pages') == 0){
  82. uni.navigateTo({
  83. url: row.jumpUrl
  84. })
  85. }
  86. }
  87. },
  88. // 获取banner
  89. getbannerList(){
  90. bannerList({type:'banner',location:'MALL_TOP'}).then(res=>{
  91. if(res.status==200){
  92. this.imageTopList=res.data
  93. }
  94. })
  95. },
  96. // 更多商品
  97. toGoods(item){
  98. uni.navigateTo({
  99. url:"/pages/goods/goods?goodsTypeNo="+ item.goodsTypeNo + "&goldLimit="+ item.goldLimit + "&name=" + item.name
  100. })
  101. },
  102. // 查询商品
  103. getGoods(item,index){
  104. getGoodsList({pageNo:1,pageSize:item.popularizeGoodsLimit,goodsTypeNo:item.goodsTypeNo}).then(res => {
  105. console.log(res,'goodsList')
  106. if(res.status == 200&&res.data.list&&res.data.list.length){
  107. this.goodsList[index] = {
  108. type: item,
  109. list: res.data.list
  110. }
  111. this.goodsList.splice()
  112. }
  113. })
  114. }
  115. }
  116. }
  117. </script>
  118. <style lang="scss" scoped>
  119. .content {
  120. background: url(../../static/topBg.png) no-repeat top center;
  121. background-size: 100%;
  122. width: 100%;
  123. .goods{
  124. >view{
  125. padding: 25upx 20upx 10upx;
  126. background: #FFFFFF;
  127. border-radius: 15upx;
  128. box-shadow: 0upx 6upx 10upx #eee;
  129. margin-bottom: 20upx;
  130. > .goods-list{
  131. padding-top: 5upx;
  132. }
  133. }
  134. }
  135. .t1{
  136. padding: 20upx 0;
  137. }
  138. }
  139. </style>