publisherQuestion.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. Page({
  2. /**
  3. * 页面的初始数据
  4. */
  5. data: {
  6. questions: [],
  7. publisherId: "",
  8. notAnswered: true,
  9. answered: true,
  10. top: false,
  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. top: function () {
  32. this.setData({
  33. top: !this.data.top
  34. })
  35. },
  36. saveQuestion: function (e) {
  37. const db = wx.cloud.database()
  38. db.collection("qaData").doc(e.target.dataset.id).update({
  39. data: {
  40. answer: e.target.dataset.answer,
  41. answerTime: new Date()
  42. },
  43. success: function () {
  44. wx.showToast({
  45. title: "保存成功",
  46. })
  47. }
  48. })
  49. },
  50. removeQuestion: function (e) {
  51. wx.showModal({
  52. content: "确认删除?",
  53. confirmColor: "#009195",
  54. success: function (res) {
  55. if (res.confirm) {
  56. const db = wx.cloud.database()
  57. db.collection("qaData").doc(e.target.dataset.id).remove({
  58. success: function () {
  59. this.onLoad({
  60. id: this.data.publisherId
  61. })
  62. wx.showToast({
  63. title: "删除成功",
  64. })
  65. }.bind(this)
  66. })
  67. }
  68. }.bind(this)
  69. })
  70. },
  71. /**
  72. * 生命周期函数--监听页面加载
  73. */
  74. onLoad: function (options) {
  75. this.setData({
  76. publisherId: options.id,
  77. questions: [{
  78. title: "我是标题",
  79. question: "我是问题?",
  80. answer: "我是回答"
  81. }]
  82. })
  83. // const db = wx.cloud.database()
  84. // db.collection("qaData").where({
  85. // publisherId: this.data.publisherId,
  86. // }).orderBy("questionTime", "desc").get({
  87. // success: async function (res) {
  88. // let arr = []
  89. // for (let i = 0; i < res.data.length; i++) {
  90. // arr.push(db.collection("mainData").doc(res.data[i].activityId).get())
  91. // }
  92. // arr = await Promise.all(arr)
  93. // for (let i = 0; i < res.data.length; i++) {
  94. // res.data[i].title = arr[i].data.title
  95. // }
  96. // this.setData({
  97. // questions: res.data
  98. // })
  99. // }.bind(this)
  100. // })
  101. },
  102. /**
  103. * 生命周期函数--监听页面初次渲染完成
  104. */
  105. onReady: function () {
  106. },
  107. /**
  108. * 生命周期函数--监听页面显示
  109. */
  110. onShow: function () {
  111. },
  112. /**
  113. * 生命周期函数--监听页面隐藏
  114. */
  115. onHide: function () {
  116. },
  117. /**
  118. * 生命周期函数--监听页面卸载
  119. */
  120. onUnload: function () {
  121. },
  122. /**
  123. * 页面相关事件处理函数--监听用户下拉动作
  124. */
  125. onPullDownRefresh: function () {
  126. },
  127. /**
  128. * 页面上拉触底事件的处理函数
  129. */
  130. onReachBottom: function () {
  131. },
  132. /**
  133. * 用户点击右上角分享
  134. */
  135. onShareAppMessage: function () {
  136. }
  137. })