业务交流通
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

homepage.js 6.0KB

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