index.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. // pages/login/login.js
  2. import WxValidate from '../../utils/wxValidate'
  3. const app = getApp()
  4. var type = "";//用来保存picker组件选中的类别id
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. // 主体高度
  11. infoHeight: '',
  12. frameStyle: { useTop: true, name: '新增赛程编排', leftArrow: true, useBar: false },
  13. form: {
  14. },
  15. // 上传图片
  16. fileList: [],
  17. //比赛id
  18. id: '',
  19. cateArray: [],
  20. cateIndex: 0,
  21. objectArray: [],
  22. cateIndex1: 0,
  23. objectArray1: [],
  24. index: 0,
  25. date: '2022-05-01',
  26. time: '08:00',
  27. red: {},
  28. blue: {},
  29. },
  30. //蓝方
  31. bindCatePickerChangeblue: function (e) {
  32. this.setData({
  33. cateIndex: e.detail.value,
  34. blue: e.currentTarget.dataset.item,
  35. })
  36. },
  37. //红方
  38. bindCatePickerChangered: function (e) {
  39. this.setData({
  40. cateIndex1: e.detail.value,
  41. red: e.currentTarget.dataset.item,
  42. })
  43. },
  44. //选择时间
  45. bindDateChange: function (e) {
  46. this.setData({
  47. date: e.detail.value
  48. })
  49. },
  50. bindTimeChange: function (e) {
  51. this.setData({
  52. time: e.detail.value
  53. })
  54. },
  55. //上传图片
  56. imgUpload: function (e) {
  57. const that = this;
  58. let data = that.data.fileList;
  59. data.push(e.detail)
  60. that.setData({ fileList: data })
  61. },
  62. //删除图片
  63. imgDel: function (e) {
  64. const that = this;
  65. let data = that.data.fileList;
  66. let arr = data.filter((i, index) => index != e.detail.index)
  67. that.setData({ fileList: arr })
  68. },
  69. back: function () {
  70. wx.navigateBack({ url: '/pages/me/index' })
  71. },
  72. //提交
  73. formSubmit: function (e) {
  74. var match_time = this.data.date + ' ' + this.data.time;
  75. const value = e.detail.value;
  76. value.match_id = this.data.id;
  77. value.red_id = this.data.red._id;
  78. value.red_name = this.data.red.team_name;
  79. value.red_logo = this.data.red.logo;
  80. value.red_members = this.data.red.members;
  81. value.blue_id = this.data.blue._id;
  82. value.blue_name = this.data.blue.team_name;
  83. value.blue_logo = this.data.blue.logo;
  84. value.blue_members = this.data.blue.members;
  85. value.match_time = match_time;
  86. if (!this.WxValidate.checkForm(value)) {
  87. const error = this.WxValidate.errorList[0];
  88. wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
  89. return false
  90. } else {
  91. wx.request({
  92. url: `${app.globalData.publicUrl}/courtAdmin/api/schedule`, //接口地址
  93. method: "post",
  94. data: value,
  95. header: {},
  96. success: res => {
  97. if (res.data.errcode == 0) {
  98. wx.showToast({
  99. title: '保存成功',
  100. icon: 'success',
  101. duration: 2000//延迟两秒
  102. })
  103. } else {
  104. wx.showToast({
  105. title: '保存失败',
  106. icon: 'success',
  107. duration: 2000
  108. })
  109. }
  110. },
  111. })
  112. }
  113. },
  114. /**
  115. * 生命周期函数--监听页面加载
  116. */
  117. onLoad: function (options) {
  118. this.setData({ id: options.id })
  119. // 计算高度
  120. this.searchHeight();
  121. // 监听用户是否登录
  122. this.watchLogin();
  123. //验证规则函数
  124. this.initValidate();
  125. },
  126. // 监听用户是否登录
  127. watchLogin: function () {
  128. const that = this;
  129. let id = that.data.id;
  130. wx.getStorage({
  131. key: 'token',
  132. success: res => {
  133. wx.request({
  134. url: `${app.globalData.publicUrl}/courtAdmin/api/match/${id}`, //接口地址
  135. method: 'get',
  136. data: {},
  137. success(res) {
  138. that.setData({ form: res.data.data })
  139. }
  140. })
  141. wx.request({
  142. url: `${app.globalData.publicUrl}/courtAdmin/api/matchteam`, //接口地址
  143. method: 'get',
  144. data: { match_id: id },
  145. success(res) {
  146. that.setData({ cateArray: res.data.data })
  147. }
  148. })
  149. },
  150. fail: res => {
  151. return wx.redirectTo({ url: '/pages/login/index', })
  152. }
  153. })
  154. },
  155. //验证必填项
  156. initValidate() {
  157. const rules = { match_name: { required: true }, }
  158. // 验证字段的提示信息,若不传则调用默认的信息
  159. const messages = { match_name: { required: '请输入比赛名称' }, };
  160. this.WxValidate = new WxValidate(rules, messages)
  161. },
  162. // 计算高度
  163. searchHeight: function () {
  164. let frameStyle = this.data.frameStyle;
  165. let client = app.globalData.client;
  166. // 减去状态栏
  167. let infoHeight = client.windowHeight - (client.statusBarHeight + client.getMenu.height + (client.getMenu.top - client.statusBarHeight) * 2);
  168. // 是否减去底部菜单
  169. if (frameStyle.useBar) infoHeight = infoHeight - 50;
  170. if (infoHeight) this.setData({ infoHeight: infoHeight })
  171. },
  172. /**
  173. * 生命周期函数--监听页面初次渲染完成
  174. */
  175. onReady: function () {
  176. },
  177. /**
  178. * 生命周期函数--监听页面显示
  179. */
  180. onShow: function () {
  181. },
  182. /**
  183. * 生命周期函数--监听页面隐藏
  184. */
  185. onHide: function () {
  186. },
  187. /**
  188. * 生命周期函数--监听页面卸载
  189. */
  190. onUnload: function () {
  191. },
  192. /**
  193. * 页面相关事件处理函数--监听用户下拉动作
  194. */
  195. onPullDownRefresh: function () {
  196. },
  197. /**
  198. * 页面上拉触底事件的处理函数
  199. */
  200. onReachBottom: function () {
  201. },
  202. /**
  203. * 用户点击右上角分享
  204. */
  205. onShareAppMessage: function () {
  206. }
  207. })