project.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. const app = getApp()
  2. import WxValidate from '../../utils/wxValidate'
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. frameStyle: { useTop: true, name: '比赛项目管理', leftArrow: true, useBar: false },
  9. searchInfo: {},
  10. list: []
  11. },
  12. // 跳转菜单
  13. back(e) {
  14. wx.navigateBack({ delta: 1 })
  15. },
  16. search: function (e) {
  17. const that = this;
  18. that.setData({ 'searchInfo.name': e.detail.value });
  19. that.watchLogin()
  20. },
  21. //添加
  22. toAdd: function () {
  23. wx.navigateTo({ url: `/pages/dictionary/projectadd` })
  24. },
  25. // 修改
  26. toEdit: function (e) {
  27. const that = this;
  28. let { id } = e.currentTarget.dataset;
  29. wx.navigateTo({ url: `/pages/dictionary/projectadd?id=${id}` })
  30. },
  31. // 删除
  32. toDel: async function (e) {
  33. const that = this;
  34. const { id } = e.currentTarget.dataset;
  35. wx.showModal({
  36. title: '提示',
  37. content: '是否确认删除该条数据?',
  38. async success(res) {
  39. if (res.confirm) {
  40. const arr = await app.$delete(`/newCourt/api/matchProject/${id}`);
  41. if (arr.errcode == '0') {
  42. wx.showToast({ title: `删除信息成功`, icon: 'success', duration: 2000 })
  43. that.watchLogin()
  44. } else {
  45. wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 })
  46. }
  47. }
  48. }
  49. })
  50. },
  51. /**
  52. * 生命周期函数--监听页面加载
  53. */
  54. onLoad: function (options) {
  55. const that = this;
  56. // 监听用户是否登录
  57. that.watchLogin();
  58. },
  59. // 监听用户是否登录
  60. watchLogin: async function () {
  61. const that = this;
  62. let searchInfo = that.data.searchInfo;
  63. wx.getStorage({
  64. key: 'user',
  65. success: async res => {
  66. let info = { skip: 0, limit: 1000 };
  67. if (searchInfo && searchInfo.name) info.name = searchInfo.name;
  68. const arr = await app.$get(`/newCourt/api/matchProject/`, { ...info });
  69. if (arr.errcode == '0') {
  70. that.setData({ list: arr.data });
  71. }
  72. },
  73. fail: res => {
  74. wx.redirectTo({ url: '/pages/index/index', })
  75. }
  76. })
  77. },
  78. /**
  79. * 生命周期函数--监听页面初次渲染完成
  80. */
  81. onReady: function () {
  82. },
  83. /**
  84. * 生命周期函数--监听页面显示
  85. */
  86. onShow: function () {
  87. this.watchLogin();
  88. },
  89. /**
  90. * 生命周期函数--监听页面隐藏
  91. */
  92. onHide: function () {
  93. },
  94. /**
  95. * 生命周期函数--监听页面卸载
  96. */
  97. onUnload: function () {
  98. },
  99. /**
  100. * 页面相关事件处理函数--监听用户下拉动作
  101. */
  102. onPullDownRefresh: function () {
  103. },
  104. /**
  105. * 页面上拉触底事件的处理函数
  106. */
  107. onReachBottom: function () {
  108. },
  109. /**
  110. * 用户点击右上角分享
  111. */
  112. onShareAppMessage: function () {
  113. }
  114. })