hotProduct.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. // pages/hotProduct/hotProduct.js
  2. const api = require('../../api/index')
  3. import { $startWuxRefresher, $stopWuxRefresher,$stopWuxLoader} from '../../miniprogram_npm/wux-weapp/index'
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. keyword:'',
  10. tableData:[],
  11. queryParams:{
  12. current:1,
  13. size:10
  14. },
  15. total:25,
  16. loading:false,
  17. scrollTop: 0,
  18. },
  19. /**
  20. * 生命周期函数--监听页面加载
  21. */
  22. onLoad(options) {
  23. this.init()
  24. },
  25. /**
  26. * 生命周期函数--监听页面初次渲染完成
  27. */
  28. onReady() {
  29. },
  30. /**
  31. * 生命周期函数--监听页面显示
  32. */
  33. onShow() {
  34. },
  35. /**
  36. * 页面功能实现的区域
  37. */
  38. //初始化加载
  39. init(){
  40. var params = {
  41. current:1,
  42. size:10
  43. }
  44. this.setData(
  45. {
  46. queryParams:params,
  47. total:0,
  48. tableData:[]
  49. }
  50. )
  51. this.getProductList()
  52. },
  53. //下拉
  54. onPulling() {
  55. console.log('onPulling')
  56. },
  57. //下拉刷新
  58. onRefresh() {
  59. console.log('onRefresh')
  60. this.init()
  61. },
  62. //获取爆款产品
  63. getProductList(){
  64. var params = this.data.queryParams
  65. wx.showLoading({
  66. title: '加载中',
  67. })
  68. api.queryHotProduct(params).then(res=>{
  69. if(res.code == 200){
  70. if(res.data.data.length>0){
  71. var data = this.data.tableData.concat(res.data.data)
  72. this.setData(
  73. {
  74. tableData:data,
  75. total:res.data.total
  76. }
  77. )
  78. }
  79. setTimeout(() => {
  80. $stopWuxRefresher()
  81. }, 1000)
  82. }
  83. })
  84. },
  85. //加载更多
  86. loadMore(){
  87. var current = this.data.queryParams.current
  88. this.setData(
  89. {
  90. ['queryParams.current']:current+1
  91. }
  92. )
  93. this.getProductList()
  94. },
  95. //修改输入的关键词
  96. changeKeyword(e){
  97. this.setData(
  98. {
  99. keyword:e.detail
  100. }
  101. )
  102. },
  103. //检索
  104. search(e){
  105. },
  106. /**
  107. * 生命周期函数--监听页面隐藏
  108. */
  109. onHide() {
  110. },
  111. /**
  112. * 生命周期函数--监听页面卸载
  113. */
  114. onUnload() {
  115. },
  116. /**
  117. * 页面相关事件处理函数--监听用户下拉动作
  118. */
  119. onPullDownRefresh() {
  120. console.log('下拉')
  121. },
  122. /**
  123. * 页面上拉触底事件的处理函数
  124. */
  125. onReachBottom() {
  126. console.log('上拉')
  127. },
  128. /**
  129. * 用户点击右上角分享
  130. */
  131. onShareAppMessage() {
  132. }
  133. })