schedule.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. // pages/login/login.js
  2. import WxValidate from '../../utils/wxValidate'
  3. const app = getApp()
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. frameStyle: { useTop: true, name: '比赛信息', leftArrow: true, useBar: false },
  10. // 主体高度
  11. infoHeight: '',
  12. // 用户信息
  13. user: {},
  14. // 数据id
  15. id: '',
  16. // 赛程信息
  17. form: {},
  18. // 红方团队
  19. redTeam: {},
  20. // 蓝方团队
  21. blueTeam: {},
  22. // 现场图片
  23. match_file: [],
  24. },
  25. back: function () {
  26. wx.navigateBack({ delta: 1 })
  27. },
  28. //上传图片
  29. imgUpload: async function (e) {
  30. const that = this;
  31. const user = that.data.user;
  32. const red = that.data.redTeam;
  33. const blue = that.data.blueTeam;
  34. const data = that.data.form;
  35. let list = that.data.match_file;
  36. if (user.type == '0') {
  37. wx.showToast({ title: '不可上传', duration: 2000, icon: 'error', })
  38. } else if (user.type == '1') {
  39. // 判断当前红方团队创建人是否为当前用户
  40. if (red.create_id == user._id) { list.push(e.detail); that.commonUpload(list); }
  41. else {
  42. // 判断当前蓝方团队创建人是否为当前用户
  43. if (blue.create_id == user._id) { list.push(e.detail); that.commonUpload(list); }
  44. else wx.showToast({ title: '不可上传', duration: 2000, icon: 'error', })
  45. }
  46. } else if (user.type == '2') {
  47. let memebers = [...data.red_members, ...data.blue_members];
  48. let memebersInfo = memebers.find((i) => i.user_id == user._id);
  49. if (memebersInfo) { list.push(e.detail); that.commonUpload(list); }
  50. else wx.showToast({ title: '不可上传', duration: 2000, icon: 'error', })
  51. }
  52. },
  53. // 公共修改图片方法
  54. commonUpload: async function (data) {
  55. const that = this;
  56. const arr = await app.$post(`/courtAdmin/api/schedule/${that.data.id}`, { match_file: data });
  57. if (arr.errcode == '0') {
  58. wx.showToast({ title: `上传图片成功`, duration: 2000, icon: 'success', })
  59. this.watchLogin();
  60. } else {
  61. wx.showToast({ title: `${arr.errmsg}`, duration: 2000, icon: 'error', })
  62. }
  63. },
  64. //删除图片
  65. imgDel: async function (e) {
  66. const that = this;
  67. const user = that.data.user;
  68. const red = that.data.redTeam;
  69. const blue = that.data.blueTeam;
  70. const data = that.data.form;
  71. let list = that.data.match_file;
  72. if (user.type == '0') {
  73. wx.showToast({ title: '不可删除', duration: 2000, icon: 'error', })
  74. } else if ((user.type == '1')) {
  75. // 判断当前红方团队创建人是否为当前用户
  76. if (red.create_id == user._id) { let match_file = list.filter((i, index) => index != e.detail.index); that.commonUpload(match_file); }
  77. else {
  78. // 判断当前蓝方团队创建人是否为当前用户
  79. if (blue.create_id == user._id) { let match_file = list.filter((i, index) => index != e.detail.index); that.commonUpload(match_file); }
  80. else wx.showToast({ title: '不可删除', duration: 2000, icon: 'error', })
  81. }
  82. } else if (user.type == '2') {
  83. let memebers = [...data.red_members, ...data.blue_members];
  84. let memebersInfo = memebers.find((i) => i.user_id == user._id);
  85. if (memebersInfo) { let match_file = list.filter((i, index) => index != e.detail.index); that.commonUpload(match_file); }
  86. else wx.showToast({ title: '不可删除', duration: 2000, icon: 'error', })
  87. }
  88. },
  89. /**
  90. * 生命周期函数--监听页面加载
  91. */
  92. onLoad: function (options) {
  93. const that = this;
  94. that.setData({ id: options.id || '62a04673b3fcf97310b3e9b9' })
  95. // 计算高度
  96. this.searchHeight()
  97. // 监听用户是否登录
  98. this.watchLogin();
  99. },
  100. // 监听用户是否登录
  101. watchLogin: async function () {
  102. const that = this;
  103. wx.getStorage({
  104. key: 'token',
  105. success: async res => {
  106. let arr;
  107. // 用户信息
  108. that.setData({ user: res.data });
  109. // 赛程信息
  110. arr = await app.$get(`/courtAdmin/api/schedule/${that.data.id}`);
  111. let schedule = arr.data;
  112. if (arr.errcode == '0') that.setData({ form: schedule }); that.setData({ match_file: schedule.match_file || [] });
  113. // 红方
  114. if (schedule && schedule.red_id) {
  115. arr = await app.$get(`/courtAdmin/api/team/${schedule.red_id}`);
  116. if (arr.errcode == '0') that.setData({ redTeam: arr.data });
  117. }
  118. // 蓝方
  119. if (schedule && schedule.blue_id) {
  120. arr = await app.$get(`/courtAdmin/api/team/${schedule.blue_id}`);
  121. if (arr.errcode == '0') that.setData({ blueTeam: arr.data });
  122. }
  123. },
  124. fail: res => {
  125. return wx.redirectTo({ url: '/pages/login/index', })
  126. }
  127. })
  128. },
  129. // 计算高度
  130. searchHeight: function () {
  131. let frameStyle = this.data.frameStyle;
  132. let client = app.globalData.client;
  133. let infoHeight = client.windowHeight;
  134. // 是否去掉状态栏
  135. if (frameStyle.useTop) infoHeight = infoHeight - (client.statusBarHeight + client.getMenu.height + (client.getMenu.top - client.statusBarHeight) * 2);
  136. // 是否减去底部菜单
  137. if (frameStyle.useBar) infoHeight = infoHeight - 50;
  138. if (infoHeight) this.setData({ infoHeight: infoHeight })
  139. },
  140. /**
  141. * 生命周期函数--监听页面初次渲染完成
  142. */
  143. onReady: function () {
  144. },
  145. /**
  146. * 生命周期函数--监听页面显示
  147. */
  148. onShow: function () {
  149. },
  150. /**
  151. * 生命周期函数--监听页面隐藏
  152. */
  153. onHide: function () {
  154. },
  155. /**
  156. * 生命周期函数--监听页面卸载
  157. */
  158. onUnload: function () {
  159. },
  160. /**
  161. * 页面相关事件处理函数--监听用户下拉动作
  162. */
  163. onPullDownRefresh: function () {
  164. },
  165. /**
  166. * 页面上拉触底事件的处理函数
  167. */
  168. onReachBottom: function () {
  169. },
  170. /**
  171. * 用户点击右上角分享
  172. */
  173. onShareAppMessage: function () {
  174. }
  175. })