myQuestion.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. // miniprogram/pages/publisherQuestion/publisherQuestion.js
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. questions: [],
  8. },
  9. removeQuestion: function (e) {
  10. wx.showModal({
  11. content: "确认删除提问?",
  12. confirmColor: "#009195"
  13. }).then(res => {
  14. if (res.confirm) {
  15. wx.showLoading({
  16. title: '删除中'
  17. })
  18. wx.cloud.callFunction({
  19. name: 'deleteQuestion',
  20. data: {
  21. que_id: e.currentTarget.dataset.id
  22. }
  23. }).then(res => {
  24. wx.hideLoading()
  25. if (res.result.status !== 'OK') {
  26. wx.showToast({
  27. title: res.result.errMsg,
  28. icon: 'none'
  29. })
  30. return
  31. }
  32. for (let i = 0; i < this.data.questions.length; i++) {
  33. if (this.data.questions[i]._id === e.currentTarget.dataset.id) {
  34. this.data.questions.splice(i, 1)
  35. break
  36. }
  37. }
  38. this.setData({
  39. questions: this.data.questions
  40. })
  41. wx.showToast({
  42. title: "删除成功",
  43. icon: 'none'
  44. })
  45. })
  46. }
  47. })
  48. },
  49. /**
  50. * 生命周期函数--监听页面加载
  51. */
  52. onLoad: function (options) {
  53. wx.showNavigationBarLoading()
  54. wx.cloud.callFunction({
  55. name: 'listQuestions',
  56. data: {
  57. page_token: 0,
  58. page_size: 20
  59. }
  60. }).then(res => {
  61. wx.hideNavigationBarLoading()
  62. if (res.result.status !== 'OK') {
  63. wx.showToast({
  64. title: res.result.errMsg,
  65. icon: 'none'
  66. })
  67. return
  68. }
  69. this.setData({
  70. questions: res.result.list
  71. })
  72. })
  73. },
  74. /**
  75. * 生命周期函数--监听页面初次渲染完成
  76. */
  77. onReady: function () {
  78. },
  79. /**
  80. * 生命周期函数--监听页面显示
  81. */
  82. onShow: function () {
  83. },
  84. /**
  85. * 生命周期函数--监听页面隐藏
  86. */
  87. onHide: function () {
  88. },
  89. /**
  90. * 生命周期函数--监听页面卸载
  91. */
  92. onUnload: function () {
  93. },
  94. /**
  95. * 页面相关事件处理函数--监听用户下拉动作
  96. */
  97. onPullDownRefresh: function () {
  98. },
  99. /**
  100. * 页面上拉触底事件的处理函数
  101. */
  102. onReachBottom: function () {
  103. },
  104. /**
  105. * 用户点击右上角分享
  106. */
  107. onShareAppMessage: function () {
  108. }
  109. })