business.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. const pages = require('../../mixin/pages')
  2. const { getProductCategoryList } = require('../../api/common')
  3. const { debounce } = require('../../utils/util')
  4. const app = getApp()
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. ...pages.data(),
  11. listUrl: '/api/user/home/shop/list',
  12. searchForm: {
  13. key_words: '',
  14. category_id: '',
  15. shop_type: ''
  16. },
  17. categoryList: [],
  18. navScrollLeft: -1,
  19. booLock: false,
  20. booPopop: false,
  21. arrShopType: app.globalData.arrShopType,
  22. shop_type: [],
  23. handleShoptype: null
  24. },
  25. ...pages.methods,
  26. /**
  27. * 生命周期函数--监听页面加载
  28. */
  29. async onLoad(options) {
  30. await this.fetchProductCategoryList()
  31. this.fetchOrderList()
  32. this.setData({
  33. handleShoptype: debounce(this.refreshOrderList, 2500)
  34. })
  35. },
  36. /**
  37. * 生命周期函数--监听页面初次渲染完成
  38. */
  39. onReady() {
  40. },
  41. /**
  42. * 生命周期函数--监听页面显示
  43. */
  44. onShow() {
  45. },
  46. /**
  47. * 生命周期函数--监听页面隐藏
  48. */
  49. onHide() {
  50. },
  51. /**
  52. * 生命周期函数--监听页面卸载
  53. */
  54. onUnload() {
  55. },
  56. /**
  57. * 页面相关事件处理函数--监听用户下拉动作
  58. */
  59. onPullDownRefresh() {
  60. if (this.data.freshing) {
  61. return
  62. }
  63. this.setData({
  64. freshing: true
  65. })
  66. this.bindCallBack()
  67. },
  68. /**
  69. * 页面上拉触底事件的处理函数
  70. */
  71. onReachBottom() {
  72. this.fetchOrderList()
  73. },
  74. bindCallBack() {
  75. this.refreshOrderList()
  76. },
  77. async fetchProductCategoryList() {
  78. try {
  79. const { status, data, msg } = await getProductCategoryList()
  80. if (status && Array.isArray(data) && data.length > 0) {
  81. const temp = data.map(item => {
  82. return {
  83. ...item,
  84. text: item.category_name
  85. }
  86. })
  87. temp.unshift({
  88. category_img_url: 'https://lanman-shining.oss-cn-hangzhou.aliyuncs.com/images/user/bashi635cd28a12481.png',
  89. category_name: '全部',
  90. id: 0
  91. })
  92. this.setData({
  93. categoryList: temp,
  94. 'searchForm.category_id': temp[0].id
  95. })
  96. } else {
  97. wx.showToast({
  98. title: msg,
  99. icon: 'none'
  100. })
  101. }
  102. } catch (err) {}
  103. },
  104. handleNav(e) {
  105. const { item } = e.currentTarget.dataset
  106. if (this.data.searchForm.category_id !== item.id) {
  107. this.setData({
  108. 'searchForm.category_id': item.id,
  109. navScrollLeft: 0
  110. }, () => {
  111. this.refreshOrderList()
  112. })
  113. }
  114. },
  115. showPopop() {
  116. this.setData({
  117. booPopop: true
  118. })
  119. },
  120. hidePopop() {
  121. this.setData({
  122. booPopop: false
  123. })
  124. },
  125. onChange(event) {
  126. const temp = event.detail
  127. const value = temp[temp.length - 1]
  128. this.setData({
  129. shop_type: [],
  130. 'searchForm.shop_type': value || ''
  131. }, () => {
  132. this.data.handleShoptype()
  133. })
  134. const timer = setTimeout(() => {
  135. clearTimeout(timer)
  136. this.setData({
  137. shop_type: value ? [value] : []
  138. })
  139. }, 200)
  140. }
  141. })