business.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. const pages = require('../../mixin/pages')
  2. const { getProductCategoryList } = require('../../api/common')
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. ...pages.data(),
  9. listUrl: '/api/user/home/shop/list',
  10. searchForm: {
  11. key_words: '',
  12. category_id: ''
  13. },
  14. categoryList: [],
  15. navScrollLeft: -1,
  16. booLock: false
  17. },
  18. ...pages.methods,
  19. /**
  20. * 生命周期函数--监听页面加载
  21. */
  22. async onLoad(options) {
  23. await this.fetchProductCategoryList()
  24. this.fetchOrderList()
  25. },
  26. /**
  27. * 生命周期函数--监听页面初次渲染完成
  28. */
  29. onReady() {
  30. },
  31. /**
  32. * 生命周期函数--监听页面显示
  33. */
  34. onShow() {
  35. },
  36. /**
  37. * 生命周期函数--监听页面隐藏
  38. */
  39. onHide() {
  40. },
  41. /**
  42. * 生命周期函数--监听页面卸载
  43. */
  44. onUnload() {
  45. },
  46. /**
  47. * 页面相关事件处理函数--监听用户下拉动作
  48. */
  49. onPullDownRefresh() {
  50. if (this.data.freshing) {
  51. return
  52. }
  53. this.setData({
  54. freshing: true
  55. })
  56. this.bindCallBack()
  57. },
  58. /**
  59. * 页面上拉触底事件的处理函数
  60. */
  61. onReachBottom() {
  62. this.fetchOrderList()
  63. },
  64. bindCallBack() {
  65. this.refreshOrderList()
  66. },
  67. async fetchProductCategoryList() {
  68. try {
  69. const { status, data, msg } = await getProductCategoryList()
  70. if (status && Array.isArray(data) && data.length > 0) {
  71. const temp = data.map(item => {
  72. return {
  73. ...item,
  74. text: item.category_name
  75. }
  76. })
  77. temp.unshift({
  78. category_img_url: '',
  79. category_name: '全部',
  80. id: 0
  81. })
  82. this.setData({
  83. categoryList: temp,
  84. 'searchForm.category_id': temp[0].id
  85. })
  86. } else {
  87. wx.showToast({
  88. title: msg,
  89. icon: 'none'
  90. })
  91. }
  92. } catch (err) {}
  93. },
  94. handleNav(e) {
  95. const { item } = e.currentTarget.dataset
  96. if (this.data.searchForm.category_id !== item.id) {
  97. this.setData({
  98. 'searchForm.category_id': item.id,
  99. navScrollLeft: 0
  100. }, () => {
  101. this.refreshOrderList()
  102. })
  103. }
  104. }
  105. })