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

Details.js 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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: null,
  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. if (app.globalData.customerId) {
  41. this.setData({
  42. customerId: app.globalData.customerId
  43. })
  44. this.getIsCollect();
  45. }else{
  46. this.getListData();
  47. }
  48. })
  49. },
  50. // 热门详情点击
  51. goDetails(e) {
  52. this.setData({
  53. currentData: e.detail,
  54. type: e.detail.type.join(),
  55. pageLoading: true,
  56. listData: [],
  57. page: 1,
  58. onRefresh: true,
  59. isCollect: false,
  60. })
  61. wx.pageScrollTo({
  62. scrollTop: 0,
  63. });
  64. this.getIsCollect();
  65. },
  66. // 判断是否收藏
  67. getIsCollect() {
  68. let { currentData, customerId } = this.data;
  69. $request.get('/businessCommunicationCollect/booleanIsCollect.action',
  70. { customerId, businessCommunicationDemandId: currentData.businessCommunicationDemandId }
  71. ).then(res => {
  72. if (res.status == 0) {
  73. this.setData({
  74. isCollect: res.data == 0 ? false : true
  75. })
  76. }
  77. this.getListData();
  78. }).catch(err => {
  79. console.log(error, 'error appletLogin')
  80. })
  81. },
  82. // 切换收藏
  83. changeCollect() {
  84. let { currentData, customerId, isCollect } = this.data;
  85. if(!customerId){
  86. app.goLogin();
  87. return
  88. }
  89. let url = "";
  90. let msg = "";
  91. // 如果已收藏就取消收藏 else 反之
  92. if (isCollect) {
  93. url = "/businessCommunicationCollect/deleteCollect.action",
  94. msg = "取消收藏成功"
  95. } else {
  96. url = "/businessCommunicationCollect/saveCollect.action",
  97. msg = "收藏成功"
  98. }
  99. wx.showLoading({
  100. title: '操作中...',
  101. mask: true
  102. })
  103. $request.post(url,
  104. { customerId, businessCommunicationDemandId: currentData.businessCommunicationDemandId }
  105. ).then(res => {
  106. wx.hideLoading()
  107. if (res.status == 0) {
  108. this.setData({
  109. isCollect: !isCollect
  110. })
  111. wx.showToast({
  112. title: msg,
  113. icon: 'success',
  114. duration: 2000
  115. })
  116. }
  117. }).catch(err => {
  118. console.log(error, 'error appletLogin')
  119. })
  120. },
  121. // 获取list数据
  122. getListData() {
  123. let { page, size, type, currentData } = this.data;
  124. $request.get('/businessCommunicationDemand/getDemandByKeywordOrType.action',
  125. { page, size, type, isInterest: 1, demandId: currentData.businessCommunicationDemandId }
  126. ).then(res => {
  127. this.setData({
  128. pageLoading: false,
  129. })
  130. let tempListData = this.data.listData;
  131. if (res.status == 0) {
  132. let datas = res.data;
  133. // 先push数据
  134. tempListData.push(...datas.demandList);
  135. tempListData.forEach(el => {
  136. el.createdOn = $util.formatTime(new Date(el.createdOn), true);
  137. if (typeof el.type == 'string') {
  138. el.type = el.type.split(',');
  139. }
  140. })
  141. // 设置总数
  142. this.setData({
  143. listData: tempListData,
  144. total: res.data.total,
  145. })
  146. // 如果数据大于了返回的总数
  147. if (tempListData.length >= this.data.total) {
  148. // 停止累加数据
  149. this.setData({
  150. onRefresh: false,
  151. itemLoading: false,
  152. isFinished: true,
  153. })
  154. } else {
  155. this.setData({
  156. onRefresh: true,
  157. itemLoading: false,
  158. isFinished: false,
  159. page: page + 1
  160. })
  161. }
  162. }
  163. }).catch(error => {
  164. console.log(error, 'error appletLogin')
  165. })
  166. },
  167. /*
  168. * 页面上拉触底事件的处理函数
  169. */
  170. onReachBottom() {
  171. if (this.data.onRefresh) {
  172. this.setData({
  173. itemLoading: true
  174. })
  175. this.getListData();
  176. }
  177. },
  178. /**
  179. * 用户点击右上角分享
  180. */
  181. onShareAppMessage: function () {
  182. }
  183. })