index.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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({ status: options.go });
  28. // if (options.go === 'order') this.checked();
  29. },
  30. /**
  31. * 登录回调
  32. *
  33. */
  34. onLoadFun: function () {
  35. let longitude = wx.getStorageSync(CACHE_LONGITUDE); //经度
  36. let latitude = wx.getStorageSync(CACHE_LATITUDE); //纬度
  37. // this.setData({ latitude: latitude, longitude: longitude });
  38. if (longitude && latitude){
  39. this.getList(longitude, latitude);
  40. }else{
  41. this.selfLocation();
  42. }
  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. */
  60. checked: function (e) {
  61. let details = e.currentTarget.dataset.details;
  62. let pages = getCurrentPages(); //当前页面
  63. let prevPage = pages[pages.length - 2]; //上一页面
  64. prevPage.setData({
  65. storeItem: details
  66. });
  67. if (this.data.status === 'order') wx.navigateBack({ delta: 1 });
  68. },
  69. /**
  70. * 获取门店列表数据
  71. */
  72. getList: function (longitudes, latitudes) {
  73. if (this.data.loadend) return;
  74. if (this.data.loading) return;
  75. this.setData({ loading: true, loadTitle: "" });
  76. let data={
  77. latitude: latitudes || '', //纬度
  78. longitude: longitudes || '', //经度
  79. page: this.data.page,
  80. limit: this.data.limit
  81. }
  82. storeListApi(data).then(res => {
  83. let list = res.data.list || [];
  84. let loadend = list.length < this.data.limit;
  85. this.data.storeList = app.SplitArray(list, this.data.storeList);
  86. this.setData({
  87. storeList: this.data.storeList,
  88. loadend: loadend,
  89. loading: false,
  90. loadTitle: loadend ? "我也是有底线的" : '加载更多',
  91. page: this.data.page + 1
  92. });
  93. }).catch(err => {
  94. this.setData({ loading: false, loadTitle: "加载更多" });
  95. })
  96. },
  97. /**
  98. * 拨打电话
  99. */
  100. makePhone: function (e) {
  101. let phone = e.currentTarget.dataset.phone;
  102. wx.makePhoneCall({
  103. phoneNumber: phone
  104. })
  105. },
  106. /**
  107. * 打开地图
  108. *
  109. */
  110. showMaoLocation: function (e) {
  111. let details = e.currentTarget.dataset.details;
  112. if (!details.latitude || !details.longitude) return app.Tips({ title: '缺少经纬度信息无法查看地图!' });
  113. wx.openLocation({
  114. latitude: parseFloat(details.latitude),
  115. longitude: parseFloat(details.longitude),
  116. scale: 8,
  117. name: details.name,
  118. address: details.address + details.detailed_address,
  119. success: function () {
  120. },
  121. });
  122. },
  123. /**
  124. * 生命周期函数--监听页面隐藏
  125. */
  126. onHide: function () {
  127. this.setData({ isClose: true });
  128. },
  129. /**
  130. * 生命周期函数--监听页面显示
  131. */
  132. onShow: function () {
  133. // if (app.globalData.isLog && this.data.isClose) {
  134. // this.setData({ loadend: false, page: 1, storeList: [] });
  135. // let longitude = wx.getStorageSync(CACHE_LONGITUDE); //经度
  136. // let latitude = wx.getStorageSync(CACHE_LATITUDE); //纬度
  137. // this.getList(longitude, latitude);
  138. // }
  139. },
  140. /**
  141. * 页面上拉触底事件的处理函数
  142. */
  143. onReachBottom: function () {
  144. let longitude = wx.getStorageSync(CACHE_LONGITUDE); //经度
  145. let latitude = wx.getStorageSync(CACHE_LATITUDE); //纬度
  146. this.getList(longitude, latitude);
  147. }
  148. })