detail.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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. show: false,
  27. form: {},
  28. },
  29. //验证是否输入
  30. initValidate() {
  31. const rules = { blue_branch: { required: true }, red_branch: { required: true, }, blue_integral: { required: true }, red_integral: { required: true, } }
  32. // 验证字段的提示信息,若不传则调用默认的信息
  33. const messages = { blue_branch: { required: '请输入蓝方比分', }, red_branch: { required: '请输入红方比分', }, blue_integral: { required: '请输入蓝方积分', }, red_integral: { required: '请输入红方积分', } };
  34. this.WxValidate = new WxValidate(rules, messages)
  35. },
  36. back: function () {
  37. wx.navigateBack({ delta: 0 })
  38. },
  39. //上传图片
  40. imgUpload: async function (e) {
  41. const that = this;
  42. let type = that.data.type;
  43. let redTeam = that.data.redTeam;
  44. let blueTeam = that.data.blueTeam;
  45. let user = that.data.userdata;
  46. let info = that.data.info;
  47. if (type == '0') {
  48. wx.showToast({ title: '不可上传', duration: 2000, icon: 'error', })
  49. } else if (type == '1') {
  50. if (redTeam || blueTeam) {
  51. if (redTeam && redTeam.create_id == user._id || blueTeam && blueTeam.create_id == user._id) {
  52. let data = that.data.match_file;
  53. let id = that.data.id;
  54. data.push(e.detail);
  55. const arr = await app.$post(`/courtAdmin/api/schedule/${id}`, { match_file: data });
  56. if (arr.errcode === 0) {
  57. wx.showToast({ title: `上传图片成功`, icon: 'success', duration: 2000 })
  58. that.watchLogin();
  59. } else {
  60. wx.showToast({ title: arr.errmsg, icon: 'success', duration: 2000 })
  61. }
  62. } else {
  63. wx.showToast({ title: '不可上传', duration: 2000, icon: 'error', })
  64. }
  65. }
  66. } else if (type == '2') {
  67. let redM = info.red_members.find((i) => i.id == user._id);
  68. let blueM = info.blue_members.find((i) => i.id == user._id);
  69. if (redM || blueM) {
  70. let data = that.data.match_file;
  71. let id = that.data.id;
  72. data.push(e.detail);
  73. const arr = await app.$post(`/courtAdmin/api/schedule/${id}`, { match_file: data });
  74. if (arr.errcode === 0) {
  75. wx.showToast({ title: `上传图片成功`, icon: 'success', duration: 2000 })
  76. that.watchLogin();
  77. } else {
  78. wx.showToast({ title: arr.errmsg, icon: 'success', duration: 2000 })
  79. }
  80. } else {
  81. wx.showToast({ title: '不可上传', duration: 2000, icon: 'error', })
  82. }
  83. }
  84. },
  85. //删除图片
  86. imgDel: async function (e) {
  87. const that = this;
  88. let type = that.data.type;
  89. let redTeam = that.data.redTeam;
  90. let blueTeam = that.data.blueTeam;
  91. let user = that.data.userdata;
  92. let info = that.data.info;
  93. if (type == '0') {
  94. wx.showToast({ title: '不可删除', duration: 2000, icon: 'error', })
  95. } else if (type == '1') {
  96. if (redTeam || blueTeam) {
  97. if (redTeam && redTeam.create_id == user._id || blueTeam && blueTeam.create_id == user._id) {
  98. let id = that.data.id;
  99. let data = that.data.match_file;
  100. let arr = data.filter((i, index) => index != e.detail.index)
  101. const res = await app.$post(`/courtAdmin/api/schedule/${id}`, { match_file: arr });
  102. if (res.errcode === 0) {
  103. wx.showToast({ title: `删除图片成功`, icon: 'success', duration: 2000 })
  104. that.watchLogin();
  105. } else {
  106. wx.showToast({ title: arr.errmsg, icon: 'success', duration: 2000 })
  107. }
  108. } else {
  109. wx.showToast({ title: '不可上传', duration: 2000, icon: 'error', })
  110. }
  111. }
  112. } else if (type == '2') {
  113. wx.showToast({ title: '不可删除', duration: 2000, icon: 'error', })
  114. }
  115. },
  116. // 上传比分
  117. clickme: async function () {
  118. const that = this;
  119. let type = that.data.type;
  120. let redTeam = that.data.redTeam;
  121. let blueTeam = that.data.blueTeam;
  122. let user = that.data.userdata;
  123. if (type == '0' || type == '2') {
  124. wx.showToast({ title: `不可上传`, icon: 'error', duration: 2000 })
  125. } else {
  126. if (redTeam || blueTeam) {
  127. if (redTeam && redTeam.create_id == user._id || blueTeam && blueTeam.create_id == user._id) {
  128. that.setData({ form: that.data.info })
  129. that.setData({ show: true })
  130. } else {
  131. wx.showToast({ title: `不可上传`, icon: 'error', duration: 2000 })
  132. }
  133. }
  134. }
  135. },
  136. // 提交比分
  137. formSubmit: async function (e) {
  138. const that = this;
  139. let id = that.data.id;
  140. let params = e.detail.value;
  141. if (!this.WxValidate.checkForm(params)) {
  142. const error = this.WxValidate.errorList[0];
  143. wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
  144. return false
  145. } else {
  146. const res = await app.$post(`/courtAdmin/api/schedule/${id}`, params);
  147. if (res.errcode == 0) {
  148. wx.showToast({ title: '保存成功', duration: 2000, icon: 'success' })
  149. that.formReset();
  150. that.watchLogin();
  151. } else {
  152. wx.showToast({ title: res.errmsg, icon: 'error', duration: 2000 })
  153. }
  154. }
  155. },
  156. // 取消提交
  157. formReset: function () {
  158. const that = this;
  159. that.setData({ show: false })
  160. },
  161. /**
  162. * 生命周期函数--监听页面加载
  163. */
  164. onLoad: function (options) {
  165. const that = this;
  166. that.setData({ id: options.id })
  167. //验证规则函数
  168. this.initValidate();
  169. // 计算高度
  170. this.searchHeight();
  171. // 监听用户是否登录
  172. this.watchLogin();
  173. },
  174. // 监听用户是否登录
  175. watchLogin: async function () {
  176. const that = this;
  177. let id = that.data.id;
  178. wx.getStorage({
  179. key: 'token',
  180. success: async res => {
  181. // 用户类别,用户信息
  182. that.setData({ type: res.data.type, userdata: res.data })
  183. const arr = await app.$get(`/courtAdmin/api/schedule/${id}`);
  184. if (arr.errcode === 0) {
  185. // 比赛信息,红方id,蓝方id
  186. that.setData({ info: arr.data })
  187. // 现场图片
  188. that.setData({ match_file: arr.data.match_file })
  189. // 查询红方,蓝方信息
  190. const p1 = await app.$get(`/courtAdmin/api/team/${arr.data.red_id}`);
  191. const p2 = await app.$get(`/courtAdmin/api/team/${arr.data.blue_id}`);
  192. if (p1.errcode === 0 && p2.errcode === 0) {
  193. that.setData({ redTeam: p1.data })
  194. that.setData({ blueTeam: p2.data })
  195. }
  196. }
  197. },
  198. fail: res => {
  199. return wx.redirectTo({ url: '/pages/login/index', })
  200. }
  201. })
  202. },
  203. // 计算高度
  204. searchHeight: function () {
  205. let frameStyle = this.data.frameStyle;
  206. let client = app.globalData.client;
  207. // 减去状态栏
  208. let infoHeight = client.windowHeight - (client.statusBarHeight + client.getMenu.height + (client.getMenu.top - client.statusBarHeight) * 2);
  209. // 是否减去底部菜单
  210. if (frameStyle.useBar) infoHeight = infoHeight - 50;
  211. if (infoHeight) this.setData({ infoHeight: infoHeight })
  212. },
  213. /**
  214. * 生命周期函数--监听页面初次渲染完成
  215. */
  216. onReady: function () {
  217. },
  218. /**
  219. * 生命周期函数--监听页面显示
  220. */
  221. onShow: function () {
  222. },
  223. /**
  224. * 生命周期函数--监听页面隐藏
  225. */
  226. onHide: function () {
  227. },
  228. /**
  229. * 生命周期函数--监听页面卸载
  230. */
  231. onUnload: function () {
  232. },
  233. /**
  234. * 页面相关事件处理函数--监听用户下拉动作
  235. */
  236. onPullDownRefresh: function () {
  237. },
  238. /**
  239. * 页面上拉触底事件的处理函数
  240. */
  241. onReachBottom: function () {
  242. },
  243. /**
  244. * 用户点击右上角分享
  245. */
  246. onShareAppMessage: function () {
  247. }
  248. })