businessDetail.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. const pages = require('../../mixin/pages')
  2. const { getShopDetail } = require('../../api/common')
  3. const { postShopCollect } = require('./api/index')
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. ...pages.data(),
  10. listUrl: '/api/user/home/shop/product/list',
  11. searchForm: {
  12. shop_id: ''
  13. },
  14. nav: [
  15. {
  16. name: '详情',
  17. value: '1'
  18. },
  19. {
  20. name: '产品',
  21. value: '2'
  22. }
  23. ],
  24. active: '1',
  25. objShopDetail: { shop_address: {} },
  26. booLock: false
  27. },
  28. ...pages.methods,
  29. /**
  30. * 生命周期函数--监听页面加载
  31. */
  32. onLoad(options) {
  33. const { shop_id } = options
  34. this.setData({
  35. 'searchForm.shop_id': shop_id
  36. }, () => {
  37. this.fetchShopDetail()
  38. this.fetchOrderList()
  39. })
  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. /**
  62. * 页面相关事件处理函数--监听用户下拉动作
  63. */
  64. onPullDownRefresh() {
  65. if (this.data.freshing) {
  66. return
  67. }
  68. this.setData({
  69. freshing: true
  70. })
  71. this.bindCallBack()
  72. },
  73. /**
  74. * 页面上拉触底事件的处理函数
  75. */
  76. onReachBottom() {
  77. if (this.data.active === '2') {
  78. this.fetchOrderList()
  79. }
  80. },
  81. bindCallBack() {
  82. this.fetchShopDetail()
  83. this.refreshOrderList()
  84. },
  85. async fetchShopDetail() {
  86. try {
  87. const { status, data, msg } = await getShopDetail(this.data.searchForm.shop_id)
  88. if (status) {
  89. const { shop_address, collect_status } = data
  90. this.setData({
  91. objShopDetail: {
  92. ...data,
  93. shop_address: shop_address ? JSON.parse(shop_address) : {}
  94. },
  95. 'searchForm.type': collect_status === 0 ? 1 : 2 // 是否收藏(0否1是)
  96. })
  97. } else {
  98. wx.showToast({
  99. title: msg,
  100. icon: 'none'
  101. })
  102. }
  103. } catch (err) {}
  104. },
  105. async shopCollect() {
  106. const { type, shop_id } = this.data.searchForm
  107. if (this.data.booLock) {
  108. return
  109. }
  110. this.setData({
  111. booLock: true
  112. })
  113. try {
  114. const { status, msg } = await postShopCollect(shop_id, type)
  115. if (status) {
  116. this.setData({
  117. 'searchForm.type': type === 1 ? 2 : 1
  118. })
  119. } else {
  120. wx.showToast({
  121. title: msg,
  122. icon: 'none'
  123. })
  124. }
  125. } catch (err) {}
  126. this.setData({
  127. booLock: false
  128. })
  129. },
  130. handleNav(e) {
  131. const { value } = e.detail
  132. this.setData({
  133. active: value
  134. })
  135. }
  136. })