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

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