index.js 5.8 KB

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