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

Details.js 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. // pages/index/components/listDetails/Details.js
  2. const app = getApp()
  3. const $request = require('../../../../utils/request.js');
  4. const $util = require('../../../../utils/util.js');
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. // 页面Loading
  11. pageLoading: false,
  12. customerId: "666678",
  13. // 路由接受的参数
  14. currentData: {},
  15. // 感兴趣的需求----
  16. // item行加载
  17. itemLoading: false,
  18. // 数据是否加载完成
  19. isFinished: false,
  20. listData: [],
  21. page: 1,
  22. size: 10,
  23. total: 0,
  24. // 是否加载数据,true加载,false不加载
  25. onRefresh: true,
  26. currentIndex: 0,
  27. },
  28. /**
  29. * 生命周期函数--监听页面加载
  30. */
  31. onLoad(option) {
  32. const eventChannel = this.getOpenerEventChannel()
  33. // 监听acceptDataFromOpenerPage事件,获取上一页面通过eventChannel传送到当前页面的数据
  34. eventChannel.on('acceptDataFromOpenerPage', data => {
  35. this.setData({
  36. currentData: data.listDetail,
  37. type: data.listDetail.type.join(),
  38. pageLoading: true,
  39. })
  40. this.getIsCollect();
  41. })
  42. },
  43. // 热门详情点击
  44. goDetails(e) {
  45. this.setData({
  46. currentData: e.detail,
  47. type: e.detail.type.join(),
  48. pageLoading: true,
  49. listData: [],
  50. page: 1,
  51. onRefresh: true,
  52. isCollect: false,
  53. })
  54. wx.pageScrollTo({
  55. scrollTop: 0,
  56. });
  57. this.getIsCollect();
  58. },
  59. // 判断是否收藏
  60. getIsCollect() {
  61. let { currentData, customerId } = this.data;
  62. $request.get('/businessCommunicationCollect/booleanIsCollect.action',
  63. { customerId, businessCommunicationDemandId: currentData.businessCommunicationDemandId }
  64. ).then(res => {
  65. console.log(res);
  66. if (res.status == 0) {
  67. this.setData({
  68. isCollect: res.data == 0 ? false : true
  69. })
  70. }
  71. this.getListData();
  72. }).catch(err => {
  73. console.log(error, 'error appletLogin')
  74. })
  75. },
  76. // 切换收藏
  77. changeCollect() {
  78. // console.log(this.data.currentData)
  79. let { currentData, customerId, isCollect } = this.data;
  80. let url = "";
  81. let msg = "";
  82. // 如果已收藏就取消收藏 else 反之
  83. if (isCollect) {
  84. url = "/businessCommunicationCollect/deleteCollect.action",
  85. msg = "取消收藏成功"
  86. } else {
  87. url = "/businessCommunicationCollect/saveCollect.action",
  88. msg = "收藏成功"
  89. }
  90. wx.showLoading({
  91. title: '操作中...',
  92. mask: true
  93. })
  94. $request.post(url,
  95. { customerId, businessCommunicationDemandId: currentData.businessCommunicationDemandId }
  96. ).then(res => {
  97. wx.hideLoading()
  98. if (res.status == 0) {
  99. this.setData({
  100. isCollect: !isCollect
  101. })
  102. wx.showToast({
  103. title: msg,
  104. icon: 'success',
  105. duration: 2000
  106. })
  107. }
  108. }).catch(err => {
  109. console.log(error, 'error appletLogin')
  110. })
  111. },
  112. // 获取list数据
  113. getListData() {
  114. let { page, size, type, currentData } = this.data;
  115. $request.get('/businessCommunicationDemand/getDemandByKeywordOrType.action',
  116. { page, size, type, isInterest: 1, demandId: currentData.businessCommunicationDemandId }
  117. ).then(res => {
  118. this.setData({
  119. pageLoading: false,
  120. })
  121. let tempListData = this.data.listData;
  122. if (res.status == 0) {
  123. let datas = res.data;
  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: res.data.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. }
  154. }).catch(error => {
  155. console.log(error, 'error appletLogin')
  156. })
  157. },
  158. /*
  159. * 页面上拉触底事件的处理函数
  160. */
  161. onReachBottom() {
  162. if (this.data.onRefresh) {
  163. this.setData({
  164. itemLoading: true
  165. })
  166. this.getListData();
  167. }
  168. },
  169. /**
  170. * 用户点击右上角分享
  171. */
  172. onShareAppMessage: function () {
  173. }
  174. })