index.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. let Parse = getApp().Parse;
  2. const company = getApp().globalData.company
  3. const compute = require("../../../utils/compute.js");
  4. let navigationBarHeight = getApp().globalData.statusBarHeight + 44;
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. latitude: 0,
  11. longitude: 0,
  12. active: 0,
  13. list: [],
  14. value: null,
  15. showTab: false,
  16. stickytop: navigationBarHeight,
  17. },
  18. navigateComments(e) {
  19. let id = e.currentTarget.dataset.item.objectId
  20. wx.navigateTo({
  21. url: `/nova-tourism/pages/gourmet/store-package/comment/index?id=` + id
  22. })
  23. },
  24. async getData() {
  25. if (this.data.latitude == 0 && this.data.longitude == 0) {
  26. let { latitude, longitude } = await this.getLocation()
  27. this.setData({
  28. latitude,
  29. longitude
  30. })
  31. console.log(this.latitude, this.longitude);
  32. }
  33. this.getShopStore()
  34. },
  35. storepackage(e) {
  36. let id = e.currentTarget.dataset.item.objectId
  37. console.log(id);
  38. wx.navigateTo({
  39. url: '/nova-tourism/pages/gourmet/store-package/index?id=' + id
  40. });
  41. },
  42. getLocation() {
  43. return new Promise((resolve, reject) => {
  44. wx.getLocation({
  45. type: 'gcj02',
  46. success: (res) => {
  47. console.log(res.latitude, res.longitude);
  48. resolve({
  49. latitude: res.latitude,
  50. longitude: res.longitude
  51. })
  52. },
  53. fail: () => { },
  54. complete: () => { }
  55. });
  56. })
  57. },
  58. onSearch() {
  59. wx.showToast({
  60. title: `搜索 ${this.data.value}`,
  61. icon: 'none',
  62. });
  63. },
  64. onClick() {
  65. wx.showToast({
  66. title: `搜索 ${this.data.value}`,
  67. icon: 'none',
  68. });
  69. },
  70. onChan(e) {
  71. this.setData({
  72. value: e.detail,
  73. });
  74. this.getShopStore()
  75. },
  76. onChange(event) {
  77. let active = event.detail.name
  78. console.log(active);
  79. this.setData({
  80. active: active
  81. })
  82. this.getShopStore()
  83. },
  84. async getShopStore() {
  85. let ShopStore = new Parse.Query('ShopStore')
  86. ShopStore.equalTo('company', company)
  87. ShopStore.equalTo('type', "catering")
  88. ShopStore.notEqualTo("isDeleted",true)
  89. if (this.data.active == 0) {
  90. ShopStore.descending('isShow')
  91. }
  92. if (this.data.active == 1) {
  93. ShopStore.descending('score')
  94. }
  95. if (this.data.active == 3) {
  96. ShopStore.ascending('perCapita')
  97. }
  98. if (this.data.value) {
  99. ShopStore.contains('storeName', this.data.value)
  100. }
  101. let shopStores = await ShopStore.find()
  102. if (shopStores) {
  103. let listJSON = []
  104. for (let i = 0; i < shopStores.length; i++) {
  105. listJSON.push(shopStores[i].toJSON())
  106. }
  107. for (let i = 0; i < listJSON.length; i++) {
  108. let item = listJSON[i]
  109. if (item.location) {
  110. console.log(this.data.latitude, this.data.longitude);
  111. let distance = compute.computeDistance(
  112. this.data.latitude,
  113. this.data.longitude,
  114. item.location.latitude,
  115. item.location.longitude
  116. )
  117. item.distance = distance.toFixed(2)
  118. listJSON[i] = item
  119. }
  120. }
  121. //按距离排序
  122. if (this.data.active == 2) {
  123. listJSON = listJSON.sort((a, b) => {
  124. return a.distance - b.distance
  125. })
  126. }
  127. this.setData({
  128. list: listJSON
  129. })
  130. }
  131. console.log(this.data.list);
  132. },
  133. onPageScroll: function (e) {
  134. var that = this;
  135. var scrollTop = parseInt(e.scrollTop); //滚动条距离顶部高度
  136. //判断'滚动条'滚动的距离 和 '元素在初始时'距顶部的距离进行判断
  137. var isSatisfy = scrollTop >= that.data.navbarInitTop ? true : false;
  138. // 只有处于吸顶的临界值才会不相等
  139. if (that.data.isFixedTop === isSatisfy) {
  140. return false;
  141. }
  142. that.setData({
  143. isFixedTop: isSatisfy
  144. });
  145. },
  146. /**
  147. * 生命周期函数--监听页面加载
  148. */
  149. onLoad: function (options) {
  150. this.setData({
  151. activeColor:getApp().globalData.activeColor || '#229293'
  152. })
  153. this.getData()
  154. this.getShopStore()
  155. },
  156. /**
  157. * 生命周期函数--监听页面初次渲染完成
  158. */
  159. onReady: function () {
  160. },
  161. /**
  162. * 生命周期函数--监听页面显示
  163. */
  164. onShow: function () {
  165. var that = this;
  166. if (that.data.navbarInitTop == 0) {
  167. //获取节点距离顶部的距离
  168. wx.createSelectorQuery().select('#navbar').boundingClientRect(function (rect) {
  169. if (rect && rect.top > 0) {
  170. var navbarInitTop = parseInt(rect.top);
  171. that.setData({
  172. navbarInitTop: navbarInitTop
  173. });
  174. }
  175. }).exec();
  176. }
  177. },
  178. /**
  179. * 生命周期函数--监听页面隐藏
  180. */
  181. onHide: function () {
  182. },
  183. /**
  184. * 生命周期函数--监听页面卸载
  185. */
  186. onUnload: function () {
  187. },
  188. /**
  189. * 页面相关事件处理函数--监听用户下拉动作
  190. */
  191. onPullDownRefresh: function () {
  192. },
  193. /**
  194. * 页面上拉触底事件的处理函数
  195. */
  196. onReachBottom: function () {
  197. },
  198. /**
  199. * 用户点击右上角分享
  200. */
  201. onShareAppMessage: function () {
  202. return {
  203. title: '美食预定',
  204. }
  205. }
  206. })