123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- import {
- icommunity
- } from '../../../api/api.js'
- const app = getApp()
- Page({
- data: {
- pagination: {
- page: 1,
- pagesize: 100
- },
- imgList: [],
- imgUrl: app.globalData.imgUrl,
- allowComments: false,
- swiperHeight: 0
- },
- clickPic(e) {
- wx.previewImage({
- current: this.data.article.upload_url_list[e.currentTarget.dataset.i],
- urls: this.data.article.upload_url_list
- })
- },
- clickFavor() {
- icommunity.loadArticleFavorToggle({
- reqdata: {
- id: this.data.article.id
- }
- }, r => {
- this.loadArticledetails()
- })
- },
- clickCollection() {
- icommunity.loadArticleCollectionToggle({
- reqdata: {
- id: this.data.article.id
- }
- }, r => {
- this.loadArticledetails()
- })
- },
- clickCommentconfirm() {
- if (!this.data.comment) {
- return wx.showToast({
- icon: 'loading',
- title: '请输入内容',
- })
- }
- icommunity.loadAddArticlecomment({
- reqdata: {
- id: this.data.article.id,
- content: this.data.comment
- }
- }, r => {
- wx.showToast({
- icon: 'success',
- title: '提交成功',
- })
- this.setData({
- comment: '',
- isFocused: false
- })
- this.loadArticlecomments(true)
- })
- },
- inputComment(e) {
- this.setData({
- comment: e.detail.value,
- })
- },
- blurComment() {
- this.setData({
- isFocused: false
- })
- },
- focusComment() {
- this.setData({
- isFocused: true
- })
- },
- loadArticlecomments(hideLoading) {
- icommunity.loadArticlecomments(this.data.pagination, r => {
- this.setData({
- comments: r.list,
- ['article.num_comment']: r.list.length
- })
- }, hideLoading)
- },
- hideComments() {
- this.setData({
- showComments: false
- })
- },
- clickComments() {
- if (!this.data.showComments) {
- this.loadArticlecomments()
- }
- this.setData({
- showComments: !this.data.showComments
- })
- },
- loadArticledetails() {
- icommunity.loadArticledetails({
- reqdata: {
- id: this.data.article.id
- }
- }, r => {
- console.log(r)
- this.setData({
- imgList:r.object.filePath.split(','),
- article: r.object
- })
- })
- },
- onLoad(args) {
- this.setData({
- allowComments: app.config.open_comment == 1,
- article: app.data.nav.communityArticle,
- ['pagination.reqdata.id']: app.data.nav.communityArticle.id
- })
- this.loadArticledetails()
- },
- // onReady() {
- // setTimeout(() => {
- // this.swiperAutoHeight()
- // }, 300)
- // },
- swiperAutoHeight() {
- let imgs = this.data.article.upload_url_list
- for (let i in imgs) {
- wx.createSelectorQuery()
- .select(`#img${i}`).boundingClientRect()
- .select(`#fake${i}`).boundingClientRect().exec(rect => {
- let h = rect[1].top - rect[0].top
- console.log(h)
- this.setData({
- swiperHeight: h > this.data.swiperHeight ? h : this.data.swiperHeight
- })
- })
- }
- }
- })
|