index.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. import { CACHE_LONGITUDE, CACHE_LATITUDE } from '../../config.js'
  2. import { storeListApi } from '../../api/store.js'
  3. import wxh from '../../utils/wxh.js'
  4. const app = getApp()
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. parameter: {
  11. navbar: '1',
  12. return: '1',
  13. title: '门店列表'
  14. },
  15. loading: false, //是否加载中
  16. loadend: false, //是否加载完毕
  17. loadTitle: '加载更多', //提示语
  18. page: 1,
  19. limit: 10,
  20. isClose: false,
  21. storeList: [],
  22. status: ''
  23. // longitude: '',
  24. // latitude: ''
  25. },
  26. onLoad: function (options) {
  27. this.setData({
  28. status: options.go
  29. })
  30. // if (options.go === 'order') this.checked();
  31. },
  32. /**
  33. * 登录回调
  34. */
  35. onLoadFun: function () {
  36. let longitude = wx.getStorageSync(CACHE_LONGITUDE) //经度
  37. let latitude = wx.getStorageSync(CACHE_LATITUDE) //纬度
  38. // this.setData({ latitude: latitude, longitude: longitude });
  39. if (longitude && latitude) {
  40. // this.getList(longitude, latitude);
  41. } else {
  42. // this.selfLocation();
  43. }
  44. },
  45. /**
  46. * 授权地址
  47. */
  48. // selfLocation: function () {
  49. // const that = this;
  50. // wxh.selfLocation().then(res => {
  51. // that.getList(res.longitude, res.latitude);
  52. // }).catch(() => {
  53. // that.getList();
  54. // });
  55. // },
  56. /**
  57. * 选中门店
  58. */
  59. checked: function (e) {
  60. let details = e.currentTarget.dataset.details
  61. let pages = getCurrentPages() //当前页面
  62. let prevPage = pages[pages.length - 2] //上一页面
  63. prevPage.setData({
  64. storeItem: details
  65. })
  66. if (this.data.status === 'order')
  67. wx.navigateBack({
  68. delta: 1
  69. })
  70. },
  71. /**
  72. * 获取门店列表数据
  73. */
  74. getList: function (longitudes, latitudes) {
  75. if (this.data.loadend) return
  76. if (this.data.loading) return
  77. this.setData({
  78. loading: true,
  79. loadTitle: ''
  80. })
  81. let data = {
  82. latitude: latitudes || '', //纬度
  83. longitude: longitudes || '', //经度
  84. page: this.data.page,
  85. limit: this.data.limit
  86. }
  87. storeListApi(data)
  88. .then(res => {
  89. let list = res.data.list || []
  90. let loadend = list.length < this.data.limit
  91. this.data.storeList = app.SplitArray(list, this.data.storeList)
  92. this.setData({
  93. storeList: this.data.storeList,
  94. loadend: loadend,
  95. loading: false,
  96. loadTitle: loadend ? '我也是有底线的' : '加载更多',
  97. page: this.data.page + 1
  98. })
  99. })
  100. .catch(err => {
  101. this.setData({
  102. loading: false,
  103. loadTitle: '加载更多'
  104. })
  105. })
  106. },
  107. /**
  108. * 拨打电话
  109. */
  110. makePhone: function (e) {
  111. let phone = e.currentTarget.dataset.phone
  112. wx.makePhoneCall({
  113. phoneNumber: phone
  114. })
  115. },
  116. /**
  117. * 打开地图
  118. */
  119. showMaoLocation: function (e) {
  120. let details = e.currentTarget.dataset.details
  121. if (!details.latitude || !details.longitude)
  122. return app.Tips({
  123. title: '缺少经纬度信息无法查看地图!'
  124. })
  125. wx.openLocation({
  126. latitude: parseFloat(details.latitude),
  127. longitude: parseFloat(details.longitude),
  128. scale: 8,
  129. name: details.name,
  130. address: details.address + details.detailed_address,
  131. success: function () {}
  132. })
  133. },
  134. /**
  135. * 生命周期函数--监听页面隐藏
  136. */
  137. onHide: function () {
  138. this.setData({
  139. isClose: true
  140. })
  141. },
  142. /**
  143. * 生命周期函数--监听页面显示
  144. */
  145. onShow: function () {
  146. // if (app.globalData.isLog && this.data.isClose) {
  147. // this.setData({ loadend: false, page: 1, storeList: [] });
  148. // let longitude = wx.getStorageSync(CACHE_LONGITUDE); //经度
  149. // let latitude = wx.getStorageSync(CACHE_LATITUDE); //纬度
  150. // this.getList(longitude, latitude);
  151. // }
  152. },
  153. /**
  154. * 页面上拉触底事件的处理函数
  155. */
  156. onReachBottom: function () {
  157. // let longitude = wx.getStorageSync(CACHE_LONGITUDE); //经度
  158. // let latitude = wx.getStorageSync(CACHE_LATITUDE); //纬度
  159. // this.getList(longitude, latitude);
  160. }
  161. })