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.
 

144 lines
2.6 KiB

// pages/ask/info/index.js
import commonApi from "../../../utils/https/common"
Page({
/**
* 页面的初始数据
*/
data: {
list:[],
total:1,
page_no:1,
keyword:'',
info:null
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.setData({
id:options.id
})
commonApi._post("ask/getQuestionDetail",{
question_id:options.id
}).then(res=>{
this.setData({
info:res.data
})
console.log(res)
})
this.getList();
},
zan:function(e){
let id = e.currentTarget.dataset.id;
commonApi.user_post("ask/like",{
answer_id:id
}).then(res=>{
if(res.code==1){
let list = this.data.list;
list.map(item=>{
if(item.id==id){
item.is_like = item.is_like?false:true;
item.like_nums = item.is_like?(item.like_nums+1):(item.like_nums-1);
}
})
this.setData({
list:list
})
}
})
},
getList:function(){
let list = this.data.list;
if(list.length>=this.data.total) return;
commonApi.user_post("ask/getQuestionAnswers",{
question_id:this.data.id,
page_no:this.data.page_no,
page_num:10
}).then(res=>{
res.data.rows.map(item=>{
item.is_like = item.is_like?true:false;
})
this.setData({
page_no:this.data.page_no+1,
total:res.data.total,
list:list.concat(res.data.rows)
})
})
},
changeKeyword:function(e){
this.setData({
keyword:e.detail.value
})
},
postAns:function(){
if(!this.data.keyword){
wx.showToast({
title: '请输入回答内容',
icon: 'none'
})
return;
}
commonApi.user_post("ask/postAnswer",{
question_id:this.data.id,
answer:this.data.keyword
}).then(res=>{
if(res.code==1){
wx.showToast({
title: '提交成功',
icon:'success'
})
}
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
this.getList()
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})