index.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. // pages/admin/index.js
  2. import {
  3. ajax
  4. } from "../../utils/util";
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. list: []
  11. },
  12. page: 1,
  13. size: 2,
  14. total: 0,
  15. T: undefined,
  16. conclusion(e) {
  17. if (this.T) clearTimeout(this.T);
  18. setTimeout(() => {
  19. if (this.T) clearTimeout(this.T);
  20. if (!e.currentTarget.dataset.conclusion) {
  21. wx.showModal({
  22. title: '请输入评语',
  23. editable: true,
  24. complete: (res) => {
  25. if (res.confirm) {
  26. this.uploadConclusion(e.currentTarget.dataset.id, e.currentTarget.dataset.conclusion, res.content, e.currentTarget.dataset.index)
  27. }
  28. }
  29. })
  30. } else {
  31. this.uploadConclusion(e.currentTarget.dataset.id, e.currentTarget.dataset.conclusion, "", e.currentTarget.dataset.index);
  32. }
  33. }, 200);
  34. },
  35. uploadConclusion(articleId, ok, message, index) {
  36. ajax({
  37. urlType: "apiurl",
  38. api: "/article/audit",
  39. method: "post",
  40. data: {
  41. articleId,
  42. ok,
  43. message
  44. }
  45. }).then(res => {
  46. if (res.code !== 0) return wx.showToast({
  47. title: res.message || '审核失败',
  48. icon: "none"
  49. })
  50. const {
  51. list
  52. } = this.data;
  53. if (ok) {
  54. list.splice(index, 1);
  55. this.setData({
  56. list
  57. })
  58. } else {
  59. list[index].message = message;
  60. }
  61. if (index >= list.length - 2) this.getData();
  62. wx.showToast({
  63. title: '审核成功',
  64. icon: "success"
  65. })
  66. })
  67. },
  68. getData() {
  69. ajax({
  70. urlType: "apiurl",
  71. api: "/article/list-audit",
  72. method: "post",
  73. data: {
  74. page: this.page,
  75. size: this.size
  76. }
  77. }).then(res => {
  78. if (res.code !== 0) return wx.showToast({
  79. title: '请求失败',
  80. icon: "none"
  81. })
  82. const data = res.data || {};
  83. data.data.length && (this.page += 1);
  84. this.total = data.total;
  85. this.setData({
  86. list: [...this.data.list, ...data.data]
  87. })
  88. })
  89. },
  90. change(e) {
  91. const T = setTimeout(() => {
  92. clearTimeout(T);
  93. if (e.detail.current >= this.data.list.length - 1) this.getData();
  94. }, 500);
  95. },
  96. /**
  97. * 生命周期函数--监听页面加载
  98. */
  99. onLoad(options) {
  100. this.getData()
  101. },
  102. /**
  103. * 生命周期函数--监听页面初次渲染完成
  104. */
  105. onReady() {
  106. },
  107. /**
  108. * 生命周期函数--监听页面显示
  109. */
  110. onShow() {
  111. },
  112. /**
  113. * 生命周期函数--监听页面隐藏
  114. */
  115. onHide() {
  116. },
  117. /**
  118. * 生命周期函数--监听页面卸载
  119. */
  120. onUnload() {
  121. },
  122. /**
  123. * 页面相关事件处理函数--监听用户下拉动作
  124. */
  125. onPullDownRefresh() {
  126. },
  127. /**
  128. * 页面上拉触底事件的处理函数
  129. */
  130. onReachBottom() {
  131. },
  132. /**
  133. * 用户点击右上角分享
  134. */
  135. onShareAppMessage() {
  136. return {
  137. title: __wxConfig.accountInfo.nickname,
  138. path: "/pages/index/index"
  139. }
  140. }
  141. })