articleDetails.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. import {
  2. icommunity
  3. } from '../../../api/api.js'
  4. const app = getApp()
  5. Page({
  6. data: {
  7. pagination: {
  8. page: 1,
  9. pagesize: 100
  10. },
  11. imgList: [],
  12. imgUrl: app.globalData.imgUrl,
  13. allowComments: false,
  14. swiperHeight: 0
  15. },
  16. clickPic(e) {
  17. wx.previewImage({
  18. current: this.data.imgList[e.currentTarget.dataset.i],
  19. urls: this.data.imgList
  20. })
  21. },
  22. clickFavor() {
  23. icommunity.loadArticleFavorToggle({
  24. reqdata: {
  25. id: this.data.article.id
  26. }
  27. }, r => {
  28. this.loadArticledetails()
  29. })
  30. },
  31. clickCollection() {
  32. icommunity.loadArticleCollectionToggle({
  33. reqdata: {
  34. id: this.data.article.id
  35. }
  36. }, r => {
  37. this.loadArticledetails()
  38. })
  39. },
  40. clickCommentconfirm() {
  41. if (!this.data.comment) {
  42. return wx.showToast({
  43. icon: 'loading',
  44. title: '请输入内容',
  45. })
  46. }
  47. icommunity.loadAddArticlecomment({
  48. reqdata: {
  49. id: this.data.article.id,
  50. content: this.data.comment
  51. }
  52. }, r => {
  53. wx.showToast({
  54. icon: 'success',
  55. title: '提交成功',
  56. })
  57. this.setData({
  58. comment: '',
  59. isFocused: false
  60. })
  61. this.loadArticlecomments(true)
  62. })
  63. },
  64. inputComment(e) {
  65. this.setData({
  66. comment: e.detail.value,
  67. })
  68. },
  69. blurComment() {
  70. this.setData({
  71. isFocused: false
  72. })
  73. },
  74. focusComment() {
  75. this.setData({
  76. isFocused: true
  77. })
  78. },
  79. loadArticlecomments(hideLoading) {
  80. icommunity.loadArticlecomments(this.data.pagination, r => {
  81. this.setData({
  82. comments: r.list,
  83. ['article.num_comment']: r.list.length
  84. })
  85. }, hideLoading)
  86. },
  87. hideComments() {
  88. this.setData({
  89. showComments: false
  90. })
  91. },
  92. clickComments() {
  93. if (!this.data.showComments) {
  94. this.loadArticlecomments()
  95. }
  96. this.setData({
  97. showComments: !this.data.showComments
  98. })
  99. },
  100. loadArticledetails() {
  101. icommunity.loadArticledetails({
  102. reqdata: {
  103. id: this.data.article.id
  104. }
  105. }, r => {
  106. console.log(r)
  107. this.setData({
  108. imgList:r.object.filePath&&r.object.filePath.split(','),
  109. article: r.object
  110. })
  111. })
  112. },
  113. onLoad(args) {
  114. this.setData({
  115. allowComments: app.config.open_comment == 1,
  116. article: app.data.nav.communityArticle,
  117. ['pagination.reqdata.id']: app.data.nav.communityArticle.id
  118. })
  119. this.loadArticledetails()
  120. },
  121. // onReady() {
  122. // setTimeout(() => {
  123. // this.swiperAutoHeight()
  124. // }, 300)
  125. // },
  126. swiperAutoHeight() {
  127. let imgs = this.data.article.upload_url_list
  128. for (let i in imgs) {
  129. wx.createSelectorQuery()
  130. .select(`#img${i}`).boundingClientRect()
  131. .select(`#fake${i}`).boundingClientRect().exec(rect => {
  132. let h = rect[1].top - rect[0].top
  133. console.log(h)
  134. this.setData({
  135. swiperHeight: h > this.data.swiperHeight ? h : this.data.swiperHeight
  136. })
  137. })
  138. }
  139. }
  140. })