index.js 2.8 KB

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