index.js 6.7 KB

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