index.js 6.6 KB

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