businessHome.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. const { getShopInfo } = require('./api/index')
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. nav: [
  8. {
  9. icon: 'goods_release.png',
  10. name: '产品发布',
  11. path: 'businessGoodsEdit'
  12. },
  13. {
  14. icon: 'goods_manage.png',
  15. name: '产品管理',
  16. path: 'businessGoodsManage'
  17. },
  18. // {
  19. // icon: 'video_manage.png',
  20. // name: '视频管理',
  21. // path: 'businessVideoManage'
  22. // },
  23. {
  24. icon: 'message.png',
  25. name: '互动消息',
  26. path: 'businessLeavingAMessage'
  27. }
  28. ],
  29. shopInfo: {},
  30. products: [],
  31. isFetchLock: false, // 接口调用加锁
  32. isRefresh: false // 是否下拉刷新
  33. },
  34. /**
  35. * 生命周期函数--监听页面加载
  36. */
  37. onLoad(options) {
  38. this.fetchShopInfo()
  39. },
  40. /**
  41. * 生命周期函数--监听页面初次渲染完成
  42. */
  43. onReady() {
  44. },
  45. /**
  46. * 生命周期函数--监听页面显示
  47. */
  48. onShow() {
  49. },
  50. /**
  51. * 生命周期函数--监听页面隐藏
  52. */
  53. onHide() {
  54. },
  55. /**
  56. * 生命周期函数--监听页面卸载
  57. */
  58. onUnload() {
  59. },
  60. onPullDownRefresh() {
  61. if (this.data.isRefresh) {
  62. return
  63. }
  64. this.setData({
  65. isRefresh: true
  66. })
  67. this.fetchShopInfo()
  68. },
  69. bindCallBack() {
  70. this.fetchShopInfo()
  71. },
  72. jump(e) {
  73. const { path, tabvalue = '' } = e.currentTarget.dataset
  74. wx.navigateTo({
  75. url: `/pages/${path}/${path}?tabvalue=${tabvalue}`
  76. })
  77. },
  78. handleNav(e) {
  79. const { item } = e.currentTarget.dataset
  80. const path = item.path
  81. wx.navigateTo({
  82. url: `/pages/${path}/${path}`
  83. })
  84. },
  85. async fetchShopInfo() {
  86. const that = this
  87. const isRefresh = that.data.isRefresh
  88. if (that.data.isFetchLock) {
  89. return
  90. }
  91. that.setData({
  92. isFetchLock: true
  93. })
  94. try {
  95. const { status, data, msg } = await getShopInfo()
  96. if (status) {
  97. this.setData({
  98. shopInfo: data,
  99. products: data.products
  100. })
  101. } else {
  102. wx.showToast({
  103. title: msg,
  104. icon: 'none'
  105. })
  106. }
  107. } catch (err) {}
  108. this.setData({
  109. isFetchLock: false,
  110. isRefresh: false
  111. })
  112. if (isRefresh) {
  113. wx.stopPullDownRefresh()
  114. }
  115. }
  116. })