myQuestion.js 3.3 KB

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