hotProduct.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. // pages/hotProduct/hotProduct.js
  2. const api = require('../../api/index')
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. keyword:'',
  9. tableData:[],
  10. queryParams:{
  11. current:1,
  12. size:10
  13. },
  14. total:25,
  15. triggered:false,
  16. load:false,
  17. hasMore:true,
  18. showDialog:false,
  19. showPopup:false,
  20. changeFollow:false,
  21. },
  22. /**
  23. * 生命周期函数--监听页面加载
  24. */
  25. onLoad(options) {
  26. this.init()
  27. },
  28. /**
  29. * 生命周期函数--监听页面初次渲染完成
  30. */
  31. onReady() {
  32. },
  33. /**
  34. * 生命周期函数--监听页面显示
  35. */
  36. onShow() {
  37. },
  38. /**
  39. * 页面功能实现的区域
  40. */
  41. //关注和监控
  42. closePopup(e){
  43. this.setData(
  44. {
  45. showPopup:false
  46. }
  47. )
  48. wx.nextTick(() => {
  49. this.setData({ changeFollow: false }) // 在当前同步流程结束后,下一个时间片执行
  50. })
  51. },
  52. openPopup(e){
  53. console.log(e)
  54. this.setData(
  55. {
  56. showPopup:true
  57. }
  58. )
  59. if(e.detail && e.detail.changeFollow){
  60. this.setData(
  61. {
  62. changeFollow:true
  63. }
  64. )
  65. }
  66. },
  67. attention(e){
  68. const childComponent = this.selectComponent('#myProduct');
  69. // var {type} = e.detail
  70. if (childComponent) {
  71. childComponent.attention(e); // 调用子组件的方法
  72. }
  73. },
  74. cancelFollow(e){
  75. const childComponent = this.selectComponent('#myProduct');
  76. // var {type} = e.detail
  77. if (childComponent) {
  78. childComponent.cancelFollow(e); // 调用子组件的方法
  79. }
  80. },
  81. //初始化加载
  82. init(){
  83. var params = {
  84. current:1,
  85. size:10
  86. }
  87. this.setData(
  88. {
  89. queryParams:params,
  90. total:0,
  91. tableData:[],
  92. hasMore:true
  93. }
  94. )
  95. this.getProductList()
  96. },
  97. //下拉刷新
  98. onRefresh() {
  99. console.log('onRefresh')
  100. this.init()
  101. this.setData({
  102. triggered: true,
  103. })
  104. },
  105. //获取爆款产品
  106. getProductList(){
  107. var params = this.data.queryParams
  108. wx.showLoading({
  109. title: '加载中',
  110. })
  111. api.queryHotProduct(params).then(res=>{
  112. if(res.code == 200){
  113. if(res.data.data.length>0){
  114. var data = this.data.tableData.concat(res.data.data)
  115. this.setData(
  116. {
  117. tableData:data,
  118. total:res.data.total
  119. }
  120. )
  121. }
  122. this.setData({
  123. triggered: false,
  124. load:false
  125. })
  126. if(this.data.total<=data.length){
  127. this.setData({
  128. hasMore:false
  129. })
  130. }
  131. }
  132. }).catch(error=>{
  133. this.setData({
  134. triggered: false,
  135. load:false
  136. })
  137. })
  138. },
  139. //加载更多
  140. loadMore(){
  141. var current = this.data.queryParams.current
  142. this.setData(
  143. {
  144. ['queryParams.current']:current+1,
  145. load :true
  146. }
  147. )
  148. this.getProductList()
  149. },
  150. //修改输入的关键词
  151. changeKeyword(e){
  152. this.setData(
  153. {
  154. keyword:e.detail
  155. }
  156. )
  157. },
  158. //检索
  159. search(e){
  160. },
  161. //打开提示框
  162. showTishi(){
  163. this.setData(
  164. {
  165. showDialog:true
  166. }
  167. )
  168. },
  169. closeDialog(){
  170. this.setData(
  171. {
  172. showDialog:false
  173. }
  174. )
  175. },
  176. /**
  177. * 生命周期函数--监听页面隐藏
  178. */
  179. onHide() {
  180. },
  181. /**
  182. * 生命周期函数--监听页面卸载
  183. */
  184. onUnload() {
  185. },
  186. /**
  187. * 页面相关事件处理函数--监听用户下拉动作
  188. */
  189. onPullDownRefresh() {
  190. console.log('下拉')
  191. },
  192. /**
  193. * 页面上拉触底事件的处理函数
  194. */
  195. onReachBottom() {
  196. console.log('上拉')
  197. },
  198. /**
  199. * 用户点击右上角分享
  200. */
  201. onShareAppMessage() {
  202. }
  203. })