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