index.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. let Parse = getApp().Parse
  2. const company = getApp().globalData.company
  3. let navigationBarHeight = getApp().globalData.statusBarHeight + 44;
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. active: 0,
  10. stickytop: navigationBarHeight,
  11. objMap : {
  12. '0':{
  13. type:'village',
  14. title:"村落推荐"
  15. },
  16. '1':{
  17. type:'catering',
  18. title:"美食推荐"
  19. },
  20. '2':{
  21. type:'stay',
  22. title:"民宿推荐"
  23. },
  24. '3':{
  25. type:'shop',
  26. title:"商超推荐"
  27. },
  28. },
  29. activeColor:"#229293"
  30. },
  31. /**
  32. * 生命周期函数--监听页面加载
  33. */
  34. onLoad: function (options) {
  35. this.setData({
  36. activeColor:getApp().globalData.activeColor || '#229293'
  37. })
  38. let {index} = options
  39. if(index){
  40. let idx = Number(index)
  41. this.setData({
  42. active:idx
  43. })
  44. }
  45. if(this.data.active==0){
  46. this.getVillage()
  47. }else{
  48. let {objMap} =this.data
  49. this.getShopStore(objMap[this.data.active].type)
  50. }
  51. },
  52. goUrl(e){
  53. let {id} = e.currentTarget.dataset
  54. let {active} = this.data
  55. let url = ''
  56. if(active==0){
  57. url=`/nova-tourism/pages/home/village/village-details/index?id=${id}`
  58. }else if(active==1){
  59. url=`/nova-tourism/pages/gourmet/store-package/index?id=${id}`
  60. }else if(active==2){
  61. url=`/nova-tourism/pages/homestay/hotel-details/index?id=${id}`
  62. }else if(active==3){
  63. wx.setStorageSync('storeID',id);
  64. url=`/nova-tourism/pages/index/index?active=3`
  65. }
  66. wx.navigateTo({
  67. url: url,
  68. })
  69. },
  70. onChange(e){
  71. console.log(e);
  72. let {detail} = e
  73. this.setData({
  74. value:detail
  75. })
  76. this.tabChange()
  77. },
  78. async tabChange(e) {
  79. console.log(e);
  80. if(e?.detail){
  81. this.setData({
  82. active:e.detail.index,
  83. })
  84. }
  85. let {objMap} =this.data
  86. if(this.data.active==0){
  87. console.log('sdks');
  88. this.getVillage()
  89. }else{
  90. this.getShopStore(objMap[this.data.active].type)
  91. }
  92. console.log(this.data.listDate);
  93. },
  94. async getVillage(){
  95. let listJSON = []
  96. let Department = new Parse.Query('Department')
  97. Department.notEqualTo('isDeleted', "true")
  98. Department.equalTo('company', company)
  99. this.data.value && Department.contains('shortname', this.data.value)
  100. let department = await Department.find()
  101. if (department && department.length > 0) {
  102. department.forEach(c => {
  103. let dJSON = c.toJSON()
  104. listJSON.push(dJSON)
  105. })
  106. }
  107. this.setData({
  108. listDate:listJSON
  109. })
  110. console.log(this.data.listDate);
  111. },
  112. async getShopStore(type) {
  113. let listDate= []
  114. let ShopStore = new Parse.Query('ShopStore')
  115. ShopStore.notEqualTo('isDeleted', "true")
  116. ShopStore.equalTo('company', company)
  117. ShopStore.equalTo('type', type)
  118. ShopStore.equalTo('isShow', "true")
  119. this.data.value && ShopStore.contains('storeName', this.data.value)
  120. let shopStores = await ShopStore.find()
  121. if (shopStores && shopStores.length > 0) {
  122. shopStores.forEach(c => {
  123. listDate.push(c.toJSON())
  124. })
  125. }
  126. this.setData({
  127. listDate
  128. })
  129. },
  130. /**
  131. * 生命周期函数--监听页面初次渲染完成
  132. */
  133. onReady: function () {
  134. },
  135. /**
  136. * 生命周期函数--监听页面显示
  137. */
  138. onShow: function () {
  139. },
  140. /**
  141. * 生命周期函数--监听页面隐藏
  142. */
  143. onHide: function () {
  144. },
  145. /**
  146. * 生命周期函数--监听页面卸载
  147. */
  148. onUnload: function () {
  149. },
  150. /**
  151. * 页面相关事件处理函数--监听用户下拉动作
  152. */
  153. onPullDownRefresh: function () {
  154. },
  155. /**
  156. * 页面上拉触底事件的处理函数
  157. */
  158. onReachBottom: function () {
  159. },
  160. /**
  161. * 用户点击右上角分享
  162. */
  163. onShareAppMessage: function () {
  164. }
  165. })