index.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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. loading: false,
  96. },
  97. onShareAppMessage: function () {
  98. return {
  99. path: '/pages/index/index'
  100. }
  101. },
  102. middle_gotoWV: function (event) {
  103. let {
  104. id
  105. } = event.currentTarget.dataset
  106. console.log(id)
  107. wx.navigateTo({
  108. url: `/pages/webview/index?id=${id}`,
  109. })
  110. },
  111. gotoWV: function (event) {
  112. let id = event.detail
  113. wx.navigateTo({
  114. url: `/pages/webview/index?id=${id}`,
  115. })
  116. },
  117. onPullDownRefresh() {
  118. this.setData({
  119. roomList: [],
  120. 'fetcherData.page': 1,
  121. hasData: true
  122. });
  123. this.getRoomList()
  124. app.onPullDownRefresh()
  125. },
  126. onReachBottom: function () {
  127. this.getRoomList()
  128. console.log('onReachBottom')
  129. },
  130. inputFocus: function () {},
  131. changeMiddleTab(e) {
  132. let type = e.currentTarget.dataset.type
  133. this.setData({
  134. middleType: type
  135. })
  136. },
  137. changeRoomType(e) {
  138. let type = e.currentTarget.dataset.type
  139. this.setData({
  140. roomType: type,
  141. roomList: [],
  142. 'fetcherData.page': 1,
  143. hasData: true
  144. })
  145. this.getRoomList()
  146. },
  147. getRoomList() {
  148. if (this.data.hasData) {
  149. this.setData({
  150. 'fetcherData.type': this.data.roomType,
  151. })
  152. if (app.globalData.city == '全国') {
  153. this.setData({
  154. 'fetcherData.address': '',
  155. })
  156. } else {
  157. this.setData({
  158. 'fetcherData.address': app.globalData.city,
  159. })
  160. }
  161. if (!this.data.loading) {
  162. this.setData({
  163. loading: true
  164. })
  165. util.request(api.BrandList, this.data.fetcherData).then((res) => {
  166. this.setData({
  167. loading: false
  168. })
  169. if (res.errno === 0) {
  170. if (res.data.data.length != 0) {
  171. this.setData({
  172. roomList: this.data.roomList.concat(res.data.data),
  173. 'fetcherData.page': this.data.fetcherData.page + 1
  174. })
  175. } else {
  176. this.setData({
  177. hasData: false
  178. })
  179. }
  180. }
  181. }).catch(err => {
  182. this.setData({
  183. loading: false
  184. })
  185. });
  186. }
  187. } else {
  188. console.log('没有更多数据')
  189. }
  190. },
  191. getMiddleList(type) {
  192. let address
  193. if (app.globalData.city == '全国') {
  194. address = ''
  195. } else {
  196. address = app.globalData.city
  197. }
  198. util.request(api.BrandList, {
  199. type: type,
  200. address: address,
  201. page: 1,
  202. size: 3,
  203. name: '',
  204. }).then((res) => {
  205. console.log(res)
  206. if (res.errno === 0) {
  207. if (res.data.data.length == 0) {
  208. this.setData({
  209. middleEmptyLength: this.data.middleEmptyLength + 1
  210. })
  211. }
  212. let value = `middleList.${type}`
  213. this.setData({
  214. [value]: res.data.data
  215. })
  216. }
  217. });
  218. },
  219. toCity() {
  220. wx.navigateTo({
  221. url: `/pages/city/city`
  222. })
  223. },
  224. toSearch(e) {
  225. var type = e.currentTarget.dataset.type
  226. console.log(type)
  227. wx.navigateTo({
  228. url: `/pages/searchRoom/searchRoom?type=` + type
  229. })
  230. },
  231. onLoad: async function (options) {
  232. app.checkNetStatu();
  233. // 页面渲染完成
  234. this.getRoomList()
  235. for (let i = 0; i < this.data.middleTabList.length; i++) {
  236. this.getMiddleList(this.data.middleTabList[i].type)
  237. }
  238. },
  239. onReady: function () {
  240. console.log(2)
  241. },
  242. onShow: function (options) {
  243. console.log(3)
  244. // 页面显示
  245. let city = app.globalData.city
  246. if (city != this.data.city) {
  247. this.setData({
  248. 'city': app.globalData.city,
  249. middleEmptyLength: 0
  250. })
  251. this.getRoomList()
  252. for (let i = 0; i < this.data.middleTabList.length; i++) {
  253. this.getMiddleList(this.data.middleTabList[i].type)
  254. }
  255. }
  256. },
  257. onHide: function () {
  258. // 页面隐藏
  259. },
  260. onUnload: function () {
  261. // 页面关闭
  262. }
  263. })