Page({ /** * 页面的初始数据 */ data: { publisherId: '', questions: [], notAnswered: true, answered: true, top: false, }, updateText: function (e) { var arr = this.data.questions arr[e.target.dataset.index].answer = e.detail.value this.setData({ questions: arr }) }, updateFilter: function (e) { var check0 = false var check1 = false for (let i = 0; i < e.detail.value.length; i++) { if (e.detail.value[i] == 0) check0 = true if (e.detail.value[i] == 1) check1 = true } this.setData({ notAnswered: check0, answered: check1 }) }, top: function () { this.setData({ top: !this.data.top }) }, saveQuestion: function (e) { const db = wx.cloud.database() db.collection("qaData").doc(e.target.dataset.id).update({ data: { answer: e.target.dataset.answer, answerTime: new Date() }, success: function () { wx.showToast({ title: "保存成功", }) } }) }, removeQuestion: function (e) { wx.showModal({ content: "确认删除提问?", confirmColor: "#009195", success: function (res) { if (res.confirm) { const db = wx.cloud.database() db.collection("qaData").doc(e.target.dataset.id).remove({ success: function () { this.onLoad({ id: this.data.publisherId }) wx.showToast({ title: "删除成功", }) }.bind(this) }) } }.bind(this) }) }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.setData({ publisherId: options.id }) wx.showNavigationBarLoading() wx.cloud.callFunction({ name: 'listQuestions', data: { pub_id: this.data.publisherId, page_token: 0, page_size: 20 } }).then(res => { wx.hideNavigationBarLoading() if (res.result.status !== 'OK') { wx.showToast({ title: res.result.errMsg, icon: 'none' }) return } this.setData({ questions: res.result.list }) }) // this.setData({ // publisherId: options.id, // questions: [{ // title: "我是标题", // question: "我是问题?", // answer: "我是回答" // }] // }) // const db = wx.cloud.database() // db.collection("qaData").where({ // publisherId: this.data.publisherId, // }).orderBy("questionTime", "desc").get({ // success: async function (res) { // let arr = [] // for (let i = 0; i < res.data.length; i++) { // arr.push(db.collection("mainData").doc(res.data[i].activityId).get()) // } // arr = await Promise.all(arr) // for (let i = 0; i < res.data.length; i++) { // res.data[i].title = arr[i].data.title // } // this.setData({ // questions: res.data // }) // }.bind(this) // }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })