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

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