| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- // miniprogram/pages/receivedQuestion/receivedQuestion.js
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- questions: [],
- publisherId: "",
- notAnswered: true,
- answered: true
- },
- 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
- })
- },
- 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: "确认删除?",
- 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
- })
- 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 () {
- }
- })
|