业务交流通
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

Details.js 8.1KB

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