store.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. import {
  2. get,
  3. post
  4. } from '../../utils/http'
  5. const app = getApp()
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. value: '',
  12. total: 0,
  13. page: 1,
  14. list: [],
  15. isSelectProduct: false, //是否是预约时跳转过来
  16. ids:'',//预约项目ID
  17. lat1:'',
  18. lng1:''
  19. },
  20. /**
  21. * 生命周期函数--监听页面加载
  22. */
  23. onLoad: function (options) {
  24. console.log(options);
  25. let defaultStore = {}
  26. if (options.defaultStore) {
  27. defaultStore = JSON.parse(options.defaultStore)
  28. }
  29. if (Object.keys(defaultStore).length == 0) {
  30. defaultStore = app.globalData.storeData
  31. }
  32. let isSelectProduct = false
  33. if (options.isSelectProduct) {
  34. isSelectProduct = true
  35. }
  36. this.setData({
  37. defaultStore: defaultStore,
  38. isSelectProduct,
  39. ids:options.project_id?JSON.parse(options.project_id):'',
  40. lat1:app.address.latitude,
  41. lng1:app.address.longitude
  42. })
  43. // 是否是预约店铺切换
  44. if(this.data.isSelectProduct){
  45. this.getSelectStore()
  46. }else{
  47. this.getStore()
  48. }
  49. },
  50. /**
  51. * 生命周期函数--监听页面初次渲染完成
  52. */
  53. onReady: function () {},
  54. /**
  55. * 生命周期函数--监听页面显示
  56. */
  57. onShow: function () {},
  58. /**
  59. * 生命周期函数--监听页面隐藏
  60. */
  61. onHide: function () {},
  62. /**
  63. * 生命周期函数--监听页面卸载
  64. */
  65. onUnload: function () {},
  66. /**
  67. * 页面相关事件处理函数--监听用户下拉动作
  68. */
  69. onPullDownRefresh: function () {},
  70. /**
  71. * 页面上拉触底事件的处理函数
  72. */
  73. onReachBottom: function () {
  74. if (this.data.page * 10 < this.data.total) {
  75. this.getStore(++this.data.page)
  76. }
  77. },
  78. /**
  79. * 用户点击右上角分享
  80. */
  81. onShareAppMessage: function () {},
  82. /**
  83. * 清除搜索文本
  84. */
  85. onClear() {
  86. this.setData({
  87. value: ''
  88. })
  89. },
  90. /**
  91. * 选中店铺
  92. */
  93. onChangeStore(e) {
  94. let pages = getCurrentPages()
  95. let prevPage = pages[pages.length - 2]
  96. let storeId = e.currentTarget.dataset.item.id
  97. prevPage.getStoreInfo(storeId)
  98. if (this.data.isSelectProduct) {
  99. wx.navigateBack({
  100. delta: 1
  101. })
  102. return
  103. }
  104. get(
  105. 'api/store/info', {
  106. store_id: storeId
  107. },
  108. (res) => {
  109. wx.setStorageSync('store_id', String(storeId))
  110. app.globalData.storeData = res.data
  111. wx.navigateBack({
  112. delta: 1
  113. })
  114. }
  115. )
  116. },
  117. /**
  118. * 监听键盘输入
  119. */
  120. onChange(e) {
  121. this.setData({
  122. value: e.detail.value
  123. })
  124. },
  125. /**
  126. * 搜索店铺
  127. */
  128. onConfirm() {
  129. this.getStore(1)
  130. },
  131. /**
  132. * 获取店铺接口
  133. * /api/store
  134. */
  135. getStore(_page) {
  136. let {
  137. list,
  138. current,
  139. page
  140. } = this.data
  141. get(
  142. 'api/store', {
  143. page: _page || page,
  144. limit: 10,
  145. keyword: this.data.value
  146. },
  147. (res) => {
  148. if (_page == 1 || page == 1) {
  149. list = []
  150. this.data.page = 1
  151. }
  152. list.push(...res.data.list)
  153. this.setData({
  154. list,
  155. total: res.data.total
  156. })
  157. console.log(res, '重复')
  158. }
  159. )
  160. },
  161. // 预约店铺选择店铺获取店铺列表
  162. getSelectStore(_page) {
  163. let {
  164. list,
  165. current,
  166. page
  167. } = this.data
  168. get(
  169. 'v2/api/order/store', {
  170. page: _page || page,
  171. limit: 10,
  172. project_id:this.data.ids.toString()||''
  173. },
  174. (res) => {
  175. if (_page == 1 || page == 1) {
  176. list = []
  177. this.data.page = 1
  178. }
  179. list.push(...res.data)
  180. this.setData({
  181. list,
  182. })
  183. console.log(res, '重复')
  184. }
  185. )
  186. },
  187. /**
  188. * 打卡地图
  189. */
  190. onOpenLocation(e) {
  191. let store = e.currentTarget.dataset.storeinfo
  192. let latitude = parseFloat(store.latitude)
  193. let longitude = parseFloat(store.longitude)
  194. wx.openLocation({
  195. latitude: parseFloat(store.latitude), // 纬度,范围为-90~90,负数表示南纬
  196. longitude: parseFloat(store.longitude), // 经度,范围为-180~180,负数表示西经
  197. name: store.belong_region
  198. })
  199. }
  200. })