receivedQuestion.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. // miniprogram/pages/receivedQuestion/receivedQuestion.js
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. questions: [],
  8. publisherId: "",
  9. notAnswered: true,
  10. answered: true
  11. },
  12. updateText: function (e) {
  13. var arr = this.data.questions
  14. arr[e.target.dataset.index].answer = e.detail.value
  15. this.setData({
  16. questions: arr
  17. })
  18. },
  19. updateFilter: function (e) {
  20. var check0 = false
  21. var check1 = false
  22. for (let i = 0; i < e.detail.value.length; i++) {
  23. if (e.detail.value[i] == 0) check0 = true
  24. if (e.detail.value[i] == 1) check1 = true
  25. }
  26. this.setData({
  27. notAnswered: check0,
  28. answered: check1
  29. })
  30. },
  31. saveQuestion: function (e) {
  32. const db = wx.cloud.database()
  33. db.collection("qaData").doc(e.target.dataset.id).update({
  34. data: {
  35. answer: e.target.dataset.answer,
  36. answerTime: new Date()
  37. },
  38. success: function () {
  39. wx.showToast({
  40. title: "保存成功",
  41. })
  42. }
  43. })
  44. },
  45. removeQuestion: function (e) {
  46. wx.showModal({
  47. content: "确认删除?",
  48. success: function (res) {
  49. if (res.confirm) {
  50. const db = wx.cloud.database()
  51. db.collection("qaData").doc(e.target.dataset.id).remove({
  52. success: function () {
  53. this.onLoad({
  54. id: this.data.publisherId
  55. })
  56. wx.showToast({
  57. title: "删除成功",
  58. })
  59. }.bind(this)
  60. })
  61. }
  62. }.bind(this)
  63. })
  64. },
  65. /**
  66. * 生命周期函数--监听页面加载
  67. */
  68. onLoad: function (options) {
  69. this.setData({
  70. publisherId: options.id
  71. })
  72. const db = wx.cloud.database()
  73. db.collection("qaData").where({
  74. publisherId: this.data.publisherId,
  75. }).orderBy("questionTime", "desc").get({
  76. success: async function (res) {
  77. let arr = []
  78. for (let i = 0; i < res.data.length; i++) {
  79. arr.push(db.collection("mainData").doc(res.data[i].activityId).get())
  80. }
  81. arr = await Promise.all(arr)
  82. for (let i = 0; i < res.data.length; i++) {
  83. res.data[i].title = arr[i].data.title
  84. }
  85. this.setData({
  86. questions: res.data
  87. })
  88. }.bind(this)
  89. })
  90. },
  91. /**
  92. * 生命周期函数--监听页面初次渲染完成
  93. */
  94. onReady: function () {
  95. },
  96. /**
  97. * 生命周期函数--监听页面显示
  98. */
  99. onShow: function () {
  100. },
  101. /**
  102. * 生命周期函数--监听页面隐藏
  103. */
  104. onHide: function () {
  105. },
  106. /**
  107. * 生命周期函数--监听页面卸载
  108. */
  109. onUnload: function () {
  110. },
  111. /**
  112. * 页面相关事件处理函数--监听用户下拉动作
  113. */
  114. onPullDownRefresh: function () {
  115. },
  116. /**
  117. * 页面上拉触底事件的处理函数
  118. */
  119. onReachBottom: function () {
  120. },
  121. /**
  122. * 用户点击右上角分享
  123. */
  124. onShareAppMessage: function () {
  125. }
  126. })