业务交流通
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

homepage.js 6.5KB

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