index.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  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. value: '',
  15. active: 1,
  16. activeKey: 0,
  17. food: [],
  18. homestay: [],
  19. department: [],
  20. banner: null,
  21. active1:0,
  22. currentTab:0,
  23. tabs: [
  24. {
  25. title: '村落',
  26. icon: 'https://file-cloud.fmode.cn/sHNeVwSaAg/20230812/gu1jnl043245587.png'
  27. },
  28. {
  29. title: '美食',
  30. icon: 'https://file-cloud.fmode.cn/sHNeVwSaAg/20230812/53a71a043348365.png'
  31. },
  32. {
  33. title: '民宿',
  34. icon: 'https://file-cloud.fmode.cn/sHNeVwSaAg/20230812/ljkjrg043355069.png'
  35. },
  36. {
  37. title: '商超',
  38. icon: 'https://file-cloud.fmode.cn/sHNeVwSaAg/20230812/teofq2043403030.png'
  39. },
  40. ],
  41. tabIndex: 0,
  42. sidebarIndex: 0,
  43. type:'catering',
  44. rankList: [{
  45. title: '村落'
  46. }, {
  47. title: '美食'
  48. }, {
  49. title: '民宿'
  50. }, {
  51. title: '商超'
  52. }],
  53. latitude: 0,
  54. longitude: 0,
  55. },
  56. ready: async function() {
  57. // 在组件布局完成后执行,确保options参数中有data信息
  58. this.getData()
  59. },
  60. /**
  61. * 组件的方法列表
  62. */
  63. methods: {
  64. async getData() {
  65. // this.getShopStore()
  66. // this.gethomestay()
  67. if (this.data.latitude == 0 && this.data.longitude == 0) {
  68. let {
  69. latitude,
  70. longitude
  71. } = await this.getLocation()
  72. this.setData({
  73. latitude,
  74. longitude
  75. })
  76. }
  77. this.getBanner()
  78. this.getRank()
  79. this.getHomeShow()
  80. // this.getDepartment()
  81. },
  82. getLocation() {
  83. return new Promise((resolve, reject) => {
  84. wx.getLocation({
  85. type: 'gcj02',
  86. success: (res) => {
  87. resolve({
  88. latitude: res.latitude,
  89. longitude: res.longitude
  90. })
  91. },
  92. fail: () => {
  93. resolve({
  94. latitude: 0,
  95. longitude: 0
  96. })
  97. },
  98. complete: () => {}
  99. });
  100. })
  101. },
  102. async getRank(){
  103. let {rankList} = this.data
  104. let village = await this.getDepartment()
  105. let catering = await this.getShopStore('catering')
  106. let stay = await this.getShopStore('stay')
  107. let shop = await this.getShopStore('shop')
  108. rankList[0]['contents']=village
  109. rankList[1]['contents']=catering
  110. rankList[2]['contents']=stay
  111. rankList[3]['contents']=shop
  112. this.setData({
  113. rankList,
  114. village
  115. })
  116. },
  117. goUrl(e){
  118. let {url} = e.currentTarget.dataset
  119. wx.navigateTo({
  120. url: url,
  121. })
  122. },
  123. villagedetails(e) {
  124. let id = e.currentTarget.dataset.item.objectId
  125. wx.navigateTo({
  126. url: '/nova-tourism/pages/home/village/village-details/index?id=' + id
  127. });
  128. },
  129. onPullDownRefresh: function() {
  130. this.setData({
  131. pageNum: 1,
  132. theEnd: false
  133. }, () => {
  134. // this.getList().then(res => wx.stopPullDownRefresh())
  135. })
  136. },
  137. village() {
  138. wx.navigateTo({
  139. url: '/nova-tourism/pages/home/village/index'
  140. });
  141. },
  142. gourmet() {
  143. wx.navigateTo({
  144. url: '/nova-tourism/pages/gourmet/index'
  145. });
  146. },
  147. foodlist() {
  148. wx.navigateTo({
  149. url: '/nova-tourism/pages/food-list/index'
  150. });
  151. },
  152. homestay() {
  153. wx.navigateTo({
  154. url: '/nova-tourism/pages/homestay/hotel-list/index'
  155. });
  156. },
  157. hoteldetails(e) {
  158. let id = e.currentTarget.dataset.item.objectId
  159. wx.navigateTo({
  160. url: '/nova-tourism/pages/homestay/hotel-details/index?id=' + id
  161. });
  162. },
  163. storepackage(e) {
  164. let id = e.currentTarget.dataset.item.objectId
  165. wx.navigateTo({
  166. url: '/nova-tourism/pages/gourmet/store-package/index?id=' + id
  167. });
  168. },
  169. // homestay(e) {
  170. // let id = e.currentTarget.dataset.item.objectId
  171. // console.log(id);
  172. // wx.navigateTo({
  173. // url: '/nova-tourism/pages/homestay/hotel-details/index?id=' + id
  174. // });
  175. // },
  176. async getShopStore(type) {
  177. let listDate= []
  178. let ShopStore = new Parse.Query('ShopStore')
  179. ShopStore.notEqualTo('isDeleted', "true")
  180. ShopStore.equalTo('company', company)
  181. ShopStore.equalTo('type', type)
  182. ShopStore.equalTo('isShow', "true")
  183. ShopStore.limit(3)
  184. let shopStores = await ShopStore.find()
  185. if (shopStores && shopStores.length > 0) {
  186. shopStores.forEach(c => {
  187. listDate.push(c.toJSON())
  188. })
  189. }
  190. return listDate
  191. },
  192. async getHomeShow(){
  193. let discount = await this.descShopStore("perCapita")
  194. let hot = await this.descShopStore("score")
  195. this.setData({
  196. discount,
  197. hot
  198. })
  199. },
  200. async descShopStore(column) {
  201. let ShopStore = new Parse.Query('ShopStore')
  202. ShopStore.notEqualTo('isDeleted', "true")
  203. ShopStore.equalTo('company', company)
  204. ShopStore.equalTo('isShow', "true")
  205. ShopStore.descending(column)
  206. let shopStore = await ShopStore.first()
  207. let shop = {}
  208. if (shopStore?.id) {
  209. shop = shopStore.toJSON()
  210. }
  211. return shop
  212. },
  213. // async getShopStore() {
  214. // let { type } = this.data
  215. // this.setData({
  216. // listDate: []
  217. // })
  218. // let ShopStore = new Parse.Query('ShopStore')
  219. // ShopStore.equalTo('company', company)
  220. // ShopStore.equalTo('type', type)
  221. // ShopStore.equalTo('isShow', "true")
  222. // this.data.value && ShopStore.contains('storeName',this.data.value)
  223. // let shopStores = await ShopStore.find()
  224. // if (shopStores && shopStores.length > 0) {
  225. // let listJSON = []
  226. // shopStores.forEach(c => {
  227. // listJSON.push(c.toJSON())
  228. // })
  229. // this.setData({
  230. // listDate: listJSON
  231. // })
  232. // }
  233. // console.log(this.data.listDate);
  234. // },
  235. player() {
  236. console.log('播放视频')
  237. },
  238. async getBanner() {
  239. let Banner = new Parse.Query('Banner')
  240. Banner.notEqualTo('isDeleted', "true")
  241. Banner.equalTo('company', company)
  242. Banner.equalTo('isEnabled', "true")
  243. Banner.equalTo('type','home')
  244. let banner = await Banner.find()
  245. if (banner && banner.length > 0) {
  246. let listJSON = []
  247. banner.forEach(c => {
  248. listJSON.push(c.toJSON())
  249. })
  250. this.setData({
  251. banner: listJSON
  252. })
  253. }
  254. },
  255. async gethomestay() {
  256. let ShopStore = new Parse.Query('ShopStore')
  257. ShopStore.notEqualTo('isDeleted', "true")
  258. ShopStore.equalTo('company', company)
  259. ShopStore.equalTo('type', "stay")
  260. ShopStore.equalTo('isShow', "true")
  261. let shopStores = await ShopStore.find()
  262. if (shopStores && shopStores.length > 0) {
  263. let listJSON = []
  264. shopStores.forEach(c => {
  265. listJSON.push(c.toJSON())
  266. })
  267. this.setData({
  268. homestay: listJSON
  269. })
  270. }
  271. },
  272. async getDepartment() {
  273. let Department = new Parse.Query('Department')
  274. Department.notEqualTo('isDeleted', "true")
  275. Department.equalTo('company', company)
  276. let department = await Department.find()
  277. if (department && department.length > 0) {
  278. let listJSON = []
  279. department.forEach(c => {
  280. let dJSON = c.toJSON()
  281. let distances = compute.computeDistance(
  282. this.data.latitude,
  283. this.data.longitude,
  284. dJSON.location.latitude,
  285. dJSON.location.longitude
  286. )
  287. dJSON.distances = distances
  288. listJSON.push(dJSON)
  289. })
  290. return listJSON
  291. }
  292. },
  293. onSearch() {
  294. wx.showToast({
  295. title: `搜索 ${this.data.value}`,
  296. icon: 'none',
  297. });
  298. },
  299. onClick() {
  300. wx.showToast({
  301. title: `搜索 ${this.data.value}`,
  302. icon: 'none',
  303. });
  304. },
  305. onChange(e) {
  306. this.setData({
  307. value: e.detail,
  308. });
  309. this.getShopStore()
  310. },
  311. tabsGoUrl(e){
  312. let {index} = e.currentTarget.dataset
  313. let url = ''
  314. switch (index) {
  315. case 0:
  316. url+=`/nova-tourism/pages/template-2/searching/index?index=${index}`
  317. break;
  318. case 1:
  319. url+=`/nova-tourism/pages/food-list/index`
  320. break;
  321. case 2:
  322. url+=`/nova-tourism/pages/homestay/hotel-list/index`
  323. break;
  324. case 3:
  325. url+=`/nova-tourism/pages/template-2/searching/index?index=${index}`
  326. break;
  327. default:
  328. break;
  329. }
  330. wx.navigateTo({
  331. url: url,
  332. })
  333. },
  334. // 处理点击tab
  335. onTabClick(e) {
  336. let id = e.currentTarget.id;
  337. console.log(id);
  338. let objMap = {
  339. '1':{
  340. type:'catering'
  341. },
  342. '2':{
  343. type:'stay'
  344. },
  345. '3':{
  346. type:'shop'
  347. },
  348. }
  349. this.setData({
  350. tabIndex: id,
  351. })
  352. if(id > 0){
  353. this.setData({
  354. type:objMap[id].type
  355. })
  356. }
  357. id > 0 && this.getShopStore(objMap[id].equl)
  358. },
  359. onSidebarClick(e) {
  360. let id = e.currentTarget.id;
  361. this.setData({
  362. sidebarIndex: id,
  363. })
  364. },
  365. rankToDetail(e){
  366. let {key,id} = e.currentTarget.dataset
  367. let url = ''
  368. if(key=='村落'){
  369. url = `/nova-tourism/pages/home/village/village-details/index?id=${id}`
  370. }else if(key=='美食'){
  371. url = `/nova-tourism/pages/gourmet/store-package/index?id=${id}`
  372. }else if(key=='民宿'){
  373. url = `/nova-tourism/pages/homestay/hotel-details/index?id=${id}`
  374. }else if(key=='商超'){
  375. wx.setStorageSync('storeID', id)
  376. url = `/nova-tourism/pages/index/index?active=3`
  377. }
  378. wx.navigateTo({
  379. url: url,
  380. })
  381. },
  382. // switchNav: function (e) {
  383. // let page = this;
  384. // let id = e.target.id;
  385. // if (this.data.currentTab == id) {
  386. // return false;
  387. // } else {
  388. // page.setData({
  389. // currentTab: id
  390. // });
  391. // }
  392. // page.setData({
  393. // active1: id
  394. // });
  395. // },
  396. },
  397. })