index.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. // 下拉刷新
  45. onPullDownRefresh() {
  46. console.log('refresh')
  47. this.pageInit()
  48. setTimeout(function () {
  49. uni.stopPullDownRefresh()
  50. }, 200)
  51. },
  52. methods: {
  53. pageInit(){
  54. this.getbannerList()
  55. this.goodsList = []
  56. getGoodsClass({}).then(res => {
  57. console.log(res)
  58. if(res.status == 200){
  59. this.goodsType = res.data
  60. this.goodsType.map((item,index) => {
  61. this.getGoods(item,index)
  62. })
  63. }else{
  64. this.goodsList = []
  65. this.noDataText = '暂无商品'
  66. }
  67. })
  68. },
  69. // 点击banner
  70. clickBanner(index){
  71. let row = this.imageTopList[index]
  72. console.log(index,row)
  73. if(row.jumpType !== 'NONE'){
  74. // 跳外网地址
  75. if(row.jumpUrl.indexOf('http') == 0){
  76. }
  77. // 跳小程序页面
  78. if(row.jumpUrl.indexOf('/pages') == 0){
  79. uni.navigateTo({
  80. url: row.jumpUrl
  81. })
  82. }
  83. }
  84. },
  85. // 获取banner
  86. getbannerList(){
  87. bannerList({type:'banner',location:'MALL_TOP'}).then(res=>{
  88. if(res.status==200){
  89. this.imageTopList=res.data
  90. }
  91. })
  92. },
  93. // 更多商品
  94. toGoods(item){
  95. uni.navigateTo({
  96. url:"/pages/goods/goods?goodsTypeNo="+ item.goodsTypeNo + "&goldLimit="+ item.goldLimit + "&name=" + item.name
  97. })
  98. },
  99. // 查询商品
  100. getGoods(item,index){
  101. getGoodsList({pageNo:1,pageSize:item.popularizeGoodsLimit,goodsTypeNo:item.goodsTypeNo}).then(res => {
  102. console.log(res,'goodsList')
  103. if(res.status == 200&&res.data.list&&res.data.list.length){
  104. this.goodsList[index] = {
  105. type: item,
  106. list: res.data.list
  107. }
  108. this.goodsList.splice()
  109. }
  110. })
  111. }
  112. }
  113. }
  114. </script>
  115. <style lang="scss" scoped>
  116. .content {
  117. background: url(../../static/topBg.png) no-repeat top center;
  118. background-size: 100%;
  119. width: 100%;
  120. .goods{
  121. >view{
  122. padding: 25upx 20upx 10upx;
  123. background: #FFFFFF;
  124. border-radius: 15upx;
  125. box-shadow: 0upx 6upx 10upx #eee;
  126. margin-bottom: 20upx;
  127. > .goods-list{
  128. padding-top: 5upx;
  129. }
  130. }
  131. }
  132. .t1{
  133. padding: 20upx 0;
  134. }
  135. }
  136. </style>