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" }).then(res => { if (res.confirm) { wx.showLoading({ title: '删除中' }) wx.cloud.callFunction({ name: 'deleteQuestion', data: { que_id: e.currentTarget.dataset.id } }).then(res => { wx.hideLoading() if (res.result.status !== 'OK') { wx.showToast({ title: res.result.errMsg, icon: 'none' }) return } for (let i = 0; i < this.data.questions.length; i++) { if (this.data.questions[i]._id === e.currentTarget.dataset.id) { this.data.questions.splice(i, 1) break } } this.setData({ questions: this.data.questions }) wx.showToast({ title: "删除成功", icon: 'none' }) }) } }) }, /** * 生命周期函数--监听页面加载 */ 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 }) }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })