index.js 4.6 KB

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