publisherQuestion.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. confirmColor: "#009195",
  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. questions: [{
  72. title: "我是标题",
  73. question: "我是问题?",
  74. answer: "我是回答"
  75. }]
  76. })
  77. // const db = wx.cloud.database()
  78. // db.collection("qaData").where({
  79. // publisherId: this.data.publisherId,
  80. // }).orderBy("questionTime", "desc").get({
  81. // success: async function (res) {
  82. // let arr = []
  83. // for (let i = 0; i < res.data.length; i++) {
  84. // arr.push(db.collection("mainData").doc(res.data[i].activityId).get())
  85. // }
  86. // arr = await Promise.all(arr)
  87. // for (let i = 0; i < res.data.length; i++) {
  88. // res.data[i].title = arr[i].data.title
  89. // }
  90. // this.setData({
  91. // questions: res.data
  92. // })
  93. // }.bind(this)
  94. // })
  95. },
  96. /**
  97. * 生命周期函数--监听页面初次渲染完成
  98. */
  99. onReady: function () {
  100. },
  101. /**
  102. * 生命周期函数--监听页面显示
  103. */
  104. onShow: function () {
  105. },
  106. /**
  107. * 生命周期函数--监听页面隐藏
  108. */
  109. onHide: function () {
  110. },
  111. /**
  112. * 生命周期函数--监听页面卸载
  113. */
  114. onUnload: function () {
  115. },
  116. /**
  117. * 页面相关事件处理函数--监听用户下拉动作
  118. */
  119. onPullDownRefresh: function () {
  120. },
  121. /**
  122. * 页面上拉触底事件的处理函数
  123. */
  124. onReachBottom: function () {
  125. },
  126. /**
  127. * 用户点击右上角分享
  128. */
  129. onShareAppMessage: function () {
  130. }
  131. })