orderbook.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. const app = getApp()
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. frameStyle: { useTop: true, name: '秩序册管理', leftArrow: true, useBar: false },
  8. // 选项卡
  9. tabs: {
  10. active: 'a',
  11. list: [
  12. { title: '组项信息', name: 'a' },
  13. { title: '赛程信息', name: 'b' },
  14. ],
  15. },
  16. // 组安排
  17. teamList: [],
  18. raceList: []
  19. },
  20. back(e) {
  21. wx.navigateBack({ delta: 1 })
  22. },
  23. tabsChange: function (e) {
  24. const that = this;
  25. const { name } = e.detail;
  26. that.setData({ 'tabs.active': name });
  27. },
  28. // 添加
  29. toCommon: function (e) {
  30. const that = this;
  31. const { route } = e.currentTarget.dataset;
  32. wx.navigateTo({ url: `/pages/${route}` })
  33. },
  34. // 信息维护
  35. toEdit: function (e) {
  36. const that = this;
  37. const { item } = e.currentTarget.dataset;
  38. wx.navigateTo({ url: `/pages/orderbook/teamAdd?id=${item._id}` })
  39. },
  40. // 信息维护
  41. raceEdit: function (e) {
  42. const that = this;
  43. const { item } = e.currentTarget.dataset;
  44. console.log(item);
  45. wx.navigateTo({ url: `/pages/orderbook/raceAdd?id=${item._id}` })
  46. },
  47. // 删除
  48. toDel: function (e) {
  49. const that = this;
  50. const { item } = e.currentTarget.dataset;
  51. wx.showModal({
  52. title: '提示',
  53. content: '是否确认删除该条数据?',
  54. async success(res) {
  55. if (res.confirm) {
  56. const arr = await app.$delete(`/newCourt/api/raceTeam/${item._id}`);
  57. if (arr.errcode == '0') {
  58. wx.showToast({ title: `删除信息成功`, icon: 'success', duration: 2000 })
  59. that.watchLogin()
  60. } else {
  61. wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 })
  62. }
  63. }
  64. }
  65. })
  66. },
  67. raceDel: function (e) {
  68. const that = this;
  69. const { item } = e.currentTarget.dataset;
  70. wx.showModal({
  71. title: '提示',
  72. content: '是否确认删除该条数据?',
  73. async success(res) {
  74. if (res.confirm) {
  75. const arr = await app.$delete(`/newCourt/api/race/${item._id}`);
  76. if (arr.errcode == '0') {
  77. wx.showToast({ title: `删除信息成功`, icon: 'success', duration: 2000 })
  78. that.watchLogin()
  79. } else {
  80. wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 })
  81. }
  82. }
  83. }
  84. })
  85. },
  86. /**
  87. * 生命周期函数--监听页面加载
  88. */
  89. onLoad: function (options) {
  90. const that = this;
  91. },
  92. /**
  93. * 生命周期函数--监听页面初次渲染完成
  94. */
  95. onReady: function () {
  96. },
  97. /**
  98. * 生命周期函数--监听页面显示
  99. */
  100. onShow: function () {
  101. const that = this;
  102. // 监听用户是否登录
  103. that.watchLogin();
  104. },
  105. watchLogin: function () {
  106. const that = this;
  107. wx.getStorage({
  108. key: 'user',
  109. success: async (res) => {
  110. let arr;
  111. let info = { skip: 0, limit: 1000 };
  112. arr = await app.$get(`/newCourt/api/raceTeam`, { ...info });
  113. if (arr.errcode == '0') { that.setData({ teamList: arr.data }) }
  114. else { wx.showToast({ title: `${res.errMsg}`, icon: 'fail', duration: 2000 }); }
  115. arr = await app.$get(`/newCourt/api/race`, { ...info });
  116. if (arr.errcode == '0') { that.setData({ raceList: arr.data }) }
  117. else { wx.showToast({ title: `${res.errMsg}`, icon: 'fail', duration: 2000 }); }
  118. },
  119. fail: async (res) => {
  120. wx.redirectTo({ url: '/pages/index/index' });
  121. },
  122. });
  123. },
  124. /**
  125. * 生命周期函数--监听页面隐藏
  126. */
  127. onHide: function () {
  128. },
  129. /**
  130. * 生命周期函数--监听页面卸载
  131. */
  132. onUnload: function () {
  133. },
  134. /**
  135. * 页面相关事件处理函数--监听用户下拉动作
  136. */
  137. onPullDownRefresh: function () {
  138. },
  139. /**
  140. * 页面上拉触底事件的处理函数
  141. */
  142. onReachBottom: function () {
  143. },
  144. /**
  145. * 用户点击右上角分享
  146. */
  147. onShareAppMessage: function () {
  148. }
  149. })