index.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /**
  2. * Copyright (C) 2018-2019
  3. * All rights reserved, Designed By www.joolun.com
  4. * 注意:
  5. * 本软件为www.joolun.com开发研制,项目使用请保留此说明
  6. */
  7. const app = getApp()
  8. Page({
  9. data: {
  10. config: app.globalData.config,
  11. page: {
  12. searchCount: false,
  13. current: 1,
  14. size: 10
  15. },
  16. loadmore: true,
  17. goodsList: [],
  18. goodsListNew: [],
  19. goodsListHot: [],
  20. swiperData: [
  21. 'https://joolun-base-test.oss-cn-zhangjiakou.aliyuncs.com/1/material/c888e1d3-f542-4b4e-aa43-be9d50cc0696.jpg',
  22. 'https://joolun-base-test.oss-cn-zhangjiakou.aliyuncs.com/1/material/a5e3b9f4-f1fe-4bb2-b487-13f4395ef187.jpg',
  23. 'https://joolun-base-test.oss-cn-zhangjiakou.aliyuncs.com/1/material/c8fd87ff-ca5d-4f95-8f81-e99cae48b0f7.jpg',
  24. 'https://joolun-base-test.oss-cn-zhangjiakou.aliyuncs.com/1/material/bf176bd5-3487-4b61-8d30-1cc2ad95b8ac.jpg'
  25. ],
  26. cardCur: 0,
  27. noticeData: []
  28. },
  29. onLoad() {
  30. app.initPage()
  31. .then(res => {
  32. this.loadData()
  33. })
  34. },
  35. onShow(){
  36. //更新tabbar购物车数量
  37. wx.setTabBarBadge({
  38. index: 2,
  39. text: app.globalData.shoppingCartCount + ''
  40. })
  41. },
  42. loadData(){
  43. this.goodsNew()
  44. this.goodsHot()
  45. this.goodsPage()
  46. },
  47. onShareAppMessage: function () {
  48. let title = 'JooLun商城源码-小程序演示'
  49. let path = 'pages/home/index'
  50. return {
  51. title: title,
  52. path: path,
  53. success: function (res) {
  54. if (res.errMsg == 'shareAppMessage:ok') {
  55. console.log(res.errMsg)
  56. }
  57. },
  58. fail: function (res) {
  59. // 转发失败
  60. }
  61. }
  62. },
  63. //新品首发
  64. goodsNew() {
  65. app.api.goodsPage({
  66. searchCount: false,
  67. current: 1,
  68. size: 5,
  69. descs: 'create_time'
  70. })
  71. .then(res => {
  72. let goodsListNew = res.data.records
  73. this.setData({
  74. goodsListNew: goodsListNew
  75. })
  76. })
  77. },
  78. //热销单品
  79. goodsHot() {
  80. app.api.goodsPage({
  81. searchCount: false,
  82. current: 1,
  83. size: 5,
  84. descs: 'sale_num'
  85. })
  86. .then(res => {
  87. let goodsListHot = res.data.records
  88. this.setData({
  89. goodsListHot: goodsListHot
  90. })
  91. })
  92. },
  93. goodsPage(e) {
  94. app.api.goodsPage(this.data.page)
  95. .then(res => {
  96. let goodsList = res.data.records
  97. this.setData({
  98. goodsList: [...this.data.goodsList, ...goodsList]
  99. })
  100. if (goodsList.length < this.data.page.size) {
  101. this.setData({
  102. loadmore: false
  103. })
  104. }
  105. })
  106. },
  107. refresh(){
  108. this.setData({
  109. loadmore: true,
  110. ['page.current']: 1,
  111. goodsList: [],
  112. goodsListNew: [],
  113. goodsListHot: []
  114. })
  115. this.loadData()
  116. },
  117. onPullDownRefresh(){
  118. // 显示顶部刷新图标
  119. wx.showNavigationBarLoading()
  120. this.refresh()
  121. // 隐藏导航栏加载框
  122. wx.hideNavigationBarLoading()
  123. // 停止下拉动作
  124. wx.stopPullDownRefresh()
  125. },
  126. onReachBottom() {
  127. if (this.data.loadmore) {
  128. this.setData({
  129. ['page.current']: this.data.page.current + 1
  130. })
  131. this.goodsPage()
  132. }
  133. },
  134. jumpPage(e){
  135. let page = e.currentTarget.dataset.page
  136. if (page){
  137. wx.navigateTo({
  138. url: page
  139. })
  140. }
  141. }
  142. })