myQuestion.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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: this.data.questions[e.currentTarget.dataset.index]._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. wx.showToast({
  33. title: "删除成功",
  34. icon: 'none'
  35. })
  36. this.data.questions.splice(e.currentTarget.dataset.index, 1)
  37. this.setData({
  38. questions: this.data.questions
  39. })
  40. })
  41. }
  42. })
  43. },
  44. /**
  45. * 生命周期函数--监听页面加载
  46. */
  47. onLoad: function (options) {
  48. wx.showNavigationBarLoading()
  49. wx.cloud.callFunction({
  50. name: 'listQuestions',
  51. data: {
  52. page_token: 0,
  53. page_size: 20
  54. }
  55. }).then(res => {
  56. wx.hideNavigationBarLoading()
  57. if (res.result.status !== 'OK') {
  58. wx.showToast({
  59. title: res.result.errMsg,
  60. icon: 'none'
  61. })
  62. return
  63. }
  64. this.setData({
  65. questions: res.result.list
  66. })
  67. })
  68. },
  69. /**
  70. * 生命周期函数--监听页面初次渲染完成
  71. */
  72. onReady: function () {
  73. },
  74. /**
  75. * 生命周期函数--监听页面显示
  76. */
  77. onShow: function () {
  78. },
  79. /**
  80. * 生命周期函数--监听页面隐藏
  81. */
  82. onHide: function () {
  83. },
  84. /**
  85. * 生命周期函数--监听页面卸载
  86. */
  87. onUnload: function () {
  88. },
  89. /**
  90. * 页面相关事件处理函数--监听用户下拉动作
  91. */
  92. onPullDownRefresh: function () {
  93. },
  94. /**
  95. * 页面上拉触底事件的处理函数
  96. */
  97. onReachBottom: function () {
  98. },
  99. /**
  100. * 用户点击右上角分享
  101. */
  102. onShareAppMessage: function () {
  103. }
  104. })