业务交流通
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

homepage.js 6.5KB

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