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

myCollect.js 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. wx.showLoading({
  74. title: '操作中...',
  75. mask: true
  76. })
  77. $request.post("/businessCommunicationCollect/deleteCollect.action",
  78. { customerId, businessCommunicationDemandId }
  79. ).then(res => {
  80. wx.hideLoading()
  81. if (res.status == 0) {
  82. let listData = this.data.listData;
  83. listData.forEach((el, inx) => {
  84. if (el.businessCommunicationDemandId == businessCommunicationDemandId) {
  85. listData.splice(inx, 1);
  86. }
  87. })
  88. this.setData({
  89. listData
  90. })
  91. }
  92. }).catch(err => {
  93. console.log(error, 'error appletLogin')
  94. })
  95. },
  96. // 数据加载提示
  97. showLoading(title) {
  98. wx.showLoading({
  99. title: title ? title : '加载中',
  100. mask: true
  101. })
  102. },
  103. getListData() {
  104. let { page, size, customerId, keyword } = this.data;
  105. $request.get('/businessCommunicationDemand/getDemandByCustomerId.action',
  106. { page, size, customerId, keyword }
  107. ).then(res => {
  108. let tempListData = this.data.listData;
  109. if (res.status == 0) {
  110. let datas = res.data;
  111. // 先push数据
  112. tempListData.push(...datas.demandList);
  113. tempListData.forEach(el => {
  114. el.createdOn = $util.formatTime(new Date(el.createdOn), true);
  115. el.createdOn = el.createdOn.replaceAll('/', '-');
  116. if (typeof el.type == 'string') {
  117. el.type = el.type.split(',');
  118. }
  119. })
  120. // 设置总数
  121. this.setData({
  122. listData: tempListData,
  123. total: datas.total,
  124. })
  125. // 如果数据大于了返回的总数
  126. if (tempListData.length >= this.data.total) {
  127. // 停止累加数据
  128. this.setData({
  129. onRefresh: false,
  130. itemLoading: false,
  131. isFinished: true,
  132. })
  133. } else {
  134. this.setData({
  135. onRefresh: true,
  136. itemLoading: false,
  137. isFinished: false,
  138. page: page + 1
  139. })
  140. }
  141. }
  142. this.setData({
  143. listLoading: false,
  144. })
  145. }).catch(error => {
  146. console.log(error, 'error appletLogin')
  147. })
  148. },
  149. //
  150. /**
  151. * 页面上拉触底事件的处理函数
  152. */
  153. onReachBottom: function () {
  154. if (this.data.onRefresh) {
  155. this.setData({
  156. itemLoading: true
  157. })
  158. this.getListData();
  159. }
  160. },
  161. })