store.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. import { get, post } from '../../utils/http'
  2. const app = getApp()
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. value: '',
  9. total: 0,
  10. page: 1,
  11. list: []
  12. },
  13. /**
  14. * 生命周期函数--监听页面加载
  15. */
  16. onLoad: function (options) {
  17. let defaultStore = {}
  18. if (options.defaultStore) {
  19. defaultStore = JSON.parse(options.defaultStore)
  20. }
  21. if (Object.keys(defaultStore).length == 0) {
  22. defaultStore = app.globalData.storeData
  23. }
  24. this.setData({
  25. defaultStore: defaultStore
  26. })
  27. this.getStore()
  28. },
  29. /**
  30. * 生命周期函数--监听页面初次渲染完成
  31. */
  32. onReady: function () {},
  33. /**
  34. * 生命周期函数--监听页面显示
  35. */
  36. onShow: function () {},
  37. /**
  38. * 生命周期函数--监听页面隐藏
  39. */
  40. onHide: function () {},
  41. /**
  42. * 生命周期函数--监听页面卸载
  43. */
  44. onUnload: function () {},
  45. /**
  46. * 页面相关事件处理函数--监听用户下拉动作
  47. */
  48. onPullDownRefresh: function () {},
  49. /**
  50. * 页面上拉触底事件的处理函数
  51. */
  52. onReachBottom: function () {
  53. if (this.data.page * 10 < this.data.total) {
  54. this.getStore(++this.data.page)
  55. }
  56. },
  57. /**
  58. * 用户点击右上角分享
  59. */
  60. onShareAppMessage: function () {},
  61. /**
  62. * 清除搜索文本
  63. */
  64. onClear() {
  65. this.setData({
  66. value: ''
  67. })
  68. },
  69. /**
  70. * 选中店铺
  71. */
  72. onChangeStore(e) {
  73. let pages = getCurrentPages()
  74. let prevPage = pages[pages.length - 2]
  75. let storeId = e.currentTarget.dataset.item.id
  76. prevPage.getStoreInfo(storeId)
  77. // prevPage.setData({
  78. // location: e.currentTarget.dataset.item
  79. // })
  80. get(
  81. 'api/store/info',
  82. {
  83. store_id: storeId
  84. },
  85. (res) => {
  86. wx.setStorageSync('store_id', String(storeId))
  87. app.globalData.storeData = res.data
  88. wx.navigateBack({
  89. delta: 1
  90. })
  91. }
  92. )
  93. },
  94. /**
  95. * 监听键盘输入
  96. */
  97. onChange(e) {
  98. this.setData({ value: e.detail.value })
  99. },
  100. /**
  101. * 搜索店铺
  102. */
  103. onConfirm() {
  104. this.getStore(1)
  105. },
  106. /**
  107. * 获取店铺接口
  108. * /api/store
  109. */
  110. getStore(_page) {
  111. let { list, current, page } = this.data
  112. get(
  113. 'api/store',
  114. {
  115. page: _page || page,
  116. limit: 10,
  117. keyword: this.data.value
  118. },
  119. (res) => {
  120. if (_page == 1 || page == 1) {
  121. list = []
  122. this.data.page = 1
  123. }
  124. list.push(...res.data.list)
  125. this.setData({ list, total: res.data.total })
  126. console.log(res,'重复')
  127. }
  128. )
  129. },
  130. /**
  131. * 打卡地图
  132. */
  133. onOpenLocation() {
  134. let store = this.data.defaultStore
  135. let latitude = parseFloat(store.latitude)
  136. let longitude = parseFloat(store.longitude)
  137. wx.openLocation({
  138. latitude: parseFloat(store.latitude), // 纬度,范围为-90~90,负数表示南纬
  139. longitude: parseFloat(store.longitude), // 经度,范围为-180~180,负数表示西经
  140. name: store.belong_region
  141. })
  142. }
  143. })