publisherQuestion.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. Page({
  2. /**
  3. * 页面的初始数据
  4. */
  5. data: {
  6. publisherId: '',
  7. questions: [],
  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. })
  78. wx.showNavigationBarLoading()
  79. wx.cloud.callFunction({
  80. name: 'listQuestions',
  81. data: {
  82. pub_id: this.data.publisherId,
  83. page_token: 0,
  84. page_size: 20
  85. }
  86. }).then(res => {
  87. wx.hideNavigationBarLoading()
  88. if (res.result.status !== 'OK') {
  89. wx.showToast({
  90. title: res.result.errMsg,
  91. icon: 'none'
  92. })
  93. return
  94. }
  95. this.setData({
  96. questions: res.result.list
  97. })
  98. })
  99. // this.setData({
  100. // publisherId: options.id,
  101. // questions: [{
  102. // title: "我是标题",
  103. // question: "我是问题?",
  104. // answer: "我是回答"
  105. // }]
  106. // })
  107. // const db = wx.cloud.database()
  108. // db.collection("qaData").where({
  109. // publisherId: this.data.publisherId,
  110. // }).orderBy("questionTime", "desc").get({
  111. // success: async function (res) {
  112. // let arr = []
  113. // for (let i = 0; i < res.data.length; i++) {
  114. // arr.push(db.collection("mainData").doc(res.data[i].activityId).get())
  115. // }
  116. // arr = await Promise.all(arr)
  117. // for (let i = 0; i < res.data.length; i++) {
  118. // res.data[i].title = arr[i].data.title
  119. // }
  120. // this.setData({
  121. // questions: res.data
  122. // })
  123. // }.bind(this)
  124. // })
  125. },
  126. /**
  127. * 生命周期函数--监听页面初次渲染完成
  128. */
  129. onReady: function () {
  130. },
  131. /**
  132. * 生命周期函数--监听页面显示
  133. */
  134. onShow: function () {
  135. },
  136. /**
  137. * 生命周期函数--监听页面隐藏
  138. */
  139. onHide: function () {
  140. },
  141. /**
  142. * 生命周期函数--监听页面卸载
  143. */
  144. onUnload: function () {
  145. },
  146. /**
  147. * 页面相关事件处理函数--监听用户下拉动作
  148. */
  149. onPullDownRefresh: function () {
  150. },
  151. /**
  152. * 页面上拉触底事件的处理函数
  153. */
  154. onReachBottom: function () {
  155. },
  156. /**
  157. * 用户点击右上角分享
  158. */
  159. onShareAppMessage: function () {
  160. }
  161. })