index.vue 3.5 KB

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