业务交流通
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

myCollect.js 5.2KB

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