businessHome.js 2.1 KB

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