index.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. let Parse = getApp().Parse;
  2. const company = getApp().globalData.company
  3. const compute = require("../../../../utils/compute.js");
  4. Component({
  5. /**
  6. * 组件的属性列表
  7. */
  8. properties: {
  9. },
  10. /**
  11. * 组件的初始数据
  12. */
  13. data: {
  14. department: [],
  15. banner: null,
  16. tabs: [{
  17. title: '村落推荐',
  18. icon: 'https://file.ruixiuauto.com/cDBRXuM6Xh/20230807/fq8811044112324.png'
  19. },
  20. {
  21. title: '美食推荐',
  22. icon: 'https://file.ruixiuauto.com/cDBRXuM6Xh/20230807/mp1e1k044119032.png'
  23. },
  24. {
  25. title: '民宿推荐',
  26. icon: 'https://file.ruixiuauto.com/cDBRXuM6Xh/20230807/qrnn1v044125861.png'
  27. },
  28. {
  29. title: '商超推荐',
  30. icon: 'https://file.ruixiuauto.com/cDBRXuM6Xh/20230807/g6bkbs044122180.png'
  31. },
  32. ],
  33. rankList: [{
  34. title: '村落'
  35. }, {
  36. title: '美食'
  37. }, {
  38. title: '民宿'
  39. }, {
  40. title: '商超'
  41. }],
  42. latitude: 0,
  43. longitude: 0,
  44. },
  45. lifetimes: {
  46. attached() {
  47. this.getData()
  48. }
  49. },
  50. /**
  51. * 组件的方法列表
  52. */
  53. methods: {
  54. async getData() {
  55. if (this.data.latitude == 0 && this.data.longitude == 0) {
  56. let {
  57. latitude,
  58. longitude
  59. } = await this.getLocation()
  60. this.setData({
  61. latitude,
  62. longitude
  63. })
  64. }
  65. this.getBanner()
  66. this.getRank()
  67. },
  68. getLocation() {
  69. return new Promise((resolve, reject) => {
  70. wx.getLocation({
  71. type: 'gcj02',
  72. success: (res) => {
  73. resolve({
  74. latitude: res.latitude,
  75. longitude: res.longitude
  76. })
  77. },
  78. fail: () => {
  79. resolve({
  80. latitude: 0,
  81. longitude: 0
  82. })
  83. },
  84. complete: () => {}
  85. });
  86. })
  87. },
  88. async getRank(){
  89. let {rankList} = this.data
  90. let village = await this.getDepartment()
  91. let catering = await this.getShopStore('catering')
  92. let stay = await this.getShopStore('stay')
  93. let shop = await this.getShopStore('shop')
  94. rankList[0]['contents']=village
  95. rankList[1]['contents']=catering
  96. rankList[2]['contents']=stay
  97. rankList[3]['contents']=shop
  98. this.setData({
  99. rankList,
  100. village
  101. })
  102. },
  103. goUrl(e){
  104. let {url} = e.currentTarget.dataset
  105. wx.navigateTo({
  106. url: url,
  107. })
  108. },
  109. tabsGoUrl(e){
  110. let {index} = e.currentTarget.dataset
  111. let url = ''
  112. switch (index) {
  113. case 0:
  114. url+=`/nova-tourism/pages/template-2/searching/index?index=${index}`
  115. break;
  116. case 1:
  117. url+=`/nova-tourism/pages/food-list/index`
  118. break;
  119. case 2:
  120. url+=`/nova-tourism/pages/homestay/hotel-list/index`
  121. break;
  122. case 3:
  123. url+=`/nova-tourism/pages/template-2/searching/index?index=${index}`
  124. break;
  125. default:
  126. break;
  127. }
  128. wx.navigateTo({
  129. url: url,
  130. })
  131. },
  132. rankToDetail(e){
  133. let {key,id} = e.currentTarget.dataset
  134. let url = ''
  135. if(key=='村落'){
  136. url = `/nova-tourism/pages/home/village/village-details/index?id=${id}`
  137. }else if(key=='美食'){
  138. url = `/nova-tourism/pages/gourmet/store-package/index?id=${id}`
  139. }else if(key=='民宿'){
  140. url = `/nova-tourism/pages/homestay/hotel-details/index?id=${id}`
  141. }else if(key=='商超'){
  142. wx.setStorageSync('storeID', id)
  143. url = `/nova-tourism/pages/index/index?active=3`
  144. }
  145. wx.navigateTo({
  146. url: url,
  147. })
  148. },
  149. async getShopStore(type) {
  150. let listDate= []
  151. let ShopStore = new Parse.Query('ShopStore')
  152. ShopStore.notEqualTo('isDeleted', "true")
  153. ShopStore.equalTo('company', company)
  154. ShopStore.equalTo('type', type)
  155. ShopStore.equalTo('isShow', "true")
  156. ShopStore.limit(4)
  157. let shopStores = await ShopStore.find()
  158. if (shopStores && shopStores.length > 0) {
  159. shopStores.forEach(c => {
  160. listDate.push(c.toJSON())
  161. })
  162. }
  163. return listDate
  164. },
  165. async getBanner() {
  166. let Banner = new Parse.Query('Banner')
  167. Banner.notEqualTo('isDeleted', "true")
  168. Banner.equalTo('company', company)
  169. Banner.equalTo('isEnabled', "true")
  170. Banner.equalTo('type','home')
  171. let banner = await Banner.find()
  172. if (banner && banner.length > 0) {
  173. let listJSON = []
  174. banner.forEach(c => {
  175. listJSON.push(c.toJSON())
  176. })
  177. this.setData({
  178. banner: listJSON
  179. })
  180. }
  181. },
  182. async getDepartment() {
  183. let Department = new Parse.Query('Department')
  184. Department.notEqualTo('isDeleted', "true")
  185. Department.equalTo('company', company)
  186. let department = await Department.find()
  187. if (department && department.length > 0) {
  188. let listJSON = []
  189. department.forEach(c => {
  190. let dJSON = c.toJSON()
  191. let distances = compute.computeDistance(
  192. this.data.latitude,
  193. this.data.longitude,
  194. dJSON.location.latitude,
  195. dJSON.location.longitude
  196. )
  197. dJSON.distances = distances
  198. listJSON.push(dJSON)
  199. })
  200. return listJSON
  201. }
  202. },
  203. },
  204. })