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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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. listData:[],
  105. })
  106. this.getListData();
  107. }
  108. }
  109. }).catch(err => {
  110. console.log(err, 'error appletLogin')
  111. })
  112. },
  113. // 切换收藏
  114. changeCollect() {
  115. let { currentData, customerId, isCollect } = this.data;
  116. if (!customerId) {
  117. app.goLogin();
  118. return
  119. }
  120. let url = "";
  121. let msg = "";
  122. // 如果已收藏就取消收藏 else 反之
  123. if (isCollect) {
  124. url = "/businessCommunicationCollect/deleteCollect.action",
  125. msg = "取消收藏成功"
  126. } else {
  127. url = "/businessCommunicationCollect/saveCollect.action",
  128. msg = "收藏成功"
  129. }
  130. wx.showLoading({
  131. title: '操作中...',
  132. mask: true
  133. })
  134. $request.post(url,
  135. { customerId, businessCommunicationDemandId: currentData.businessCommunicationDemandId }
  136. ).then(res => {
  137. wx.hideLoading()
  138. if (res.status == 0) {
  139. this.setData({
  140. isCollect: !isCollect
  141. })
  142. wx.showToast({
  143. title: msg,
  144. icon: 'success',
  145. duration: 2000
  146. })
  147. }
  148. }).catch(err => {
  149. console.log(error, 'error appletLogin')
  150. })
  151. },
  152. // 获取list数据
  153. getListData() {
  154. let { page, size, type, currentData } = this.data;
  155. if (typeof type == 'object') {
  156. type = type.join(',');
  157. }
  158. $request.get('/businessCommunicationDemand/getDemandByKeywordOrType.action',
  159. { page, size, type, isInterest: 1, demandId: currentData.businessCommunicationDemandId }
  160. ).then(res => {
  161. let tempListData = this.data.listData;
  162. if (res.status == 0) {
  163. let datas = res.data;
  164. // 先push数据
  165. tempListData.push(...datas.demandList);
  166. tempListData.forEach(el => {
  167. el.createdOn = $util.formatTime(new Date(el.createdOn), true);
  168. el.createdOn = el.createdOn.replaceAll('/', '-');
  169. if (typeof el.type == 'string') {
  170. el.type = el.type.split(',');
  171. }
  172. })
  173. // 设置总数
  174. this.setData({
  175. listData: tempListData,
  176. total: res.data.total,
  177. })
  178. // 如果数据大于了返回的总数
  179. if (tempListData.length >= this.data.total) {
  180. // 停止累加数据
  181. this.setData({
  182. onRefresh: false,
  183. itemLoading: false,
  184. isFinished: true,
  185. })
  186. } else {
  187. this.setData({
  188. onRefresh: true,
  189. itemLoading: false,
  190. isFinished: false,
  191. page: page + 1
  192. })
  193. }
  194. }
  195. this.setData({
  196. hotLoading: false,
  197. })
  198. }).catch(error => {
  199. console.log(error, 'error appletLogin')
  200. this.setData({
  201. hotLoading: false,
  202. })
  203. })
  204. },
  205. /*
  206. * 页面上拉触底事件的处理函数
  207. */
  208. onReachBottom() {
  209. if (this.data.onRefresh) {
  210. this.setData({
  211. itemLoading: true
  212. })
  213. this.getListData();
  214. }
  215. },
  216. /**
  217. * 用户点击右上角分享
  218. */
  219. onShareAppMessage() {
  220. return {
  221. title: "发现了一个适合你的需求!推荐你一起来关注~",
  222. imageUrl: '/images/home/ShareApp-details.png',
  223. path: 'pages/index/components/listDetails/Details?businessCommunicationDemandId=' + this.data.businessCommunicationDemandId
  224. }
  225. },
  226. })