业务交流通
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

myRelease.js 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. tabs: [
  10. {
  11. tab: "发布中",
  12. code: 'release'
  13. },
  14. {
  15. tab: "已下架",
  16. code: 'remove'
  17. }
  18. ],
  19. currentTab: 'release',
  20. listLoading: false,
  21. customerId: null,
  22. // 我发布的需求----
  23. // item行加载
  24. itemLoading: false,
  25. // 数据是否加载完成
  26. isFinished: false,
  27. listData: [],
  28. page: 1,
  29. size: 10,
  30. total: 0,
  31. // 是否加载数据,true加载,false不加载
  32. onRefresh: true,
  33. // 搜索值
  34. keyword: "",
  35. },
  36. /**
  37. * 生命周期函数--监听页面加载
  38. */
  39. onLoad: function (options) {
  40. const eventChannel = this.getOpenerEventChannel()
  41. // 监听acceptDataFromOpenerPage事件,获取上一页面通过eventChannel传送到当前页面的数据
  42. eventChannel.on('customerid', data => {
  43. console.log(data)
  44. this.setData({
  45. customerId: data.customerid,
  46. listLoading: true,
  47. })
  48. this.getListData();
  49. })
  50. },
  51. // tab切换
  52. tabChange(e) {
  53. let code = e.currentTarget.dataset.code;
  54. this.setData({
  55. currentTab: code
  56. })
  57. this.toSearch();
  58. },
  59. // 搜索框输入同步值
  60. bindKeyInput: function (e) {
  61. this.setData({
  62. keyword: e.detail.value
  63. })
  64. },
  65. toSearch() {
  66. this.setData({
  67. listData: [],
  68. onRefresh: true,
  69. isFinished: false,
  70. listLoading: true,
  71. page: 1,
  72. })
  73. this.getListData();
  74. },
  75. // 上架/下架需求
  76. productRelease(e) {
  77. let item = e.currentTarget.dataset.item;
  78. let that = this;
  79. wx.showModal({
  80. title: '提示',
  81. content: "是否确认下架?",
  82. confirmText: "确认",
  83. cancelText: "取消",
  84. success(res) {
  85. if (res.confirm) {
  86. that.productReleasePost(item);
  87. }
  88. }
  89. })
  90. },
  91. productReleasePost(item) {
  92. let { businessCommunicationDemandId, state } = item;
  93. $request.post(`/businessCommunicationDemand/outDemand.action`, { businessCommunicationDemandId, state }
  94. ).then(res => {
  95. if (res.status == 0) {
  96. wx.showToast({
  97. title: state == 0 ? '下架' : '上架' + '成功',
  98. icon: 'success',
  99. duration: 2000
  100. })
  101. let listData = this.data.listData;
  102. listData.forEach(el => {
  103. if (el.businessCommunicationDemandId == businessCommunicationDemandId) {
  104. el.state = state == 0 ? 1 : 0;
  105. }
  106. })
  107. this.setData({
  108. listData
  109. })
  110. }
  111. }).catch(error => {
  112. console.log(error, 'error appletLogin')
  113. })
  114. },
  115. getListData() {
  116. let { page, size, customerId, keyword, currentTab } = this.data;
  117. $request.get('/businessCommunicationDemand/getDemandByStateAndCustomerId.action',
  118. { page, size, customerId, keyword, state: currentTab }
  119. ).then(res => {
  120. let tempListData = this.data.listData;
  121. if (res.status == 0) {
  122. let datas = res.data;
  123. console.log(datas, 'datas')
  124. // 先push数据
  125. tempListData.push(...datas.demandList);
  126. tempListData.forEach(el => {
  127. el.createdOn = $util.formatTime(new Date(el.createdOn), true);
  128. if (typeof el.type == 'string') {
  129. el.type = el.type.split(',');
  130. }
  131. })
  132. // 设置总数
  133. this.setData({
  134. listData: tempListData,
  135. total: datas.total,
  136. })
  137. // 如果数据大于了返回的总数
  138. if (tempListData.length >= this.data.total) {
  139. // 停止累加数据
  140. this.setData({
  141. onRefresh: false,
  142. itemLoading: false,
  143. isFinished: true,
  144. })
  145. } else {
  146. this.setData({
  147. onRefresh: true,
  148. itemLoading: false,
  149. isFinished: false,
  150. page: page + 1
  151. })
  152. }
  153. console.log('-------------个人主页 beg-------------------')
  154. console.log(this.data.listData);
  155. console.log('-------------个人主页 end-------------------')
  156. }
  157. this.setData({
  158. listLoading: false,
  159. })
  160. }).catch(error => {
  161. console.log(error, 'error appletLogin')
  162. })
  163. },
  164. /**
  165. * 页面上拉触底事件的处理函数
  166. */
  167. onReachBottom: function () {
  168. if (this.data.onRefresh) {
  169. this.setData({
  170. itemLoading: true
  171. })
  172. this.getListData();
  173. }
  174. },
  175. /**
  176. * 用户点击右上角分享
  177. */
  178. onShareAppMessage: function () {
  179. }
  180. })