index.vue 3.6 KB

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