index.vue 3.8 KB

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