index.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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. match_file: [],
  18. showModal: false,
  19. //修改比分
  20. form: [],
  21. },
  22. //验证是否输入
  23. initValidate() {
  24. const rules = { blue_branch: { required: true }, red_branch: { required: true, },blue_integral: { required: true }, red_integral: { required: true, } }
  25. // 验证字段的提示信息,若不传则调用默认的信息
  26. const messages = { blue_branch: { required: '请输入蓝方比分', }, red_branch: { required: '请输入红方比分', },blue_integral: { required: '请输入蓝方积分', }, red_integral: { required: '请输入红方积分', } };
  27. this.WxValidate = new WxValidate(rules, messages)
  28. },
  29. back: function () {
  30. wx.navigateBack({ url: '/pages/home/index' })
  31. },
  32. //显示对话框
  33. clickme: function () {
  34. this.setData({showModal: true})
  35. },
  36. //关闭弹窗
  37. go: function () {
  38. this.setData({showModal: false})
  39. },
  40. //上传图片
  41. imgUpload: function (e) {
  42. const that = this;
  43. let data = that.data.match_file;
  44. let id = that.data.id;
  45. data.push(e.detail)
  46. wx.request({
  47. url: `${app.globalData.publicUrl}/courtAdmin/api/schedule/${id}`, //接口地址
  48. method: 'post',
  49. data: { match_file: data },
  50. success(res) {
  51. if (res.data.errcode == 0) {
  52. wx.showToast({
  53. title: '添加成功',
  54. duration: 2000,
  55. icon: 'success',
  56. })
  57. that.setData({ match_file: data })
  58. } else {
  59. wx.showToast({ title: res.data.errmsg, icon: 'error', duration: 2000 })
  60. }
  61. }
  62. })
  63. },
  64. //删除图片
  65. imgDel: function (e) {
  66. const that = this;
  67. let data = that.data.match_file;
  68. let id = that.data.id;
  69. let arr = data.filter((i, index) => index != e.detail.index)
  70. wx.request({
  71. url: `${app.globalData.publicUrl}/courtAdmin/api/schedule/${id}`, //接口地址
  72. method: 'post',
  73. data: { match_file: arr },
  74. success(res) {
  75. if (res.data.errcode == 0) {
  76. wx.showToast({
  77. title: '删除成功',
  78. duration: 2000,
  79. icon: 'success',
  80. })
  81. that.setData({ match_file: arr })
  82. } else {
  83. wx.showToast({ title: res.data.errmsg, icon: 'error', duration: 2000 })
  84. }
  85. }
  86. })
  87. },
  88. // 提交登录
  89. formSubmit: function (e) {
  90. const that = this;
  91. let id = that.data.id;
  92. const params = e.detail.value;
  93. params.match_file = that.data.match_file;
  94. if (!this.WxValidate.checkForm(params)) {
  95. const error = this.WxValidate.errorList[0];
  96. wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
  97. return false
  98. } else {
  99. wx.request({
  100. url: `${app.globalData.publicUrl}/courtAdmin/api/schedule/${id}`, //接口地址
  101. method: 'post',
  102. data: params,
  103. success(res) {
  104. if (res.data.errcode == 0) {
  105. wx.showToast({
  106. title: '保存成功',
  107. duration: 2000,
  108. icon: 'success',
  109. success: (res) => { that.back() }
  110. })
  111. } else {
  112. wx.showToast({ title: res.data.errmsg, icon: 'error', duration: 2000 })
  113. }
  114. }
  115. })
  116. }
  117. },
  118. /**
  119. * 生命周期函数--监听页面加载
  120. */
  121. onLoad: function (options) {
  122. const that = this;
  123. that.setData({ id: options.id })
  124. //验证规则函数
  125. this.initValidate();
  126. // 计算高度
  127. this.searchHeight();
  128. // 监听用户是否登录
  129. this.watchLogin();
  130. },
  131. // 监听用户是否登录
  132. watchLogin: async function () {
  133. const that = this;
  134. let id = that.data.id;
  135. wx.getStorage({
  136. key: 'token',
  137. success: async res => {
  138. const arr = await app.$get(`/courtAdmin/api/schedule/${id}`);
  139. if (arr.errcode === 0) {
  140. that.setData({ info: arr.data })
  141. that.setData({ match_file: arr.data.match_file })
  142. }
  143. },
  144. fail: res => {
  145. return wx.redirectTo({ url: '/pages/login/index', })
  146. }
  147. })
  148. },
  149. // 计算高度
  150. searchHeight: function () {
  151. let frameStyle = this.data.frameStyle;
  152. let client = app.globalData.client;
  153. // 减去状态栏
  154. let infoHeight = client.windowHeight - (client.statusBarHeight + client.getMenu.height + (client.getMenu.top - client.statusBarHeight) * 2);
  155. // 是否减去底部菜单
  156. if (frameStyle.useBar) infoHeight = infoHeight - 50;
  157. if (infoHeight) this.setData({ infoHeight: infoHeight })
  158. },
  159. /**
  160. * 生命周期函数--监听页面初次渲染完成
  161. */
  162. onReady: function () {
  163. },
  164. /**
  165. * 生命周期函数--监听页面显示
  166. */
  167. onShow: function () {
  168. },
  169. /**
  170. * 生命周期函数--监听页面隐藏
  171. */
  172. onHide: function () {
  173. },
  174. /**
  175. * 生命周期函数--监听页面卸载
  176. */
  177. onUnload: function () {
  178. },
  179. /**
  180. * 页面相关事件处理函数--监听用户下拉动作
  181. */
  182. onPullDownRefresh: function () {
  183. },
  184. /**
  185. * 页面上拉触底事件的处理函数
  186. */
  187. onReachBottom: function () {
  188. },
  189. /**
  190. * 用户点击右上角分享
  191. */
  192. onShareAppMessage: function () {
  193. }
  194. })