index.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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. /**默认餐厅照片 */
  16. defaultCover:'https://file-cloud.fmode.cn/sHNeVwSaAg/20230812/j1aeh1052327045.jpg?imageView2/1/w/200/h/200',
  17. imgUrls: [
  18. 'https://file-cloud.fmode.cn/sHNeVwSaAg/20230530/v61567044111362.png',
  19. 'https://file-cloud.fmode.cn/sHNeVwSaAg/20230530/aijk11044111180.png',
  20. 'https://file-cloud.fmode.cn/sHNeVwSaAg/20230530/6eqp18044111072.web',
  21. 'https://file-cloud.fmode.cn/sHNeVwSaAg/20230530/5rv371044110921.png'
  22. ],
  23. latitude: 0,
  24. longitude: 0,
  25. active: 0,
  26. list: [],
  27. value: null,
  28. showTab: false,
  29. stickytop: navigationBarHeight,
  30. tabs: [
  31. {
  32. title: '推荐',
  33. icon: 'https://s1.ax1x.com/2023/04/10/ppqEqdH.png'
  34. },
  35. {
  36. title: '评分',
  37. icon: 'https://s1.ax1x.com/2023/04/10/ppqkofx.png'
  38. },
  39. {
  40. title: '距离',
  41. icon: 'https://s1.ax1x.com/2023/04/10/ppqkIt1.png'
  42. },
  43. {
  44. title: '价格',
  45. icon: 'https://s1.ax1x.com/2023/04/10/ppqkh79.png'
  46. },
  47. ],
  48. tabIndex: 0,
  49. },
  50. lifetimes: {
  51. attached() {
  52. this.getData()
  53. }
  54. },
  55. // ready: function() {
  56. // // 在组件布局完成后执行,确保options参数中有data信息
  57. // this.getData()
  58. // // this.selectComponent('#tabs').resize();
  59. // },
  60. navigateComments(e) {
  61. let id = e.currentTarget.dataset.item.objectId
  62. wx.navigateTo({
  63. url: `/nova-tourism/pages/gourmet/store-package/comment/index?id=` + id
  64. })
  65. },
  66. /**
  67. * 组件的方法列表
  68. */
  69. methods: {
  70. async getData() {
  71. if (this.data.latitude == 0 && this.data.longitude == 0) {
  72. let { latitude, longitude } = await this.getLocation()
  73. this.setData({
  74. latitude,
  75. longitude,
  76. })
  77. }
  78. this.getBanner()
  79. this.getShopStore()
  80. await this.getCategory()
  81. this.getShopRank(this.data.textItem)
  82. },
  83. async getBanner() {
  84. let Banner = new Parse.Query('Banner')
  85. Banner.equalTo('company', company)
  86. Banner.equalTo('isEnabled', "true")
  87. Banner.notEqualTo('isDeleted', "true")
  88. Banner.equalTo('type','homestay')
  89. let banner = await Banner.find()
  90. console.log(banner);
  91. if (banner && banner.length > 0) {
  92. let listJSON = []
  93. banner.forEach(c => {
  94. listJSON.push(c.toJSON())
  95. })
  96. this.setData({
  97. banner: listJSON
  98. })
  99. }
  100. },
  101. /**获取美食分类 */
  102. async getCategory(){
  103. let cate = new Parse.Query("Category")
  104. cate.equalTo("company",company)
  105. cate.notEqualTo('isDeleted', "true")
  106. cate.equalTo("type",'foodTag')
  107. let cateDate = await cate.find()
  108. console.log(cateDate)
  109. let cateList = []
  110. cateDate.forEach(res=>{
  111. let item = res.toJSON()
  112. cateList.push(item)
  113. })
  114. console.log(cateList)
  115. if(cateList.length){
  116. this.setData({
  117. textItem:cateList[0]?.objectId,
  118. })
  119. }
  120. this.setData({
  121. cateList
  122. })
  123. },
  124. /** 选择美食分类*/
  125. changeText(e) {
  126. let {
  127. id
  128. } = e.currentTarget.dataset
  129. this.setData({
  130. textItem: id
  131. })
  132. this.getShopRank(id)
  133. },
  134. /**获取美食排行 */
  135. async getShopRank(id) {
  136. let ShopStore = new Parse.Query('ShopStore')
  137. ShopStore.equalTo('company', company)
  138. ShopStore.equalTo('type', "catering")
  139. ShopStore.notEqualTo('isDeleted', "true")
  140. ShopStore.equalTo('category', id)
  141. ShopStore.include("category")
  142. let shopStores = await ShopStore.find()
  143. if (shopStores) {
  144. let rankList = []
  145. for (let i = 0; i < shopStores.length; i++) {
  146. let json = shopStores[i].toJSON()
  147. rankList.push(json)
  148. }
  149. this.setData({
  150. rankList
  151. })
  152. }
  153. },
  154. storepackage(e) {
  155. let id = e.currentTarget.dataset.item.objectId
  156. wx.navigateTo({
  157. url: '/nova-tourism/pages/gourmet/store-package/index?id=' + id
  158. });
  159. },
  160. getLocation() {
  161. return new Promise((resolve, reject) => {
  162. wx.getLocation({
  163. type: 'gcj02',
  164. success: (res) => {
  165. resolve({
  166. latitude: res.latitude,
  167. longitude: res.longitude
  168. })
  169. },
  170. fail: () => {},
  171. complete: () => {}
  172. });
  173. })
  174. },
  175. onTabClick(e) {
  176. console.log(e);
  177. let index = e.currentTarget.dataset.index;
  178. this.setData({
  179. // tabIndex: index,
  180. active: index
  181. })
  182. this.getShopStore()
  183. // this.getCategory()
  184. },
  185. onClick() {
  186. this.setData({
  187. value: null,
  188. });
  189. },
  190. // onChan(e) {
  191. // this.setData({
  192. // value: e.detail,
  193. // });
  194. // this.getCategory()
  195. // this.getShopStore()
  196. // },
  197. // onChange(event) {
  198. // let active = event.detail.name
  199. // this.setData({
  200. // active: active
  201. // })
  202. // this.getCategory()
  203. // this.getShopStore()
  204. // },
  205. async getShopStore() {
  206. let ShopStore = new Parse.Query('ShopStore')
  207. ShopStore.equalTo('company', company)
  208. ShopStore.notEqualTo('isDeleted', "true")
  209. ShopStore.equalTo('type', "catering")
  210. if (this.data.active == 0) {
  211. ShopStore.descending('isShow')
  212. }
  213. if (this.data.active == 1) {
  214. ShopStore.descending('score')
  215. }
  216. if (this.data.active == 3) {
  217. ShopStore.ascending('perCapita')
  218. }
  219. if (this.data.value) {
  220. ShopStore.contains('storeName', this.data.value)
  221. }
  222. let shopStores = await ShopStore.find()
  223. if (shopStores) {
  224. let listJSON = []
  225. for (let i = 0; i < shopStores.length; i++) {
  226. listJSON.push(shopStores[i].toJSON())
  227. }
  228. for (let i = 0; i < listJSON.length; i++) {
  229. let item = listJSON[i]
  230. if (item.location) {
  231. let distance = compute.computeDistance(
  232. this.data.latitude,
  233. this.data.longitude,
  234. item.location.latitude,
  235. item.location.longitude
  236. )
  237. item.distance = distance.toFixed(2)
  238. listJSON[i] = item
  239. }
  240. }
  241. //按距离排序
  242. if (this.data.active == 2) {
  243. listJSON = listJSON.sort((a, b) => {
  244. return a.distance - b.distance
  245. })
  246. }
  247. this.setData({
  248. list: listJSON
  249. })
  250. }
  251. },
  252. }
  253. })