index.vue 2.4 KB

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