index.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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. Component({
  6. /**
  7. * 组件的属性列表
  8. */
  9. properties: {
  10. },
  11. /**
  12. * 组件的初始数据
  13. */
  14. data: {
  15. imgUrls: [
  16. 'https://file-cloud.fmode.cn/sHNeVwSaAg/20230530/v61567044111362.png',
  17. 'https://file-cloud.fmode.cn/sHNeVwSaAg/20230530/aijk11044111180.png',
  18. 'https://file-cloud.fmode.cn/sHNeVwSaAg/20230530/6eqp18044111072.web',
  19. 'https://file-cloud.fmode.cn/sHNeVwSaAg/20230530/5rv371044110921.png'
  20. ],
  21. latitude: 0,
  22. longitude: 0,
  23. active: 0,
  24. list: [],
  25. value: null,
  26. showTab: false,
  27. stickytop: navigationBarHeight,
  28. tabs: [{
  29. title: '推荐',
  30. icon: 'https://s1.ax1x.com/2023/04/10/ppqEqdH.png'
  31. },
  32. {
  33. title: '评分',
  34. icon: 'https://s1.ax1x.com/2023/04/10/ppqkofx.png'
  35. },
  36. {
  37. title: '距离',
  38. icon: 'https://s1.ax1x.com/2023/04/10/ppqkIt1.png'
  39. },
  40. {
  41. title: '价格',
  42. icon: 'https://s1.ax1x.com/2023/04/10/ppqkh79.png'
  43. },
  44. ],
  45. tabIndex: 0,
  46. banners: []
  47. },
  48. ready: function () {
  49. // 在组件布局完成后执行,确保options参数中有data信息
  50. this.getBanner()
  51. this.getData()
  52. // this.selectComponent('#tabs').resize();
  53. },
  54. navigateComments(e) {
  55. let id = e.currentTarget.dataset.item.objectId
  56. wx.navigateTo({
  57. url: `/nova-tourism/pages/gourmet/store-package/comment/index?id=` + id
  58. })
  59. },
  60. /**
  61. * 组件的方法列表
  62. */
  63. methods: {
  64. async getData() {
  65. if (this.data.latitude == 0 && this.data.longitude == 0) {
  66. let {
  67. latitude,
  68. longitude
  69. } = await this.getLocation()
  70. this.setData({
  71. latitude,
  72. longitude
  73. })
  74. }
  75. this.getShopStore()
  76. },
  77. storepackage(e) {
  78. let id = e.currentTarget.dataset.item.objectId
  79. wx.navigateTo({
  80. url: '/nova-tourism/pages/gourmet/store-package/index?id=' + id
  81. });
  82. },
  83. getLocation() {
  84. return new Promise((resolve, reject) => {
  85. wx.getLocation({
  86. type: 'gcj02',
  87. success: (res) => {
  88. resolve({
  89. latitude: res.latitude,
  90. longitude: res.longitude
  91. })
  92. },
  93. fail: () => {},
  94. complete: () => {}
  95. });
  96. })
  97. },
  98. onSearch() {
  99. wx.showToast({
  100. title: `搜索 ${this.data.value}`,
  101. icon: 'none',
  102. });
  103. },
  104. onTabClick(e) {
  105. let index = e.currentTarget.dataset.index;
  106. this.setData({
  107. tabIndex: index,
  108. active: index
  109. })
  110. this.getShopStore()
  111. },
  112. onClick() {
  113. this.setData({
  114. value: null,
  115. });
  116. },
  117. onChan(e) {
  118. this.setData({
  119. value: e.detail,
  120. });
  121. this.getShopStore()
  122. },
  123. onChange(event) {
  124. let active = event.detail.name
  125. this.setData({
  126. active: active
  127. })
  128. this.getShopStore()
  129. },
  130. async getShopStore() {
  131. let ShopStore = new Parse.Query('ShopStore')
  132. ShopStore.notEqualTo('isDeleted', "true")
  133. ShopStore.equalTo('company', company)
  134. ShopStore.equalTo('type', "catering")
  135. if (this.data.active == 0) {
  136. ShopStore.descending('isShow')
  137. }
  138. if (this.data.active == 1) {
  139. ShopStore.descending('score')
  140. }
  141. if (this.data.active == 3) {
  142. ShopStore.ascending('perCapita')
  143. }
  144. if (this.data.value) {
  145. ShopStore.contains('storeName', this.data.value)
  146. }
  147. let shopStores = await ShopStore.find()
  148. if (shopStores) {
  149. let listJSON = []
  150. for (let i = 0; i < shopStores.length; i++) {
  151. listJSON.push(shopStores[i].toJSON())
  152. }
  153. for (let i = 0; i < listJSON.length; i++) {
  154. let item = listJSON[i]
  155. if (item.location) {
  156. let distance = compute.computeDistance(
  157. this.data.latitude,
  158. this.data.longitude,
  159. item.location.latitude,
  160. item.location.longitude
  161. )
  162. item.distance = distance.toFixed(2)
  163. listJSON[i] = item
  164. }
  165. }
  166. //按距离排序
  167. if (this.data.active == 2) {
  168. listJSON = listJSON.sort((a, b) => {
  169. return a.distance - b.distance
  170. })
  171. }
  172. this.setData({
  173. list: listJSON
  174. })
  175. }
  176. },
  177. async getBanner() {
  178. let Banner = new Parse.Query('Banner')
  179. Banner.notEqualTo('isDeleted', "true")
  180. Banner.equalTo('company', company)
  181. Banner.equalTo('isEnabled', "true")
  182. Banner.equalTo('type', 'gourmet')
  183. let banner = await Banner.find()
  184. if (banner && banner.length > 0) {
  185. let listJSON = []
  186. banner.forEach(c => {
  187. listJSON.push(c.toJSON())
  188. })
  189. this.setData({
  190. banners: listJSON
  191. })
  192. }
  193. },
  194. }
  195. })