schedule.js 7.0 KB

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