index.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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. grades: [],
  20. cateArray: [
  21. { id: '0', type: '未开始' }, { id: '1', type: '报名中' }, { id: '2', type: '待比赛' }, { id: '3', type: '进行中' }, { id: '4', type: '已结束' }],
  22. cateIndex: 0,
  23. objectArray: [],
  24. index: 0,
  25. date: '2022-05-01',
  26. time: '08:00',
  27. red: {},
  28. blue: {},
  29. },
  30. //当用户点击确定时,执行的事件
  31. bindCatePickerChange: function (e) {
  32. var cid = this.data.cateArray[e.detail.value].id;
  33. type = cid
  34. //下面重新赋值必须有,页面显示的信息才会改为刚刚选中的值
  35. this.setData({
  36. cateIndex: e.detail.value,
  37. })
  38. },
  39. //蓝方
  40. bindShowMsg() {
  41. this.setData({
  42. select: !this.data.select
  43. })
  44. },
  45. mySelect(e) {
  46. var name = e.currentTarget.dataset.name
  47. var blue = e.currentTarget.dataset.data
  48. this.setData({
  49. blue: blue,
  50. grade_name: name,
  51. select: false
  52. })
  53. },
  54. //红方
  55. bindShowMsg1() {
  56. this.setData({
  57. select1: !this.data.select
  58. })
  59. },
  60. mySelect1(e) {
  61. var name = e.currentTarget.dataset.name1
  62. var red = e.currentTarget.dataset.data1
  63. this.setData({
  64. red: red,
  65. grade_name1: name,
  66. select1: false
  67. })
  68. },
  69. //选择时间
  70. bindDateChange: function (e) {
  71. this.setData({
  72. date: e.detail.value
  73. })
  74. },
  75. bindTimeChange: function (e) {
  76. this.setData({
  77. time: e.detail.value
  78. })
  79. },
  80. //上传图片
  81. imgUpload: function (e) {
  82. const that = this;
  83. let data = that.data.fileList;
  84. data.push(e.detail)
  85. that.setData({ fileList: data })
  86. },
  87. //删除图片
  88. imgDel: function (e) {
  89. const that = this;
  90. let data = that.data.fileList;
  91. let arr = data.filter((i, index) => index != e.detail.index)
  92. that.setData({ fileList: arr })
  93. },
  94. back: function () {
  95. wx.navigateBack({ url: '/pages/me/index' })
  96. },
  97. //提交
  98. formSubmit: function (e) {
  99. var match_time = this.data.date + ' ' + this.data.time;
  100. const value = e.detail.value;
  101. value.match_id = this.data.id;
  102. value.red_id = this.data.red._id;
  103. value.red_name = this.data.red.team_name;
  104. value.red_logo = this.data.red.logo;
  105. value.red_members = this.data.red.members;
  106. value.blue_id = this.data.blue._id;
  107. value.blue_name = this.data.blue.team_name;
  108. value.blue_logo = this.data.blue.logo;
  109. value.blue_members = this.data.blue.members;
  110. value.match_time = match_time;
  111. if (!this.WxValidate.checkForm(value)) {
  112. const error = this.WxValidate.errorList[0];
  113. wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
  114. return false
  115. } else {
  116. wx.request({
  117. url: `${app.globalData.publicUrl}/courtAdmin/api/schedule`, //接口地址
  118. method: "post",
  119. data: value,
  120. header: {},
  121. success: res => {
  122. if (res.data.errcode == 0) {
  123. wx.showToast({
  124. title: '保存成功',
  125. icon: 'success',
  126. duration: 2000//延迟两秒
  127. })
  128. } else {
  129. wx.showToast({
  130. title: '保存失败',
  131. icon: 'success',
  132. duration: 2000
  133. })
  134. }
  135. },
  136. })
  137. }
  138. },
  139. /**
  140. * 生命周期函数--监听页面加载
  141. */
  142. onLoad: function (options) {
  143. //选择器
  144. var cindex = this.data.cateIndex
  145. type = this.data.cateArray[cindex].id
  146. this.setData({ id: options.id })
  147. // 计算高度
  148. this.searchHeight();
  149. // 监听用户是否登录
  150. this.watchLogin();
  151. //验证规则函数
  152. this.initValidate();
  153. },
  154. // 监听用户是否登录
  155. watchLogin: function () {
  156. const that = this;
  157. let id = that.data.id;
  158. wx.getStorage({
  159. key: 'token',
  160. success: res => {
  161. wx.request({
  162. url: `${app.globalData.publicUrl}/courtAdmin/api/match/${id}`, //接口地址
  163. method: 'get',
  164. data: {},
  165. success(res) {
  166. that.setData({ form: res.data.data })
  167. }
  168. })
  169. wx.request({
  170. url: `${app.globalData.publicUrl}/courtAdmin/api/matchteam`, //接口地址
  171. method: 'get',
  172. data: { match_id: id },
  173. success(res) {
  174. let datas = res.data.data;
  175. console.log(datas);
  176. that.setData({ cateArray: datas })
  177. }
  178. })
  179. },
  180. fail: res => {
  181. return wx.redirectTo({ url: '/pages/login/index', })
  182. }
  183. })
  184. },
  185. //验证必填项
  186. initValidate() {
  187. const rules = { match_name: { required: true }, }
  188. // 验证字段的提示信息,若不传则调用默认的信息
  189. const messages = { match_name: { required: '请输入比赛名称' }, };
  190. this.WxValidate = new WxValidate(rules, messages)
  191. },
  192. // 计算高度
  193. searchHeight: function () {
  194. let frameStyle = this.data.frameStyle;
  195. let client = app.globalData.client;
  196. // 减去状态栏
  197. let infoHeight = client.windowHeight - (client.statusBarHeight + client.getMenu.height + (client.getMenu.top - client.statusBarHeight) * 2);
  198. // 是否减去底部菜单
  199. if (frameStyle.useBar) infoHeight = infoHeight - 50;
  200. if (infoHeight) this.setData({ infoHeight: infoHeight })
  201. },
  202. /**
  203. * 生命周期函数--监听页面初次渲染完成
  204. */
  205. onReady: function () {
  206. },
  207. /**
  208. * 生命周期函数--监听页面显示
  209. */
  210. onShow: function () {
  211. },
  212. /**
  213. * 生命周期函数--监听页面隐藏
  214. */
  215. onHide: function () {
  216. },
  217. /**
  218. * 生命周期函数--监听页面卸载
  219. */
  220. onUnload: function () {
  221. },
  222. /**
  223. * 页面相关事件处理函数--监听用户下拉动作
  224. */
  225. onPullDownRefresh: function () {
  226. },
  227. /**
  228. * 页面上拉触底事件的处理函数
  229. */
  230. onReachBottom: function () {
  231. },
  232. /**
  233. * 用户点击右上角分享
  234. */
  235. onShareAppMessage: function () {
  236. }
  237. })