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

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