publisherQuestion.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. }).then(res => {
  55. if (res.confirm) {
  56. wx.showLoading({
  57. title: '删除中'
  58. })
  59. wx.cloud.callFunction({
  60. name: 'deleteQuestion',
  61. data: {
  62. que_id: e.currentTarget.dataset.id
  63. }
  64. }).then(res => {
  65. wx.hideLoading()
  66. if (res.result.status !== 'OK') {
  67. wx.showToast({
  68. title: res.result.errMsg,
  69. icon: 'none'
  70. })
  71. return
  72. }
  73. for (let i = 0; i < this.data.questions.length; i++) {
  74. if (this.data.questions[i]._id === e.currentTarget.dataset.id) {
  75. this.data.questions.splice(i, 1)
  76. break
  77. }
  78. }
  79. this.setData({
  80. questions: this.data.questions
  81. })
  82. wx.showToast({
  83. title: "删除成功",
  84. icon: 'none'
  85. })
  86. })
  87. }
  88. })
  89. },
  90. /**
  91. * 生命周期函数--监听页面加载
  92. */
  93. onLoad: function (options) {
  94. this.setData({
  95. publisherId: options.id
  96. })
  97. wx.showNavigationBarLoading()
  98. wx.cloud.callFunction({
  99. name: 'listQuestions',
  100. data: {
  101. pub_id: this.data.publisherId,
  102. page_token: 0,
  103. page_size: 20
  104. }
  105. }).then(res => {
  106. wx.hideNavigationBarLoading()
  107. if (res.result.status !== 'OK') {
  108. wx.showToast({
  109. title: res.result.errMsg,
  110. icon: 'none'
  111. })
  112. return
  113. }
  114. this.setData({
  115. questions: res.result.list
  116. })
  117. })
  118. },
  119. /**
  120. * 生命周期函数--监听页面初次渲染完成
  121. */
  122. onReady: function () {
  123. },
  124. /**
  125. * 生命周期函数--监听页面显示
  126. */
  127. onShow: function () {
  128. },
  129. /**
  130. * 生命周期函数--监听页面隐藏
  131. */
  132. onHide: function () {
  133. },
  134. /**
  135. * 生命周期函数--监听页面卸载
  136. */
  137. onUnload: function () {
  138. },
  139. /**
  140. * 页面相关事件处理函数--监听用户下拉动作
  141. */
  142. onPullDownRefresh: function () {
  143. },
  144. /**
  145. * 页面上拉触底事件的处理函数
  146. */
  147. onReachBottom: function () {
  148. },
  149. /**
  150. * 用户点击右上角分享
  151. */
  152. onShareAppMessage: function () {
  153. }
  154. })