index.js 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. let Parse = getApp().Parse;
  2. const company = getApp().globalData.company
  3. Component({
  4. /**
  5. * 组件的属性列表
  6. */
  7. properties: {
  8. },
  9. /**
  10. * 组件的初始数据
  11. */
  12. data: {
  13. value: '',
  14. active: 1,
  15. activeKey: 0,
  16. food: [],
  17. homestay: [],
  18. department: [],
  19. banners: [],
  20. active1:0,
  21. currentTab:0,
  22. tabs: [
  23. {
  24. title: '村落推荐',
  25. icon: 'https://s1.ax1x.com/2023/04/06/ppoPu9J.png'
  26. },
  27. {
  28. title: '美食推荐',
  29. icon: 'https://s1.ax1x.com/2023/04/06/ppoPmh4.png'
  30. },
  31. {
  32. title: '民宿推荐',
  33. icon: 'https://s1.ax1x.com/2023/04/06/ppoPZAU.png'
  34. },
  35. // {
  36. // title: '商超推荐',
  37. // icon: 'https://s1.ax1x.com/2023/04/06/ppoPE7T.png'
  38. // },
  39. ],
  40. tabIndex: 0,
  41. sidebarIndex: 0,
  42. // sidebars: [
  43. // {
  44. // time: '2023/04/07',
  45. // text: '今日首推景点'
  46. // },
  47. // {
  48. // time: '2023/04/07',
  49. // text: '今日特惠景点'
  50. // },
  51. // {
  52. // time: '2023/04/07',
  53. // text: '今日热门景点'
  54. // }
  55. // ]
  56. type:'catering'
  57. },
  58. ready: async function() {
  59. // 在组件布局完成后执行,确保options参数中有data信息
  60. this.getBanner()
  61. this.getData()
  62. },
  63. lifetimes: {
  64. attached() {
  65. }
  66. },
  67. /**
  68. * 组件的方法列表
  69. */
  70. methods: {
  71. getData() {
  72. // this.getShopStore()
  73. // this.gethomestay()
  74. this.getDepartment()
  75. },
  76. villagedetails(e) {
  77. let id = e.currentTarget.dataset.item.objectId
  78. wx.navigateTo({
  79. url: '/nova-tourism/pages/home/village/village-details/index?id=' + id
  80. });
  81. },
  82. onPullDownRefresh: function() {
  83. this.setData({
  84. pageNum: 1,
  85. theEnd: false
  86. }, () => {
  87. // this.getList().then(res => wx.stopPullDownRefresh())
  88. })
  89. },
  90. village() {
  91. wx.navigateTo({
  92. url: '/nova-tourism/pages/home/village/index'
  93. });
  94. },
  95. gourmet() {
  96. wx.navigateTo({
  97. url: '/nova-tourism/pages/gourmet/index'
  98. });
  99. },
  100. foodlist() {
  101. wx.navigateTo({
  102. url: '/nova-tourism/pages/food-list/index'
  103. });
  104. },
  105. homestay() {
  106. wx.navigateTo({
  107. url: '/nova-tourism/pages/homestay/hotel-list/index'
  108. });
  109. },
  110. hoteldetails(e) {
  111. let id = e.currentTarget.dataset.item.objectId
  112. wx.navigateTo({
  113. url: '/nova-tourism/pages/homestay/hotel-details/index?id=' + id
  114. });
  115. },
  116. storepackage(e) {
  117. let id = e.currentTarget.dataset.item.objectId
  118. wx.navigateTo({
  119. url: '/nova-tourism/pages/gourmet/store-package/index?id=' + id
  120. });
  121. },
  122. // homestay(e) {
  123. // let id = e.currentTarget.dataset.item.objectId
  124. // console.log(id);
  125. // wx.navigateTo({
  126. // url: '/nova-tourism/pages/homestay/hotel-details/index?id=' + id
  127. // });
  128. // },
  129. async getShopStore() {
  130. let { type } = this.data
  131. this.setData({
  132. listDate: []
  133. })
  134. let ShopStore = new Parse.Query('ShopStore')
  135. ShopStore.notEqualTo('isDeleted', "true")
  136. ShopStore.equalTo('company', company)
  137. ShopStore.equalTo('type', type)
  138. ShopStore.equalTo('isShow', "true")
  139. this.data.value && ShopStore.contains('storeName',this.data.value)
  140. let shopStores = await ShopStore.find()
  141. if (shopStores && shopStores.length > 0) {
  142. let listJSON = []
  143. shopStores.forEach(c => {
  144. listJSON.push(c.toJSON())
  145. })
  146. this.setData({
  147. listDate: listJSON
  148. })
  149. }
  150. console.log(this.data.listDate);
  151. },
  152. player() {
  153. console.log('播放视频')
  154. },
  155. async getBanner() {
  156. let Banner = new Parse.Query('Banner')
  157. Banner.notEqualTo('isDeleted', "true")
  158. Banner.equalTo('company', company)
  159. Banner.equalTo('isEnabled', "true")
  160. Banner.equalTo('type','home')
  161. let banner = await Banner.find()
  162. if (banner && banner.length > 0) {
  163. let listJSON = []
  164. banner.forEach(c => {
  165. listJSON.push(c.toJSON())
  166. })
  167. this.setData({
  168. banners: listJSON
  169. })
  170. }
  171. },
  172. async gethomestay() {
  173. let ShopStore = new Parse.Query('ShopStore')
  174. ShopStore.notEqualTo('isDeleted', "true")
  175. ShopStore.equalTo('company', company)
  176. ShopStore.equalTo('type', "stay")
  177. ShopStore.equalTo('isShow', "true")
  178. let shopStores = await ShopStore.find()
  179. if (shopStores && shopStores.length > 0) {
  180. let listJSON = []
  181. shopStores.forEach(c => {
  182. listJSON.push(c.toJSON())
  183. })
  184. this.setData({
  185. homestay: listJSON
  186. })
  187. }
  188. },
  189. async getDepartment() {
  190. let Department = new Parse.Query('Department')
  191. Department.notEqualTo('isDeleted', "true")
  192. Department.equalTo('company', company)
  193. Department.limit(3)
  194. let department = await Department.find()
  195. if (department && department.length > 0) {
  196. let listJSON = []
  197. department.forEach(c => {
  198. let dJSON = c.toJSON()
  199. let imageExtend = [
  200. "png","jpg","jpeg","ico","gif", "JPG","PNG","JPEG","ICO","GIF"
  201. ]
  202. let videoExtend = [
  203. "mp4","flv","avi", "MP4", "FLV", "AIV"
  204. ]
  205. let nameArray = dJSON.logo ? dJSON.logo.split(".") : ''
  206. let extend = nameArray.length>0?nameArray[nameArray.length-1]:""
  207. let logoType
  208. if(imageExtend.indexOf(extend)>-1){
  209. logoType = "image"
  210. }
  211. if(videoExtend.indexOf(extend)>-1){
  212. logoType = "video"
  213. }
  214. dJSON.logoType = logoType
  215. listJSON.push(dJSON)
  216. })
  217. this.setData({
  218. department: listJSON
  219. })
  220. console.log(this.data.department);
  221. }
  222. },
  223. onSearch() {
  224. wx.showToast({
  225. title: `搜索 ${this.data.value}`,
  226. icon: 'none',
  227. });
  228. },
  229. onClick() {
  230. wx.showToast({
  231. title: `搜索 ${this.data.value}`,
  232. icon: 'none',
  233. });
  234. },
  235. onChange(e) {
  236. this.setData({
  237. value: e.detail,
  238. });
  239. this.getShopStore()
  240. },
  241. // 处理点击tab
  242. onTabClick(e) {
  243. let id = e.currentTarget.id;
  244. console.log(id);
  245. let objMap = {
  246. '1':{
  247. type:'catering'
  248. },
  249. '2':{
  250. type:'stay'
  251. },
  252. '3':{
  253. type:'shop'
  254. },
  255. }
  256. this.setData({
  257. tabIndex: id,
  258. })
  259. if(id > 0){
  260. this.setData({
  261. type:objMap[id].type
  262. })
  263. }
  264. id > 0 && this.getShopStore(objMap[id].equl)
  265. },
  266. onSidebarClick(e) {
  267. let id = e.currentTarget.id;
  268. this.setData({
  269. sidebarIndex: id,
  270. })
  271. },
  272. // switchNav: function (e) {
  273. // let page = this;
  274. // let id = e.target.id;
  275. // if (this.data.currentTab == id) {
  276. // return false;
  277. // } else {
  278. // page.setData({
  279. // currentTab: id
  280. // });
  281. // }
  282. // page.setData({
  283. // active1: id
  284. // });
  285. // },
  286. },
  287. })