business.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. // pages/business/business.js
  2. const app = getApp()
  3. import http from "../../utils/http"
  4. import util from "../../utils/util"
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. current:1,
  11. menuH: '32px',
  12. safeTop: `40px`,
  13. cate: [{id: '', label: '全部'}],
  14. cate_id: '',
  15. list: [],
  16. address: '',
  17. name: ''
  18. },
  19. selectAddress(){
  20. util.skip('/service/selectAddress/selectAddress?city='+this.data.address.city+'&name='+this.data.address.name)
  21. },
  22. /**
  23. * 生命周期函数--监听页面加载
  24. */
  25. onLoad(options) {
  26. this.setData({
  27. safeTop: `${app.globalData.safeTop}px`,
  28. menuH: `${app.globalData.menuH}px`,
  29. })
  30. this.getInfo()
  31. },
  32. shopTap(e){
  33. util.skip('/service/shopdetail/shopdetail?shop_id='+e.detail.id)
  34. },
  35. nameChange(e) {
  36. this.setData({
  37. name: e.detail,
  38. });
  39. },
  40. onSearch(){
  41. if(this.data.value === '') return util.toast('请输入搜索内容')
  42. this.reload()
  43. },
  44. onShowAddress(option){
  45. this.setData({
  46. address: app.globalData.address
  47. })
  48. this.reload()
  49. },
  50. reload(){
  51. this.setData({
  52. list: [],
  53. page: 1,
  54. finish: false
  55. })
  56. this.getList()
  57. },
  58. getList(){
  59. if(this.data.finish){
  60. return
  61. }
  62. if(this.data.loading){
  63. return
  64. }
  65. this.setData({
  66. loading: true
  67. })
  68. http.post('shop/searchshop', {
  69. city: this.data.address.city,
  70. lat: this.data.address.lat,
  71. lng: this.data.address.lng,
  72. page: this.data.page,
  73. name: this.data.name,
  74. category_id: this.data.cate_id
  75. }).then(res => {
  76. if(res.data.length === 0){
  77. this.setData({
  78. finish: true
  79. })
  80. }
  81. let arr = this.data.list.concat(res.data)
  82. this.setData({
  83. list: arr
  84. })
  85. }).finally(res => {
  86. this.setData({
  87. loading: false
  88. })
  89. })
  90. },
  91. getInfo(){
  92. http.post('category/getlist', '', true).then(res => {
  93. let arr = this.data.cate.concat(res.data)
  94. this.setData({
  95. cate: arr
  96. })
  97. })
  98. },
  99. onChange(e){
  100. this.setData({
  101. cate_id: this.data.cate[e.detail.index].id
  102. })
  103. this.reload()
  104. },
  105. lowerthreshold(){
  106. this.setData({
  107. page: ++this.data.page
  108. })
  109. this.getList()
  110. },
  111. choosetype(e){
  112. this.setData({
  113. current:e.currentTarget.dataset.id
  114. })
  115. },
  116. /**
  117. * 生命周期函数--监听页面初次渲染完成
  118. */
  119. onReady() {
  120. },
  121. /**
  122. * 生命周期函数--监听页面显示
  123. */
  124. onShow() {
  125. },
  126. /**
  127. * 生命周期函数--监听页面隐藏
  128. */
  129. onHide() {
  130. },
  131. /**
  132. * 生命周期函数--监听页面卸载
  133. */
  134. onUnload() {
  135. },
  136. /**
  137. * 页面相关事件处理函数--监听用户下拉动作
  138. */
  139. onPullDownRefresh() {
  140. },
  141. /**
  142. * 页面上拉触底事件的处理函数
  143. */
  144. onReachBottom() {
  145. },
  146. /**
  147. * 用户点击右上角分享
  148. */
  149. onShareAppMessage() {
  150. return {}
  151. }
  152. })