榆山
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

234 lines
6.3 KiB

const app = getApp()
const api = require('../../../../api/consult')
import { formatTimestamp } from '../../../../utils/util'
Page({
data: {
loadMoreType: 'loading',
loadMoreVisible: true,
tabList:['我的待回答','公共待回答','已经回答'],//tab列表
currentTabIndex:0,
currentQuestion:'',
pageNo: 1, // 分页页码
pageSize: 10, // 分页页长
isLoading: true,
timestamp:'',
answerInput:'',
questionList:[],
},
onHide:function(){
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.setData({
timestamp:formatTimestamp(new Date())
})
let param = {
pageIndex:this.data.pageNo,
pageSize:this.data.pageSize,
timestamp:this.data.timestamp,
designatedFlag:this.data.currentTabIndex==0?'1':'0'
}
this.getQuestionList(param)
},
getQuestionList(param){
api.getQuestionList(param).then((res)=>{
this.setData({
questionList:this.data.questionList.concat(res.data),
isLoading:false
})
this.setCollapse();
if(res.data.length<10){
this.setData({
loadMoreType:'none',
loadMoreVisible:true,
})
}else{
this.setData({
loadMoreType:"more",
loadMoreVisible:false
})
}
}).catch(err=>{
this.setData({
questionList:[],
isLoading:false,
loadMoreType:'none',
loadMoreVisible:true
})
})
},
getMyQuestionList(param){
api.getMyQuestionList(param).then((res)=>{
this.setData({
questionList:this.data.questionList.concat(res.data),
isLoading:false
})
this.setCollapse();
if(res.data.length<10){
this.setData({
loadMoreType:'none',
loadMoreVisible:true,
})
}else{
this.setData({
loadMoreType:"more",
loadMoreVisible:false
})
}
}).catch(err=>{
this.setData({
questionList:[],
isLoading:false,
loadMoreType:'none',
loadMoreVisible:true
})
})
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
onReachBottom(){
if(!this.data.isLoading && this.data.loadMoreType!='none'){
this.setData({
isLoading:true,
loadMoreVisible:true,
loadMoreType:'loading',
pageNo:this.data.pageNo+1
})
if(this.data.currentTabIndex!=2){
let param = {
pageIndex:this.data.pageNo,
pageSize:this.data.pageSize,
timestamp:this.data.timestamp,
designatedFlag:this.data.currentTabIndex==0?'1':'0'
}
this.getQuestionList(param)
}else{
let param = {
pageIndex:this.data.pageNo,
pageSize:this.data.pageSize,
timestamp:this.data.timestamp,
}
this.getMyQuestionList(param)
}
}
},
handleInput(e){
this.setData({
answerInput:e.detail.value
})
},
changeTab(e){
if(this.data.isLoading){
return false;
}
this.setData({
questionList:[],
currentQuestion:'',
answerInput:'',
currentTabIndex:e.detail.key,
loadMoreType:'loading',
loadMoreVisible:true,
isLoading:true,
pageSize:10,
pageNo:1,
timestamp:formatTimestamp(new Date())
})
this.selectComponent("#question-list").clearInput();
if(e.detail.key!=2){
let param = {
pageIndex:this.data.pageNo,
pageSize:this.data.pageSize,
timestamp:this.data.timestamp,
designatedFlag:this.data.currentTabIndex==0?'1':'0'
}
this.getQuestionList(param)
}else{
let param = {
pageIndex:this.data.pageNo,
pageSize:this.data.pageSize,
timestamp:this.data.timestamp,
}
this.getMyQuestionList(param)
}
},
openInput(e){
this.setData({
currentQuestion:e.detail,
answerInput:''
})
},
submitAnswer(e){
let param = {
questionId:e.detail.id,
answerContent:e.detail.answer
}
api.submitAnswer(param).then(()=>{
this.data.questionList.splice(this.data.currentQuestion,1);
this.selectComponent("#question-list").clearInput();
wx.showToast({
title: '回复成功',
icon:"none"
})
this.setData({
questionList:this.data.questionList,
currentQuestion:''
})
}).catch(err=>{
})
},
setCollapse: function() {
var query = wx.createSelectorQuery();
var that = this;
query.in(this.selectComponent('#question-list')).selectAll('#questionContent').boundingClientRect(function (rect) {
rect.forEach((v, i) => {
if (v.height > 60) { //判断高度,根据各种高度取折中
var set = "questionList[" + i + "].collapse";
var set1 = "questionList[" + i + "].showCollapse";
that.setData({
[set]: true,
[set1]: true,
})
}
})
}).exec();
query.in(this.selectComponent('#question-list')).selectAll('#answerContent').boundingClientRect(function (rect) {
rect.forEach((v, i) => {
console.log(v)
console.log(v.dataset.question)
if (v.height > 70) {
var set = "questionList[" + v.dataset.question + "].answerList[0].collapse";
var set1 = "questionList[" + v.dataset.question + "].answerList[0].showCollapse";
that.setData({
[set]: true,
[set1]: true,
})
}
})
}).exec();
},
//点击全文收起
changeCollapse: function(e){
var index = e.detail.currentTarget.dataset.index;
var questionIndex=e.detail.currentTarget.dataset.questionindex;
if(questionIndex===undefined){
var set = "questionList[" + index + "].collapse";
this.setData({
[set]: !this.data.questionList[index].collapse
})
}else{
var set = "questionList[" + questionIndex + "].answerList[0].collapse";
console.log(set)
this.setData({
[set]: !this.data.questionList[questionIndex].answerList[0].collapse
})
}
}
})