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

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