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

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