follow-list.js 968 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import UserApi from '../../apis/user'
  2. let app = getApp()
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. tabs: [
  9. { name: '新房', saleType: 1, house_list: []},
  10. { name: '二手房', saleType: 2, house_list: []},
  11. { name: '租房', saleType: 3, house_list: []},
  12. ]
  13. },
  14. /**
  15. * 生命周期函数--监听页面加载
  16. */
  17. onLoad: function (options) {
  18. this.fetchHistory(this.data.tabs[0].saleType)
  19. },
  20. fetchHistory (sale_type) {
  21. UserApi.fetchFocusHouses({
  22. user_id: app.globalData.userinfo.user_id,
  23. sale_type
  24. }).then(res => {
  25. let { tabs } = this.data
  26. tabs = tabs.map(item => {
  27. if (item.saleType === sale_type) {
  28. item.house_list = res.data.filter(item => item.sale_type == sale_type)
  29. }
  30. return item
  31. })
  32. this.setData({
  33. tabs: tabs
  34. })
  35. })
  36. },
  37. change (e) {
  38. const item = e.detail
  39. this.fetchHistory(item.saleType)
  40. }
  41. })