circlesDetail.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. // pages/circlesDetail/circlesDetail.js
  2. const app = getApp();
  3. const request = require("../../utils/request.js");
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. bannerIndex: 0,
  10. contentId: null,
  11. info: {},
  12. scale: 1,
  13. commentList: [],
  14. focusStatus: false,
  15. iptValue: '',
  16. iptPla: '喜欢就给个评论呗~',
  17. reply_params: {
  18. contentId: null,
  19. comment: '',
  20. parentCommentId: null,
  21. atUserId: null
  22. },
  23. handleStatus: true,
  24. commentId: null,
  25. scene: null,
  26. deleteStatus: true
  27. },
  28. previewMedia(event) {
  29. let sources = this.data.info.imgUrlList.map((item, index)=>{
  30. return {url: item}
  31. });
  32. let current = event.currentTarget.dataset.index;
  33. wx.previewMedia({
  34. sources: sources,
  35. current: current
  36. })
  37. },
  38. toReport() {
  39. wx.navigateTo({
  40. url: '../report/report?targetType=Comment&targetId=' + this.data.commentId
  41. })
  42. },
  43. deleteComFun() {
  44. let that = this;
  45. request.postData(
  46. 'app/cont/comment/del',
  47. {commentId: that.data.commentId},
  48. res => {
  49. that.getDetailData()
  50. that.getCommentList()
  51. that.setData({
  52. commentId: null,
  53. handleStatus: true
  54. })
  55. wx.showToast({
  56. title: '删除成功',
  57. icon: 'none',
  58. duration: 2000
  59. })
  60. }
  61. )
  62. },
  63. pressReplyComment(event) {
  64. let userId = event.currentTarget.dataset.userid;
  65. let userId2 = app.globalData.userInfo.userId ? app.globalData.userInfo.userId : null;
  66. this.data.commentId = event.currentTarget.dataset.commentid ? event.currentTarget.dataset.commentid : null;
  67. if(userId == userId2) {
  68. this.setData({
  69. deleteStatus: false,
  70. commentId: this.data.commentId,
  71. handleStatus: !this.data.handleStatus
  72. })
  73. }else{
  74. this.setData({
  75. deleteStatus: true,
  76. commentId: this.data.commentId,
  77. handleStatus: !this.data.handleStatus
  78. })
  79. }
  80. },
  81. tapReplyComment(event) {
  82. let that = this;
  83. that.data.reply_params.contentId = that.data.contentId;
  84. that.data.reply_params.parentCommentId = event.currentTarget.dataset.commentid;
  85. that.data.reply_params.atUserId = event.currentTarget.dataset.userid;
  86. this.setData({
  87. focusStatus: true,
  88. reply_params: that.data.reply_params,
  89. iptPla: '@' + event.currentTarget.dataset.name
  90. })
  91. },
  92. sendComment(event) {
  93. let that = this;
  94. if(that.data.reply_params.atUserId){
  95. that.data.reply_params.comment = event.detail.value;
  96. request.postData(
  97. 'app/cont/comment/reply',
  98. that.data.reply_params,
  99. res => {
  100. that.data.reply_params.atUserId = null;
  101. that.setData({
  102. iptValue: '',
  103. reply_params: that.data.reply_params
  104. })
  105. that.getCommentList();
  106. },
  107. res => {
  108. that.data.reply_params.atUserId = null;
  109. that.setData({
  110. iptValue: '',
  111. reply_params: that.data.reply_params
  112. })
  113. }
  114. )
  115. }else{
  116. let comment = event.detail.value;
  117. request.postData(
  118. 'app/cont/comment',
  119. {contentId: that.data.contentId, comment: comment},
  120. res => {
  121. that.getCommentList();
  122. that.setData({
  123. iptValue: ''
  124. })
  125. },
  126. res => {
  127. console.log(res)
  128. }
  129. )
  130. }
  131. },
  132. iptBlurFun() {
  133. this.setData({
  134. iptPla: '喜欢就给个评论呗~'
  135. })
  136. },
  137. iptFun() {
  138. this.setData({
  139. focusStatus: !this.data.focusStatus
  140. })
  141. },
  142. commentlikeFun(event) {
  143. let that = this;
  144. let commentId = event.currentTarget.dataset.commentid;
  145. request.postData(
  146. 'app/op/like',
  147. {recordType: 'CommentList', outBusiId: commentId},
  148. res => {
  149. that.getCommentList();
  150. },
  151. res => {
  152. console.log(res)
  153. }
  154. )
  155. },
  156. commentCellikeFun(event) {
  157. let that = this;
  158. let commentId = event.currentTarget.dataset.commentid;
  159. request.postData(
  160. 'app/op/like/cancel',
  161. {recordType: 'CommentList', outBusiId: commentId},
  162. res => {
  163. that.getCommentList();
  164. },
  165. res => {
  166. console.log(res)
  167. }
  168. )
  169. },
  170. contentlikeFun() {
  171. let that = this;
  172. request.postData(
  173. 'app/op/like',
  174. {recordType: 'ContentLike', outBusiId: that.data.contentId},
  175. res => {
  176. that.getDetailData();
  177. },
  178. res => {
  179. console.log(res)
  180. }
  181. )
  182. },
  183. contentCellikeFun() {
  184. let that = this;
  185. request.postData(
  186. 'app/op/like/cancel',
  187. {recordType: 'ContentLike', outBusiId: that.data.contentId},
  188. res => {
  189. that.getDetailData();
  190. },
  191. res => {
  192. console.log(res)
  193. }
  194. )
  195. },
  196. getCommentList() {
  197. let that = this;
  198. request.getData(
  199. 'app/cont/comment/list',
  200. {contentId : that.data.contentId},
  201. res => {
  202. that.setData({
  203. commentList: res.data.data
  204. })
  205. },
  206. res => {
  207. console.log(res)
  208. }
  209. )
  210. },
  211. getDetailData() {
  212. let that = this;
  213. request.getData(
  214. 'app/cont/content/detail',
  215. {contentId : that.data.contentId},
  216. res => {
  217. let scale = request.getUrlKey(res.data.data.imgUrlList[0], 'scale');
  218. that.setData({
  219. info: res.data.data,
  220. scale: scale ? scale : 1
  221. })
  222. },
  223. res => {
  224. console.log(res)
  225. }
  226. )
  227. },
  228. backPge() {
  229. if(this.data.scene == 1007 || this.data.scene == 1008) {
  230. wx.switchTab({
  231. url: '../index/index'
  232. })
  233. }else{
  234. wx.navigateBack({
  235. delta: 1
  236. })
  237. }
  238. },
  239. bindchange(event) {
  240. this.setData({
  241. bannerIndex: event.detail.current
  242. })
  243. },
  244. /**
  245. * 生命周期函数--监听页面加载
  246. */
  247. onLoad(options) {
  248. this.setData({
  249. contentId: options.contentId
  250. })
  251. this.getDetailData()
  252. this.getCommentList()
  253. },
  254. /**
  255. * 生命周期函数--监听页面初次渲染完成
  256. */
  257. onReady() {
  258. },
  259. /**
  260. * 生命周期函数--监听页面显示
  261. */
  262. onShow() {
  263. this.setData({
  264. handleStatus: true
  265. })
  266. let EnterOptions = wx.getEnterOptionsSync()
  267. this.setData({
  268. scene: EnterOptions.scene
  269. })
  270. },
  271. /**
  272. * 生命周期函数--监听页面隐藏
  273. */
  274. onHide() {
  275. },
  276. /**
  277. * 生命周期函数--监听页面卸载
  278. */
  279. onUnload() {
  280. },
  281. /**
  282. * 页面相关事件处理函数--监听用户下拉动作
  283. */
  284. onPullDownRefresh() {
  285. },
  286. /**
  287. * 页面上拉触底事件的处理函数
  288. */
  289. onReachBottom() {
  290. let that = this;
  291. if(that.data.commentList.length>0) {
  292. let lastCommentId = Number(that.data.commentList[that.data.commentList.length-1].commentId);
  293. request.getData(
  294. 'app/cont/comment/list',
  295. {contentId : that.data.contentId, lastCommentId: lastCommentId},
  296. res => {
  297. if(res.data.data.length > 0) {
  298. that.setData({
  299. commentList: that.data.commentList.concat(res.data.data)
  300. })
  301. }
  302. },
  303. res => {
  304. console.log(res)
  305. }
  306. )
  307. }
  308. },
  309. /**
  310. * 用户点击右上角分享
  311. */
  312. onShareAppMessage() {
  313. let title = this.data.info.content
  314. let contentId = this.data.contentId
  315. let imageUrl = this.data.info.imgUrlList[0]
  316. return {
  317. title: title,
  318. imageUrl: imageUrl,
  319. path: '/pages/circlesDetail/circlesDetail?contentId=' + contentId
  320. }
  321. },
  322. onShareTimeline() {
  323. }
  324. })