circlesDetail.js 7.7 KB

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