业务交流通
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

myCollect.js 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. // pages/myModule/components/myRelease/myRelease.js
  2. const $request = require('../../../../utils/request.js');
  3. const $util = require('../../../../utils/util.js');
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. listLoading: false,
  10. customerId: null,
  11. // 我发布的需求----
  12. // item行加载
  13. itemLoading: false,
  14. // 数据是否加载完成
  15. isFinished: false,
  16. listData: [],
  17. page: 1,
  18. size: 10,
  19. total: 0,
  20. // 是否加载数据,true加载,false不加载
  21. onRefresh: true,
  22. // 搜索值
  23. keyword: "",
  24. },
  25. /**
  26. * 生命周期函数--监听页面加载
  27. */
  28. onLoad: function (options) {
  29. const eventChannel = this.getOpenerEventChannel()
  30. // 监听acceptDataFromOpenerPage事件,获取上一页面通过eventChannel传送到当前页面的数据
  31. eventChannel.on('customerid', data => {
  32. this.setData({
  33. customerId: data.customerid,
  34. listLoading: true,
  35. })
  36. this.getListData();
  37. })
  38. },
  39. // tab切换
  40. tabChange(e) {
  41. let code = e.currentTarget.dataset.code;
  42. this.setData({
  43. currentTab: code
  44. })
  45. this.toSearch();
  46. },
  47. // 搜索框输入同步值
  48. bindKeyInput: function (e) {
  49. this.setData({
  50. keyword: e.detail.value
  51. })
  52. },
  53. toSearch() {
  54. this.setData({
  55. listData: [],
  56. onRefresh: true,
  57. isFinished: false,
  58. listLoading: true,
  59. page: 1,
  60. })
  61. this.getListData();
  62. },
  63. // 进入详情
  64. goDetails(e) {
  65. wx.navigateTo({
  66. url: '/pages/index/components/listDetails/Details?businessCommunicationDemandId=' + e.detail,
  67. })
  68. },
  69. // 删除收藏
  70. delCollect(e) {
  71. let businessCommunicationDemandId = e.currentTarget.dataset.id;
  72. let customerId = this.data.customerId;
  73. console.log({ customerId, businessCommunicationDemandId });
  74. wx.showLoading({
  75. title: '操作中...',
  76. mask: true
  77. })
  78. $request.post("/businessCommunicationCollect/deleteCollect.action",
  79. { customerId, businessCommunicationDemandId }
  80. ).then(res => {
  81. wx.hideLoading()
  82. if (res.status == 0) {
  83. let listData = this.data.listData;
  84. listData.forEach((el, inx) => {
  85. if (el.businessCommunicationDemandId == businessCommunicationDemandId) {
  86. listData.splice(inx, 1);
  87. }
  88. })
  89. this.setData({
  90. listData
  91. })
  92. }
  93. }).catch(err => {
  94. console.log(error, 'error appletLogin')
  95. })
  96. },
  97. // 数据加载提示
  98. showLoading(title) {
  99. wx.showLoading({
  100. title: title ? title : '加载中',
  101. mask: true
  102. })
  103. },
  104. getListData() {
  105. let { page, size, customerId, keyword } = this.data;
  106. $request.get('/businessCommunicationDemand/getDemandByCustomerId.action',
  107. { page, size, customerId, keyword }
  108. ).then(res => {
  109. let tempListData = this.data.listData;
  110. if (res.status == 0) {
  111. let datas = res.data;
  112. console.log(datas, 'datas')
  113. // 先push数据
  114. tempListData.push(...datas.demandList);
  115. tempListData.forEach(el => {
  116. el.createdOn = $util.formatTime(new Date(el.createdOn), true);
  117. el.createdOn = el.createdOn.replaceAll('/', '-');
  118. if (typeof el.type == 'string') {
  119. el.type = el.type.split(',');
  120. }
  121. })
  122. // 设置总数
  123. this.setData({
  124. listData: tempListData,
  125. total: datas.total,
  126. })
  127. // 如果数据大于了返回的总数
  128. if (tempListData.length >= this.data.total) {
  129. // 停止累加数据
  130. this.setData({
  131. onRefresh: false,
  132. itemLoading: false,
  133. isFinished: true,
  134. })
  135. } else {
  136. this.setData({
  137. onRefresh: true,
  138. itemLoading: false,
  139. isFinished: false,
  140. page: page + 1
  141. })
  142. }
  143. }
  144. this.setData({
  145. listLoading: false,
  146. })
  147. }).catch(error => {
  148. console.log(error, 'error appletLogin')
  149. })
  150. },
  151. //
  152. /**
  153. * 页面上拉触底事件的处理函数
  154. */
  155. onReachBottom: function () {
  156. if (this.data.onRefresh) {
  157. this.setData({
  158. itemLoading: true
  159. })
  160. this.getListData();
  161. }
  162. },
  163. })