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

myCollect.js 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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.setStorageSync('listDetail', e.detail)
  66. wx.navigateTo({
  67. url: '/pages/index/components/listDetails/Details',
  68. })
  69. },
  70. // 删除收藏
  71. delCollect(e) {
  72. let businessCommunicationDemandId = e.currentTarget.dataset.id;
  73. let customerId = this.data.customerId;
  74. console.log({ customerId, businessCommunicationDemandId });
  75. wx.showLoading({
  76. title: '操作中...',
  77. mask: true
  78. })
  79. $request.post("/businessCommunicationCollect/deleteCollect.action",
  80. { customerId, businessCommunicationDemandId }
  81. ).then(res => {
  82. wx.hideLoading()
  83. if (res.status == 0) {
  84. let listData = this.data.listData;
  85. listData.forEach((el, inx) => {
  86. if (el.businessCommunicationDemandId == businessCommunicationDemandId) {
  87. listData.splice(inx, 1);
  88. }
  89. })
  90. this.setData({
  91. listData
  92. })
  93. }
  94. }).catch(err => {
  95. console.log(error, 'error appletLogin')
  96. })
  97. },
  98. // 数据加载提示
  99. showLoading(title) {
  100. wx.showLoading({
  101. title: title ? title : '加载中',
  102. mask: true
  103. })
  104. },
  105. getListData() {
  106. let { page, size, customerId, keyword } = this.data;
  107. $request.get('/businessCommunicationDemand/getDemandByCustomerId.action',
  108. { page, size, customerId, keyword }
  109. ).then(res => {
  110. let tempListData = this.data.listData;
  111. if (res.status == 0) {
  112. let datas = res.data;
  113. console.log(datas, 'datas')
  114. // 先push数据
  115. tempListData.push(...datas.demandList);
  116. tempListData.forEach(el => {
  117. el.createdOn = $util.formatTime(new Date(el.createdOn), true);
  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. /**
  164. * 用户点击右上角分享
  165. */
  166. onShareAppMessage: function () {
  167. }
  168. })