index.js 3.0 KB

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