index.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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. showTab: false,
  26. stickytop: navigationBarHeight,
  27. tabs: [{
  28. title: '推荐',
  29. icon: 'https://s1.ax1x.com/2023/04/10/ppqEqdH.png'
  30. },
  31. {
  32. title: '评分',
  33. icon: 'https://s1.ax1x.com/2023/04/10/ppqkofx.png'
  34. },
  35. {
  36. title: '距离',
  37. icon: 'https://s1.ax1x.com/2023/04/10/ppqkIt1.png'
  38. },
  39. {
  40. title: '价格',
  41. icon: 'https://s1.ax1x.com/2023/04/10/ppqkh79.png'
  42. },
  43. ],
  44. tabIndex: 0,
  45. },
  46. lifetimes: {
  47. attached() {
  48. this.getData()
  49. }
  50. },
  51. /**
  52. * 组件的方法列表
  53. */
  54. methods: {
  55. async getData() {
  56. if (this.data.latitude == 0 && this.data.longitude == 0) {
  57. let {
  58. latitude,
  59. longitude
  60. } = await this.getLocation()
  61. this.setData({
  62. latitude,
  63. longitude
  64. })
  65. }
  66. this.getBanner()
  67. this.getShopStore()
  68. await this.getCategory()
  69. // this.data.textItem
  70. this.getShopRank(this.data.textItem)
  71. },
  72. async getBanner() {
  73. let Banner = new Parse.Query('Banner')
  74. Banner.notEqualTo('isDeleted', "true")
  75. Banner.equalTo('company', company)
  76. Banner.equalTo('isEnabled', "true")
  77. Banner.equalTo('type','homestay')
  78. let banner = await Banner.find()
  79. if (banner && banner.length > 0) {
  80. let listJSON = []
  81. banner.forEach(c => {
  82. listJSON.push(c.toJSON())
  83. })
  84. this.setData({
  85. banner: listJSON
  86. })
  87. }
  88. },
  89. async getCategory(){
  90. let cate = new Parse.Query("Category")
  91. cate.notEqualTo('isDeleted', "true")
  92. cate.equalTo("company",company)
  93. cate.equalTo("type",'foodTag')
  94. let cateDate = await cate.find()
  95. let cateList = []
  96. cateDate.forEach(res=>{
  97. let item = res.toJSON()
  98. cateList.push(item)
  99. })
  100. if(cateList.length){
  101. this.setData({
  102. textItem:cateList[0].objectId,
  103. })
  104. }
  105. this.setData({
  106. cateList
  107. })
  108. },
  109. goUrl(e) {
  110. let {
  111. url
  112. } = e.currentTarget.dataset
  113. wx.navigateTo({
  114. url: url,
  115. })
  116. },
  117. getLocation() {
  118. return new Promise((resolve, reject) => {
  119. wx.getLocation({
  120. type: 'gcj02',
  121. success: (res) => {
  122. resolve({
  123. latitude: res.latitude,
  124. longitude: res.longitude
  125. })
  126. },
  127. fail: () => {
  128. resolve({
  129. latitude: 0,
  130. longitude: 0
  131. })
  132. },
  133. complete: () => {}
  134. });
  135. })
  136. },
  137. onTabClick(e) {
  138. let index = e.currentTarget.dataset.index;
  139. this.setData({
  140. tabIndex: index,
  141. active: index
  142. })
  143. this.getShopStore()
  144. },
  145. async getShopStore() {
  146. let ShopStore = new Parse.Query('ShopStore')
  147. ShopStore.notEqualTo('isDeleted', "true")
  148. ShopStore.equalTo('company', company)
  149. ShopStore.equalTo('type', "catering")
  150. ShopStore.include("category")
  151. ShopStore.limit(10)
  152. if (this.data.active == 0) {
  153. ShopStore.descending('isShow')
  154. }
  155. if (this.data.active == 1) {
  156. ShopStore.descending('score')
  157. }
  158. if (this.data.active == 3) {
  159. ShopStore.ascending('perCapita')
  160. }
  161. // if (this.data.value) {
  162. // ShopStore.contains('storeName', this.data.value)
  163. // }
  164. let shopStores = await ShopStore.find()
  165. if (shopStores) {
  166. let listJSON = []
  167. for (let i = 0; i < shopStores.length; i++) {
  168. let json = shopStores[i].toJSON()
  169. let distances = compute.computeDistance(
  170. this.data.latitude,
  171. this.data.longitude,
  172. json.location.latitude,
  173. json.location.longitude
  174. )
  175. json.distances = distances
  176. listJSON.push(json)
  177. }
  178. //按距离排序
  179. if (this.data.active == 2) {
  180. listJSON = listJSON.sort((a, b) => {
  181. return a.distance - b.distance
  182. })
  183. }
  184. this.setData({
  185. list: listJSON
  186. })
  187. }
  188. },
  189. async getShopRank(id) {
  190. let ShopStore = new Parse.Query('ShopStore')
  191. ShopStore.notEqualTo('isDeleted', "true")
  192. ShopStore.equalTo('company', company)
  193. ShopStore.equalTo('type', "catering")
  194. ShopStore.equalTo('category', id)
  195. ShopStore.include("category")
  196. let shopStores = await ShopStore.find()
  197. if (shopStores) {
  198. let rankList = []
  199. for (let i = 0; i < shopStores.length; i++) {
  200. let json = shopStores[i].toJSON()
  201. rankList.push(json)
  202. }
  203. this.setData({
  204. rankList
  205. })
  206. }
  207. },
  208. changeText(e) {
  209. let {
  210. id
  211. } = e.currentTarget.dataset
  212. this.setData({
  213. textItem: id
  214. })
  215. this.getShopRank(id)
  216. }
  217. }
  218. })