业务交流通
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

homepage.js 5.9KB

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