businessHome.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. finished: false
  34. },
  35. /**
  36. * 生命周期函数--监听页面加载
  37. */
  38. onLoad(options) {
  39. this.fetchShopInfo()
  40. },
  41. /**
  42. * 生命周期函数--监听页面初次渲染完成
  43. */
  44. onReady() {
  45. },
  46. /**
  47. * 生命周期函数--监听页面显示
  48. */
  49. onShow() {
  50. },
  51. /**
  52. * 生命周期函数--监听页面隐藏
  53. */
  54. onHide() {
  55. },
  56. /**
  57. * 生命周期函数--监听页面卸载
  58. */
  59. onUnload() {
  60. },
  61. onPullDownRefresh() {
  62. if (this.data.isRefresh) {
  63. return
  64. }
  65. this.setData({
  66. isRefresh: true,
  67. finished: false
  68. })
  69. this.fetchShopInfo()
  70. },
  71. bindCallBack() {
  72. this.fetchShopInfo()
  73. },
  74. jump(e) {
  75. const { path, tabvalue = '' } = e.currentTarget.dataset
  76. wx.navigateTo({
  77. url: `/pages/${path}/${path}?tabvalue=${tabvalue}`
  78. })
  79. },
  80. handleNav(e) {
  81. const { item } = e.currentTarget.dataset
  82. const path = item.path
  83. wx.navigateTo({
  84. url: `/pages/${path}/${path}`
  85. })
  86. },
  87. async fetchShopInfo() {
  88. const that = this
  89. const isRefresh = that.data.isRefresh
  90. if (that.data.isFetchLock) {
  91. return
  92. }
  93. that.setData({
  94. isFetchLock: true
  95. })
  96. try {
  97. const { status, data, msg } = await getShopInfo()
  98. if (status) {
  99. this.setData({
  100. shopInfo: data,
  101. products: data.products
  102. })
  103. } else {
  104. wx.showToast({
  105. title: msg,
  106. icon: 'none'
  107. })
  108. }
  109. } catch (err) {}
  110. this.setData({
  111. isFetchLock: false,
  112. isRefresh: false,
  113. finished: true
  114. })
  115. if (isRefresh) {
  116. wx.stopPullDownRefresh()
  117. }
  118. }
  119. })