业务交流通
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

Details.js 7.8KB

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