index.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. // pages/login/login.js
  2. import WxValidate from '../../utils/wxValidate'
  3. const app = getApp()
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. // 主体高度
  10. infoHeight: '',
  11. frameStyle: { useTop: true, name: '已上传图片', leftArrow: true, useBar: false },
  12. //赛程列表
  13. scheduleList: [],
  14. // 选中的数据
  15. selectList: [],
  16. },
  17. back: function () {
  18. wx.navigateBack({ url: '/pages/me/index' })
  19. },
  20. // 多选
  21. toSelect: function (e) {
  22. const that = this;
  23. let list = that.data.scheduleList;
  24. let arr = []
  25. for (const val of list) {
  26. for (const vaq of val.match_file) {
  27. vaq.check = true;
  28. arr.push({ id: val._id, name: vaq.name })
  29. }
  30. }
  31. that.setData({ scheduleList: list })
  32. that.setData({ selectList: arr })
  33. },
  34. // 单个选择
  35. dataChange: function (e) {
  36. const that = this;
  37. let list = that.data.selectList;
  38. let { id, name } = e.currentTarget.dataset;
  39. let is_d = list.find((i) => i.name == name);
  40. if (is_d) {
  41. let data = list.filter((i) => i.name != name);
  42. that.setData({ selectList: data })
  43. } else {
  44. list.push({ id: id, name: name })
  45. }
  46. },
  47. // 删除多选
  48. toDel: async function () {
  49. const that = this;
  50. let list = that.data.scheduleList;
  51. let p1 = that.data.selectList;
  52. wx.showModal({
  53. content: `您确定提交删除操作吗?`,
  54. title: '提示',
  55. success: async result => {
  56. if (result.confirm) {
  57. for (const p2 of p1) {
  58. for (const p3 of list) {
  59. p3.match_file = p3.match_file.filter((i) => i.name != p2.name);
  60. }
  61. }
  62. for (const val of list) {
  63. const res = await app.$post(`/courtAdmin/api/schedule/${val._id}`, val);
  64. if (res.errcode === 0) {
  65. wx.showToast({ title: `删除图片成功`, icon: 'success', duration: 2000 })
  66. that.watchLogin()
  67. } else {
  68. wx.showToast({ title: res.errmsg, icon: 'error', duration: 2000 })
  69. }
  70. }
  71. } else if (result.cancel) { }
  72. }
  73. })
  74. },
  75. // 保存
  76. toSubmit: function () { },
  77. /**
  78. * 生命周期函数--监听页面加载
  79. */
  80. onLoad: function (options) {
  81. // 计算高度
  82. this.searchHeight();
  83. // 监听用户是否登录
  84. this.watchLogin();
  85. },
  86. // 监听用户是否登录
  87. watchLogin: async function () {
  88. const that = this;
  89. wx.getStorage({
  90. key: 'token',
  91. success: async res => {
  92. const arr = await app.$get('/courtAdmin/api/schedule');
  93. if (arr.errcode === 0) that.setData({ scheduleList: arr.data })
  94. },
  95. fail: res => {
  96. wx.redirectTo({ url: '/pages/login/index', })
  97. }
  98. })
  99. },
  100. // 计算高度
  101. searchHeight: function () {
  102. let frameStyle = this.data.frameStyle;
  103. let client = app.globalData.client;
  104. let infoHeight = client.windowHeight;
  105. // 是否去掉状态栏
  106. if (frameStyle.useTop) infoHeight = infoHeight - (client.statusBarHeight + client.getMenu.height + (client.getMenu.top - client.statusBarHeight) * 2);
  107. // 是否减去底部菜单
  108. if (frameStyle.useBar) infoHeight = infoHeight - 50;
  109. if (infoHeight) this.setData({ infoHeight: infoHeight })
  110. },
  111. /**
  112. * 生命周期函数--监听页面初次渲染完成
  113. */
  114. onReady: function () {
  115. },
  116. /**
  117. * 生命周期函数--监听页面显示
  118. */
  119. onShow: function () {
  120. },
  121. /**
  122. * 生命周期函数--监听页面隐藏
  123. */
  124. onHide: function () {
  125. },
  126. /**
  127. * 生命周期函数--监听页面卸载
  128. */
  129. onUnload: function () {
  130. },
  131. /**
  132. * 页面相关事件处理函数--监听用户下拉动作
  133. */
  134. onPullDownRefresh: function () {
  135. },
  136. /**
  137. * 页面上拉触底事件的处理函数
  138. */
  139. onReachBottom: function () {
  140. },
  141. /**
  142. * 用户点击右上角分享
  143. */
  144. onShareAppMessage: function () {
  145. }
  146. })