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

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