index.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. const util = require('../../utils/util.js');
  2. const api = require('../../config/api.js');
  3. const user = require('../../services/user.js');
  4. import header from './data'
  5. import {
  6. Router
  7. } from '../../utils/router.js'
  8. const app = getApp()
  9. //获取应用实例
  10. Router({
  11. data: {
  12. // 头部导航栏的高度
  13. statusBarHeight: app.globalData.statusBarHeight,
  14. hasData: true,
  15. classifyList: [{
  16. type: 0,
  17. title: '新房',
  18. icon: "../../static/images/icon/house@2x.png",
  19. },
  20. {
  21. type: 1,
  22. title: '二手房',
  23. icon: "../../static/images/icon/second_hand@2x.png",
  24. },
  25. {
  26. type: 2,
  27. title: '公寓',
  28. icon: "../../static/images/icon/apartments@2x.png",
  29. },
  30. {
  31. type: 3,
  32. title: '民宿',
  33. icon: "../../static/images/icon/b&b@2x.png",
  34. },
  35. {
  36. type: 4,
  37. title: '社区',
  38. icon: "../../static/images/icon/community@2x.png",
  39. },
  40. ],
  41. type: '',
  42. middleType: 11,
  43. // type :-1:所有;0:新房;1:二手房;2:公寓;3:民宿;4:社区
  44. // 11:新上房源;12:热门房源;13:热门企业;
  45. // 21:商家列表;
  46. // 31:VR场景;32:VR直播间
  47. middleTabList: [{
  48. type: 11,
  49. title: '新上房源'
  50. },
  51. {
  52. type: 12,
  53. title: '热门房源'
  54. },
  55. {
  56. type: 13,
  57. title: '热门企业'
  58. },
  59. ],
  60. middleList: {},
  61. middleEmptyLength: 0,
  62. // middleList: [{
  63. // url: 'https://m4.publicimg.browser.qq.com/publicimg/pcqb/ewtab_yunying/477_266_datu_20210802.jpg',
  64. // title: '华发水岸1'
  65. // }, {
  66. // url: 'https://m4.publicimg.browser.qq.com/publicimg/pcqb/ewtab_yunying/477_266_datu_20210802.jpg',
  67. // title: '华发水岸1'
  68. // }, {
  69. // url: 'https://m4.publicimg.browser.qq.com/publicimg/pcqb/ewtab_yunying/477_266_datu_20210802.jpg',
  70. // title: '华发水岸1'
  71. // }, ],
  72. roomTabList: [{
  73. type: 0,
  74. title: '新房'
  75. },
  76. {
  77. type: 1,
  78. title: '二手房'
  79. },
  80. {
  81. type: 2,
  82. title: '公寓'
  83. },
  84. ],
  85. roomType: 0,
  86. roomList: [],
  87. city: app.globalData.city,
  88. fetcherData: {
  89. type: '',
  90. address: '',
  91. page: 1,
  92. size: 20,
  93. name: ''
  94. }
  95. },
  96. onShareAppMessage: function () {
  97. return {
  98. path: '/pages/index/index'
  99. }
  100. },
  101. middle_gotoWV: function (event) {
  102. let {
  103. id
  104. } = event.currentTarget.dataset
  105. console.log(id)
  106. wx.navigateTo({
  107. url: `/pages/webview/index?id=${id}`,
  108. })
  109. },
  110. gotoWV: function (event) {
  111. let id = event.detail
  112. wx.navigateTo({
  113. url: `/pages/webview/index?id=${id}`,
  114. })
  115. },
  116. onPullDownRefresh() {
  117. this.setData({
  118. roomList: [],
  119. 'fetcherData.page': 1,
  120. hasData: true
  121. });
  122. this.getRoomList()
  123. app.onPullDownRefresh()
  124. },
  125. onReachBottom: function () {
  126. this.getRoomList()
  127. console.log('onReachBottom')
  128. },
  129. inputFocus: function () {},
  130. changeMiddleTab(e) {
  131. let type = e.currentTarget.dataset.type
  132. this.setData({
  133. middleType: type
  134. })
  135. },
  136. changeRoomType(e) {
  137. let type = e.currentTarget.dataset.type
  138. this.setData({
  139. roomType: type,
  140. roomList: [],
  141. 'fetcherData.page': 1,
  142. hasData: true
  143. })
  144. this.getRoomList()
  145. },
  146. getRoomList() {
  147. if (this.data.hasData) {
  148. this.setData({
  149. 'fetcherData.type': this.data.roomType,
  150. })
  151. if (app.globalData.city == '全国') {
  152. this.setData({
  153. 'fetcherData.address': '',
  154. })
  155. } else {
  156. this.setData({
  157. 'fetcherData.address': app.globalData.city,
  158. })
  159. }
  160. util.request(api.BrandList, this.data.fetcherData).then((res) => {
  161. console.log(res)
  162. if (res.errno === 0) {
  163. if (res.data.data.length != 0) {
  164. this.setData({
  165. roomList: this.data.roomList.concat(res.data.data),
  166. 'fetcherData.page': this.data.fetcherData.page + 1
  167. })
  168. } else {
  169. this.setData({
  170. hasData: false
  171. })
  172. }
  173. }
  174. });
  175. } else {
  176. console.log('没有更多数据')
  177. }
  178. },
  179. getMiddleList(type) {
  180. let address
  181. if (app.globalData.city == '全国') {
  182. address = ''
  183. } else {
  184. address = app.globalData.city
  185. }
  186. util.request(api.BrandList, {
  187. type: type,
  188. address: address,
  189. page: 1,
  190. size: 3,
  191. name: '',
  192. }).then((res) => {
  193. console.log(res)
  194. if (res.errno === 0) {
  195. if (res.data.data.length == 0) {
  196. this.setData({
  197. middleEmptyLength: this.data.middleEmptyLength + 1
  198. })
  199. }
  200. let value = `middleList.${type}`
  201. this.setData({
  202. [value]: res.data.data
  203. })
  204. }
  205. });
  206. },
  207. toCity() {
  208. wx.navigateTo({
  209. url: `/pages/city/city`
  210. })
  211. },
  212. toSearch(e) {
  213. var type = e.currentTarget.dataset.type
  214. console.log(type)
  215. wx.navigateTo({
  216. url: `/pages/searchRoom/searchRoom?type=` + type
  217. })
  218. },
  219. onLoad: async function (options) {
  220. app.checkNetStatu();
  221. // 页面渲染完成
  222. this.getRoomList()
  223. for (let i = 0; i < this.data.middleTabList.length; i++) {
  224. this.getMiddleList(this.data.middleTabList[i].type)
  225. }
  226. },
  227. onReady: function () {
  228. console.log(2)
  229. },
  230. onShow: function (options) {
  231. console.log(3)
  232. // 页面显示
  233. let city = app.globalData.city
  234. if (city != this.data.city) {
  235. this.setData({
  236. 'city': app.globalData.city,
  237. middleEmptyLength: 0
  238. })
  239. this.getRoomList()
  240. for (let i = 0; i < this.data.middleTabList.length; i++) {
  241. this.getMiddleList(this.data.middleTabList[i].type)
  242. }
  243. }
  244. },
  245. onHide: function () {
  246. // 页面隐藏
  247. },
  248. onUnload: function () {
  249. // 页面关闭
  250. }
  251. })