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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. console.log(this.data.isOther)
  56. // 前往聊一聊
  57. if(this.data.isOther){
  58. console.log(this.data.customer)
  59. let customer = this.data.customer;
  60. wx.navigateTo({
  61. url: "/pages/msgModule/wechat2/wechat2",
  62. success: function (res) {
  63. // 通过eventChannel向被打开页面传送数据
  64. res.eventChannel.emit('customerid', { customerid: customer.customerId, chatHeads: customer.chatHeads })
  65. }
  66. })
  67. }
  68. // 前往发布需求
  69. else{
  70. wx.navigateTo({
  71. url: '/pages/releaseModule/index',
  72. })
  73. }
  74. },
  75. getListData() {
  76. let { page, size, customerId } = this.data;
  77. $request.get('/businessCommunicationDemand/getDemandHomePage.action',
  78. { page, size, customerId }
  79. ).then(res => {
  80. this.setData({
  81. pageLoading: false,
  82. })
  83. console.log(res)
  84. let tempListData = this.data.listData;
  85. if (res.status == 0) {
  86. let datas = res.data;
  87. console.log(datas,'datas')
  88. // 先push数据
  89. tempListData.push(...datas.demandList);
  90. tempListData.forEach(el => {
  91. el.createdOn = $util.formatTime(new Date(el.createdOn), true);
  92. el.createdOn = el.createdOn.replaceAll('/', '-');
  93. if (typeof el.type == 'string') {
  94. el.type = el.type.split(',');
  95. }
  96. })
  97. // datas.businessCommunicationCustomer.serviceProject = "公司注册,注销变更,银行开户,代理记账,园区合作,招募合作伙伴"
  98. // 设置总数
  99. this.setData({
  100. listData: tempListData,
  101. total:datas.total,
  102. customer: datas.businessCommunicationCustomer,
  103. beCollectDemand:datas.beCollectDemand,
  104. collectDemand:datas.collectDemand,
  105. postDemand:datas.postDemand,
  106. totalPageView:datas.totalPageView,
  107. })
  108. // 如果数据大于了返回的总数
  109. if (tempListData.length >= this.data.total) {
  110. // 停止累加数据
  111. this.setData({
  112. onRefresh: false,
  113. itemLoading: false,
  114. isFinished: true,
  115. })
  116. } else {
  117. this.setData({
  118. onRefresh: true,
  119. itemLoading: false,
  120. isFinished: false,
  121. page: page + 1
  122. })
  123. }
  124. console.log('-------------个人主页 beg-------------------')
  125. console.log(this.data.listData);
  126. console.log('-------------个人主页 end-------------------')
  127. }
  128. }).catch(error => {
  129. console.log(error, 'error appletLogin')
  130. })
  131. },
  132. /**
  133. * 页面上拉触底事件的处理函数
  134. */
  135. onReachBottom: function () {
  136. if (this.data.onRefresh) {
  137. this.setData({
  138. itemLoading: true
  139. })
  140. this.getListData();
  141. }
  142. },
  143. /**
  144. * 用户点击右上角分享
  145. */
  146. onShareAppMessage: function () {
  147. if(this.data.isOther){
  148. return {
  149. title: "发现了一个适合你的客户需求!推荐你一起来关注~",
  150. imageUrl: '/images/home/ShareApp-homePage2.png',
  151. path: 'pages/index/components/homepage/homepage'
  152. }
  153. }else{
  154. return {
  155. title: "分享给你我的需求信息!推荐你一起来关注~",
  156. imageUrl: '/images/home/ShareApp-homePage1.png',
  157. path: 'pages/index/components/homepage/homepage'
  158. }
  159. }
  160. }
  161. })