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

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