businessDetail.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. const pages = require('../../mixin/pages')
  2. const { getShopDetail } = require('../../api/common')
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. ...pages.data(),
  9. listUrl: '/api/user/home/shop/product/list',
  10. searchForm: {
  11. shop_id: ''
  12. },
  13. background: ['demo-text-1', 'demo-text-2', 'demo-text-3'],
  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. },
  27. ...pages.methods,
  28. /**
  29. * 生命周期函数--监听页面加载
  30. */
  31. onLoad(options) {
  32. const { shop_id } = options
  33. this.setData({
  34. 'searchForm.shop_id': shop_id
  35. }, () => {
  36. this.fetchShopDetail()
  37. this.fetchOrderList()
  38. })
  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. /**
  61. * 页面相关事件处理函数--监听用户下拉动作
  62. */
  63. onPullDownRefresh() {
  64. if (this.data.freshing) {
  65. return
  66. }
  67. this.setData({
  68. freshing: true
  69. })
  70. this.bindCallBack()
  71. },
  72. /**
  73. * 页面上拉触底事件的处理函数
  74. */
  75. onReachBottom() {
  76. if (this.data.active === '2') {
  77. this.fetchOrderList()
  78. }
  79. },
  80. bindCallBack() {
  81. this.fetchShopDetail()
  82. this.refreshOrderList()
  83. },
  84. async fetchShopDetail() {
  85. try {
  86. const { status, data, msg } = await getShopDetail(this.data.searchForm.shop_id)
  87. if (status) {
  88. this.setData({
  89. objShopDetail: {
  90. ...data,
  91. shop_address: JSON.parse(data.shop_address)
  92. }
  93. })
  94. } else {
  95. wx.showToast({
  96. title: msg,
  97. icon: 'none'
  98. })
  99. }
  100. } catch (err) {}
  101. },
  102. handleNav(e) {
  103. const { value } = e.detail
  104. this.setData({
  105. active: value
  106. })
  107. }
  108. })