业务交流通
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

homepage.js 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. // pages/index/components/homepage/homepage.js
  2. const app = getApp()
  3. const $request = require('../../../../utils/request.js');
  4. const $util = require('../../../../utils/util.js');
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. pageLoading: false,
  11. customerId: null,
  12. // 我发布的需求----
  13. // item行加载
  14. itemLoading: false,
  15. // 数据是否加载完成
  16. isFinished: false,
  17. listData: [],
  18. page: 1,
  19. size: 10,
  20. total: 0,
  21. // 是否加载数据,true加载,false不加载
  22. onRefresh: true,
  23. // 顶部数据
  24. customer: {},
  25. // 被关注
  26. beCollectDemand: 0,
  27. // 关注
  28. collectDemand: 0,
  29. // 发布需求
  30. postDemand: 0,
  31. // 被浏览量
  32. totalPageView: 0,
  33. // 是他人主业还是个人主业
  34. isOther:false,
  35. },
  36. /**
  37. * 生命周期函数--监听页面加载
  38. */
  39. onLoad: function (options) {
  40. const eventChannel = this.getOpenerEventChannel()
  41. // 监听acceptDataFromOpenerPage事件,获取上一页面通过eventChannel传送到当前页面的数据
  42. eventChannel.on('customerid', data => {
  43. console.log(data,'customerid')
  44. this.setData({
  45. customerId: data.customerid,
  46. pageLoading: true,
  47. isOther:data.customerid != app.globalData.customerId
  48. })
  49. this.getListData();
  50. })
  51. },
  52. // 底部按钮点击
  53. footBtnClick(){
  54. console.log(`点击了底部按钮`)
  55. },
  56. getListData() {
  57. let { page, size, customerId } = this.data;
  58. $request.get('/businessCommunicationDemand/getDemandHomePage.action',
  59. { page, size, customerId }
  60. ).then(res => {
  61. this.setData({
  62. pageLoading: false,
  63. })
  64. console.log(res)
  65. let tempListData = this.data.listData;
  66. if (res.status == 0) {
  67. let datas = res.data;
  68. console.log(datas,'datas')
  69. // 先push数据
  70. tempListData.push(...datas.demandList);
  71. tempListData.forEach(el => {
  72. el.createdOn = $util.formatTime(new Date(el.createdOn), true);
  73. if (typeof el.type == 'string') {
  74. el.type = el.type.split(',');
  75. }
  76. })
  77. // datas.businessCommunicationCustomer.serviceProject = "公司注册,注销变更,银行开户,代理记账,园区合作,招募合作伙伴"
  78. // 设置总数
  79. this.setData({
  80. listData: tempListData,
  81. total:datas.total,
  82. customer: datas.businessCommunicationCustomer,
  83. beCollectDemand:datas.beCollectDemand,
  84. collectDemand:datas.collectDemand,
  85. postDemand:datas.postDemand,
  86. totalPageView:datas.totalPageView,
  87. })
  88. // 如果数据大于了返回的总数
  89. if (tempListData.length >= this.data.total) {
  90. // 停止累加数据
  91. this.setData({
  92. onRefresh: false,
  93. itemLoading: false,
  94. isFinished: true,
  95. })
  96. } else {
  97. this.setData({
  98. onRefresh: true,
  99. itemLoading: false,
  100. isFinished: false,
  101. page: page + 1
  102. })
  103. }
  104. console.log('-------------个人主页 beg-------------------')
  105. console.log(this.data.listData);
  106. console.log('-------------个人主页 end-------------------')
  107. }
  108. }).catch(error => {
  109. console.log(error, 'error appletLogin')
  110. })
  111. },
  112. /**
  113. * 页面上拉触底事件的处理函数
  114. */
  115. onReachBottom: function () {
  116. if (this.data.onRefresh) {
  117. this.setData({
  118. itemLoading: true
  119. })
  120. this.getListData();
  121. }
  122. },
  123. /**
  124. * 用户点击右上角分享
  125. */
  126. onShareAppMessage: function () {
  127. }
  128. })