articleDetails.js 2.9 KB

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