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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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: true,
  12. // 路由接受的参数
  13. currentData: {},
  14. // 感兴趣的需求----
  15. // item行加载
  16. itemLoading: false,
  17. // 数据是否加载完成
  18. isFinished: false,
  19. listData: [],
  20. page: 1,
  21. size: 10,
  22. total: 0,
  23. // 是否加载数据,true加载,false不加载
  24. onRefresh: true,
  25. currentIndex: -1,
  26. // 当前登录器用户登录ID
  27. customerId: null,
  28. businessCommunicationDemandId: "",
  29. // 热门加载loading
  30. hotLoading: false,
  31. },
  32. /**
  33. * 生命周期函数--监听页面加载
  34. */
  35. onLoad(option) {
  36. this.setData({
  37. businessCommunicationDemandId: option.businessCommunicationDemandId
  38. })
  39. },
  40. onShow() {
  41. this.setData({
  42. pageLoading: true,
  43. })
  44. const businessCommunicationCustomer = wx.getStorageSync('businessCommunicationCustomer') || null;
  45. if (businessCommunicationCustomer) {
  46. this.setData({
  47. customerId: businessCommunicationCustomer.customerId
  48. })
  49. }
  50. // 获取当前数据
  51. this.getCurrentData();
  52. // 设置当前访问量
  53. this.setDemandCollect();
  54. },
  55. setDemandCollect() {
  56. let businessCommunicationDemandId = this.data.businessCommunicationDemandId;
  57. $request.post('/statisticsBusinessCommunicationDemand/saveDemandCollect.action',
  58. { businessCommunicationDemandId }
  59. ).then(res => { }).catch(err => { console.log(err) })
  60. $request.post('/statisticsBusinessCommunicationDemand/demandPageView.action',
  61. { businessCommunicationDemandId, customerId: this.data.customerId }
  62. ).then(res => { }).catch(err => { console.log(err) })
  63. },
  64. // 热门详情点击
  65. goDetails(e) {
  66. this.setData({
  67. currentData: null,
  68. type: [],
  69. pageLoading: true,
  70. listData: [],
  71. page: 1,
  72. onRefresh: true,
  73. isCollect: false,
  74. businessCommunicationDemandId: e.detail
  75. })
  76. this.getCurrentData();
  77. wx.pageScrollTo({
  78. scrollTop: 0,
  79. });
  80. },
  81. getCurrentData() {
  82. let { businessCommunicationDemandId, customerId } = this.data;
  83. let paramCustomerId = customerId ? customerId * 1 : null;
  84. console.log(paramCustomerId, 'paramCustomerId')
  85. $request.get('/businessCommunicationDemand/getDemandByDemandId.action',
  86. { demandId: businessCommunicationDemandId, customerId: paramCustomerId }
  87. ).then(res => {
  88. if (res.status == 0) {
  89. let listDetail = res.data.demandByDemandId;
  90. listDetail.createdOn = $util.formatTime(new Date(listDetail.createdOn), true);
  91. listDetail.createdOn = listDetail.createdOn.replaceAll('/', '-');
  92. if (typeof listDetail.type == 'string') {
  93. listDetail.type = listDetail.type.split(',');
  94. }
  95. this.setData({
  96. currentData: listDetail,
  97. type: listDetail.type,
  98. pageLoading: false,
  99. isCollect: res.data.booleanIsCollect == 0 ? false : true,
  100. })
  101. if (this.data.currentData.customerId != this.data.userCustomerId) {
  102. this.setData({
  103. hotLoading: true,
  104. })
  105. this.getListData();
  106. }
  107. }
  108. }).catch(err => {
  109. console.log(err, 'error appletLogin')
  110. })
  111. },
  112. // 切换收藏
  113. changeCollect() {
  114. let { currentData, customerId, isCollect } = this.data;
  115. if (!customerId) {
  116. app.goLogin();
  117. return
  118. }
  119. let url = "";
  120. let msg = "";
  121. // 如果已收藏就取消收藏 else 反之
  122. if (isCollect) {
  123. url = "/businessCommunicationCollect/deleteCollect.action",
  124. msg = "取消收藏成功"
  125. } else {
  126. url = "/businessCommunicationCollect/saveCollect.action",
  127. msg = "收藏成功"
  128. }
  129. wx.showLoading({
  130. title: '操作中...',
  131. mask: true
  132. })
  133. $request.post(url,
  134. { customerId, businessCommunicationDemandId: currentData.businessCommunicationDemandId }
  135. ).then(res => {
  136. wx.hideLoading()
  137. if (res.status == 0) {
  138. this.setData({
  139. isCollect: !isCollect
  140. })
  141. wx.showToast({
  142. title: msg,
  143. icon: 'success',
  144. duration: 2000
  145. })
  146. }
  147. }).catch(err => {
  148. console.log(error, 'error appletLogin')
  149. })
  150. },
  151. // 获取list数据
  152. getListData() {
  153. let { page, size, type, currentData } = this.data;
  154. if (typeof type == 'object') {
  155. type = type.join(',');
  156. }
  157. $request.get('/businessCommunicationDemand/getDemandByKeywordOrType.action',
  158. { page, size, type, isInterest: 1, demandId: currentData.businessCommunicationDemandId }
  159. ).then(res => {
  160. let tempListData = this.data.listData;
  161. if (res.status == 0) {
  162. let datas = res.data;
  163. // 先push数据
  164. tempListData.push(...datas.demandList);
  165. tempListData.forEach(el => {
  166. el.createdOn = $util.formatTime(new Date(el.createdOn), true);
  167. el.createdOn = el.createdOn.replaceAll('/', '-');
  168. if (typeof el.type == 'string') {
  169. el.type = el.type.split(',');
  170. }
  171. })
  172. // 设置总数
  173. this.setData({
  174. listData: tempListData,
  175. total: res.data.total,
  176. })
  177. // 如果数据大于了返回的总数
  178. if (tempListData.length >= this.data.total) {
  179. // 停止累加数据
  180. this.setData({
  181. onRefresh: false,
  182. itemLoading: false,
  183. isFinished: true,
  184. })
  185. } else {
  186. this.setData({
  187. onRefresh: true,
  188. itemLoading: false,
  189. isFinished: false,
  190. page: page + 1
  191. })
  192. }
  193. }
  194. this.setData({
  195. hotLoading: false,
  196. })
  197. }).catch(error => {
  198. console.log(error, 'error appletLogin')
  199. this.setData({
  200. hotLoading: false,
  201. })
  202. })
  203. },
  204. /*
  205. * 页面上拉触底事件的处理函数
  206. */
  207. onReachBottom() {
  208. if (this.data.onRefresh) {
  209. this.setData({
  210. itemLoading: true
  211. })
  212. this.getListData();
  213. }
  214. },
  215. /**
  216. * 用户点击右上角分享
  217. */
  218. onShareAppMessage() {
  219. return {
  220. title: "发现了一个适合你的需求!推荐你一起来关注~",
  221. imageUrl: '/images/home/ShareApp-details.png',
  222. path: 'pages/index/components/listDetails/Details?businessCommunicationDemandId=' + this.data.businessCommunicationDemandId
  223. }
  224. },
  225. })