index.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <template>
  2. <view class="content">
  3. <u-swiper height="250" :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="item.type.id" v-if="goodsList.length&&item.list.length">
  10. <u-section :title="item.type.name" line-color="#01c9b2" sub-title="更多" @click="toGoods(item.type)"></u-section>
  11. <view class="goods-list">
  12. <uni-coods :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></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. }
  39. },
  40. onShow() {
  41. this.getbannerList()
  42. this.goodsList = []
  43. getGoodsClass({}).then(res => {
  44. console.log(res)
  45. if(res.status == 200){
  46. this.goodsType = res.data
  47. this.goodsType.map((item,index) => {
  48. this.getGoods(item,index)
  49. })
  50. }else{
  51. this.goodsList = []
  52. this.noDataText = '暂无商品'
  53. }
  54. })
  55. },
  56. methods: {
  57. // 获取banner
  58. getbannerList(){
  59. bannerList({type:'banner',location:'MALL_TOP'}).then(res=>{
  60. if(res.status==200){
  61. this.imageTopList=res.data
  62. }
  63. })
  64. },
  65. // 更多商品
  66. toGoods(item){
  67. uni.navigateTo({
  68. url:"/pages/goods/goods?goodsTypeNo="+ item.goodsTypeNo + "&goldLimit="+ item.goldLimit
  69. })
  70. },
  71. // 查询商品
  72. getGoods(item,index){
  73. getGoodsList({pageNo:1,pageSize:item.popularizeGoodsLimit,goodsTypeNo:item.goodsTypeNo}).then(res => {
  74. console.log(res,'goodsList')
  75. if(res.status == 200&&res.data.list&&res.data.list.length){
  76. this.goodsList.push({
  77. type: item,
  78. list: res.data.list
  79. })
  80. this.goodsList.splice()
  81. }
  82. })
  83. }
  84. }
  85. }
  86. </script>
  87. <style lang="scss" scoped>
  88. .content {
  89. background: url(../../static/topBg.png) no-repeat top center;
  90. background-size: 100%;
  91. width: 100%;
  92. .goods{
  93. >view{
  94. padding: 25upx 20upx 10upx;
  95. background: #FFFFFF;
  96. border-radius: 15upx;
  97. box-shadow: 0upx 6upx 10upx #eee;
  98. margin-bottom: 20upx;
  99. > .goods-list{
  100. padding-top: 5upx;
  101. }
  102. }
  103. }
  104. .t1{
  105. padding: 20upx 0;
  106. }
  107. }
  108. </style>