index.vue 2.4 KB

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