index.js 6.5 KB

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