publisherQuestion.js 2.9 KB

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