业务交流通
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.1KB

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