index.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. // pages/userData/index.js
  2. import {
  3. ajax
  4. } from "../../utils/util";
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. list: []
  11. },
  12. list: [],
  13. phone: wx.getStorageSync('phone') || '',
  14. change(e) {
  15. const rex = new RegExp(e.detail);
  16. const li = [];
  17. for (let i = 0; i < this.list.length; i++) {
  18. const v = this.list[i];
  19. let isShow = false;
  20. const keys = ["area", "articleDescribe", "articleGroup", "articleName", "birthday", "name", "phone", "school", "teacher", "teacherPhone"];
  21. for (let o = 0; o < keys.length; o++) {
  22. if (rex.test(v[keys[o]])) isShow = true;
  23. }
  24. if (!e.detail) isShow = true
  25. if (isShow) li.push(v);
  26. }
  27. this.setData({
  28. list: li
  29. })
  30. },
  31. modify(e) {
  32. const {
  33. list
  34. } = this.data;
  35. const item = list[e.currentTarget.dataset.index];
  36. wx.navigateTo({
  37. url: '/pages/modify/index?data=' + JSON.stringify(item)
  38. })
  39. },
  40. delet(e) {
  41. const {
  42. list
  43. } = this.data;
  44. const item = list[e.currentTarget.dataset.index];
  45. wx.showModal({
  46. title: '删除',
  47. content: '确定删除' + item.articleName + '?',
  48. complete: (res) => {
  49. if (res.confirm) {
  50. ajax({
  51. urlType: "apiurl",
  52. api: "/article/delete?articleId=" + item.id,
  53. }).then(res => {
  54. if (res.code !== 0) {
  55. wx.showToast({
  56. title: res.message || '网络波动',
  57. icon: "none"
  58. })
  59. return
  60. }
  61. list.splice(e.currentTarget.dataset.index, 1)
  62. this.setData({
  63. list
  64. })
  65. })
  66. }
  67. }
  68. })
  69. },
  70. init() {
  71. ajax({
  72. urlType: "apiurl",
  73. api: "/article/list",
  74. }).then(res => {
  75. if (res.code !== 0) return wx.showToast({
  76. title: res.message || '请求失败',
  77. icon: 'none'
  78. })
  79. const li = res.data || [];
  80. this.list = li;
  81. this.setData({
  82. list: li
  83. })
  84. })
  85. },
  86. /**
  87. * 生命周期函数--监听页面加载
  88. */
  89. onLoad(options) {
  90. this.init();
  91. },
  92. /**
  93. * 生命周期函数--监听页面初次渲染完成
  94. */
  95. onReady() {
  96. },
  97. /**
  98. * 生命周期函数--监听页面显示
  99. */
  100. onShow() {
  101. this.init();
  102. },
  103. /**
  104. * 生命周期函数--监听页面隐藏
  105. */
  106. onHide() {
  107. },
  108. /**
  109. * 生命周期函数--监听页面卸载
  110. */
  111. onUnload() {
  112. },
  113. /**
  114. * 页面相关事件处理函数--监听用户下拉动作
  115. */
  116. onPullDownRefresh() {
  117. },
  118. /**
  119. * 页面上拉触底事件的处理函数
  120. */
  121. onReachBottom() {
  122. },
  123. /**
  124. * 用户点击右上角分享
  125. */
  126. onShareAppMessage() {
  127. return {
  128. title: __wxConfig.accountInfo.nickname,
  129. path: "/pages/index/index"
  130. }
  131. }
  132. })