shop.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. // pages/shoplist/shoplist.js
  2. import {
  3. default as storeApi
  4. } from "../../api/store"
  5. import commentsApi from '../../api/comments'
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. shopList: []
  12. },
  13. /**
  14. * 生命周期函数--监听页面加载
  15. */
  16. onLoad: async function (options) {
  17. wx.getSetting({
  18. success: async (res) => {
  19. let authSetting = res.authSetting
  20. if (authSetting['scope.userLocation']) {
  21. console.log('已授权地理位置')
  22. let lon = wx.getStorageSync('lon')
  23. let lat = wx.getStorageSync('lat')
  24. let rs = await storeApi.getStoreList(1, 5,`&lon=${lon}&lat=${lat}`);
  25. this.setData({
  26. shopList: rs.list,
  27. })
  28. // 已授权
  29. } else {
  30. // 未授权
  31. console.log('未授权地理位置');
  32. wx.getLocation({
  33. type: 'wgs84',
  34. async success(res) {
  35. console.log(res)
  36. const latitude = res.latitude
  37. const longitude = res.longitude
  38. wx.setStorageSync('lon', longitude)
  39. wx.setStorageSync('lat', latitude)
  40. const rs = await storeApi.getNearStore(latitude, longitude)
  41. console.log(rs.info);
  42. self.setData({
  43. locationFlag: true,
  44. storeInfo: rs.info
  45. })
  46. let shopList = await storeApi.getStoreList(1, 5,`&lon=${longitude}&lat=${latitude}`);
  47. this.setData({
  48. shopList: shopList.shopList,
  49. })
  50. }
  51. })
  52. }
  53. }
  54. })
  55. },
  56. /**
  57. * 生命周期函数--监听页面初次渲染完成
  58. */
  59. onReady: function () {
  60. },
  61. /**
  62. * 生命周期函数--监听页面显示
  63. */
  64. onShow: function () {
  65. },
  66. /**
  67. * 生命周期函数--监听页面隐藏
  68. */
  69. onHide: function () {
  70. },
  71. /**
  72. * 生命周期函数--监听页面卸载
  73. */
  74. onUnload: function () {
  75. },
  76. /**
  77. * 页面相关事件处理函数--监听用户下拉动作
  78. */
  79. onPullDownRefresh: function () {
  80. },
  81. /**
  82. * 页面上拉触底事件的处理函数
  83. */
  84. onReachBottom: function () {
  85. },
  86. /**
  87. * 用户点击右上角分享
  88. */
  89. onShareAppMessage: function () {
  90. }
  91. })