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

Details.js 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. // pages/index/components/listDetails/Details.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. // 页面Loading
  11. pageLoading: false,
  12. // 路由接受的参数
  13. currentData: {},
  14. // 感兴趣的需求----
  15. // item行加载
  16. itemLoading: false,
  17. // 数据是否加载完成
  18. isFinished: false,
  19. listData: [],
  20. page: 1,
  21. size: 10,
  22. total: 0,
  23. // 是否加载数据,true加载,false不加载
  24. onRefresh: true,
  25. currentIndex: 0,
  26. },
  27. /**
  28. * 生命周期函数--监听页面加载
  29. */
  30. onLoad(option) {
  31. const eventChannel = this.getOpenerEventChannel()
  32. // 监听acceptDataFromOpenerPage事件,获取上一页面通过eventChannel传送到当前页面的数据
  33. eventChannel.on('acceptDataFromOpenerPage', data => {
  34. this.setData({
  35. currentData: data.listDetail,
  36. type: data.listDetail.type.join(),
  37. pageLoading: true,
  38. })
  39. this.getListData();
  40. })
  41. },
  42. // 热门详情点击
  43. goDetails(e){
  44. this.setData({
  45. currentData: e.detail,
  46. type: e.detail.type.join(),
  47. pageLoading: true,
  48. listData:[],
  49. page:1,
  50. onRefresh:true,
  51. })
  52. this.getListData();
  53. },
  54. // 获取list数据
  55. getListData() {
  56. let { page, size, type,currentData } = this.data;
  57. $request.get('/businessCommunicationDemand/getDemandByKeywordOrType.action',
  58. { page, size, type, isInterest: 1,demandId:currentData.businessCommunicationDemandId }
  59. ).then(res => {
  60. this.setData({
  61. pageLoading: false,
  62. })
  63. let tempListData = this.data.listData;
  64. if (res.status == 0) {
  65. let datas = res.data;
  66. // 先push数据
  67. tempListData.push(...datas.demandList);
  68. tempListData.forEach(el => {
  69. el.createdOn = $util.formatTime(new Date(el.createdOn), true);
  70. if (typeof el.type == 'string') {
  71. el.type = el.type.split(',');
  72. }
  73. })
  74. // 设置总数
  75. this.setData({
  76. listData: tempListData,
  77. total: res.data.total,
  78. })
  79. // 如果数据大于了返回的总数
  80. if (tempListData.length >= this.data.total) {
  81. // 停止累加数据
  82. this.setData({
  83. onRefresh: false,
  84. itemLoading: false,
  85. isFinished: true,
  86. })
  87. } else {
  88. this.setData({
  89. onRefresh: true,
  90. itemLoading: false,
  91. isFinished: false,
  92. page: page + 1
  93. })
  94. }
  95. console.log('-------------详情页 beg-------------------')
  96. console.log(this.data.listData);
  97. console.log('-------------详情页 end-------------------')
  98. }
  99. }).catch(error => {
  100. console.log(error, 'error appletLogin')
  101. })
  102. },
  103. /*
  104. * 页面上拉触底事件的处理函数
  105. */
  106. onReachBottom() {
  107. if (this.data.onRefresh) {
  108. this.setData({
  109. itemLoading: true
  110. })
  111. this.getListData();
  112. }
  113. },
  114. /**
  115. * 用户点击右上角分享
  116. */
  117. onShareAppMessage: function () {
  118. }
  119. })