index.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. // pages/login/login.js
  2. import WxValidate from '../../utils/wxValidate'
  3. const moment = require("../../utils/moment.min")
  4. const app = getApp()
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. frameStyle: { useTop: true, name: '创建比赛', leftArrow: true, useBar: false },
  11. // 主体高度
  12. infoHeight: '',
  13. form: {},
  14. singledate: '2022-04-11',
  15. time: '12:01',
  16. date: '2022-04-11',//默认起始时间
  17. date2: '2022-04-24',//默认结束时间
  18. // 赛制信息
  19. // 默认值
  20. szValue: [],
  21. // 赛制选择信息
  22. valueList: [],
  23. // 原数据
  24. levelArray: [
  25. ['淘汰制', '循环制'],
  26. ['单败淘汰', '双败淘汰', '交叉淘汰'],
  27. ['单循环', '双循环', '四循环']
  28. ],
  29. // 赛制储存信息
  30. szList: [],
  31. },
  32. //验证是否输入
  33. initValidate() {
  34. const rules = { name: { required: true }, match_time: { required: true, }, single_time: { required: true }, address: { required: true, }, format: { required: true } }
  35. // 验证字段的提示信息,若不传则调用默认的信息
  36. const messages = { name: { required: '请输入比赛名称', }, match_time: { required: '请输入时间', }, single_time: { required: '请输入单场时间', }, address: { required: '请输入地点', }, format: { required: '请选择赛制', } };
  37. this.WxValidate = new WxValidate(rules, messages)
  38. },
  39. back: function () {
  40. wx.navigateBack({ url: '/pages/home/index' })
  41. },
  42. // 确定选择
  43. szChange: function (e) {
  44. const that = this;
  45. let value = e.detail.value;
  46. let list = that.data.valueList;
  47. let data = []
  48. for (let [index, val] of value.entries()) {
  49. if (list[index][val]) data.push(list[index][val])
  50. else data.push(list[index][0])
  51. }
  52. //存值
  53. let sz = [...that.data.szList, { type: data[0], name: data[1] }]
  54. that.setData({ szList: sz })
  55. that.setData({ szValue: data })
  56. that.search();
  57. },
  58. // 列值改变时
  59. columnChange: function (e) {
  60. const that = this;
  61. let array = that.data.levelArray;
  62. let list = that.data.valueList;
  63. if (e.detail.column == '0') list[1] = array[parseInt(e.detail.value) + 1];
  64. that.setData({ valueList: list });
  65. },
  66. //删除
  67. toDel: function (e) {
  68. const that = this;
  69. let list = that.data.szList;
  70. let value = e.currentTarget.dataset.index;
  71. let data = list.filter((i, index) => index != value)
  72. this.setData({ szList: data })
  73. },
  74. //日期选择器
  75. bindDateChange3: function (e) {
  76. this.setData({ singledate: e.detail.value })
  77. },
  78. //时间选择器
  79. bindTimeChange: function (e) {
  80. this.setData({ time: e.detail.value })
  81. },
  82. // 时间段选择
  83. bindDateChange(e) {
  84. let that = this;
  85. that.setData({ date: e.detail.value })
  86. },
  87. bindDateChange2(e) {
  88. let that = this;
  89. that.setData({ date2: e.detail.value })
  90. },
  91. // 提交创建
  92. onSubmit: function (e) {
  93. const param = e.detail.value;
  94. param.match_time = this.data.date + ' - ' + this.data.date2;
  95. param.single_time = this.data.singledate + ' ' + this.data.time;
  96. param.format = this.data.szList;
  97. if (!this.WxValidate.checkForm(param)) {
  98. const error = this.WxValidate.errorList[0];
  99. wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
  100. return false
  101. } else {
  102. wx.request({
  103. url: `${app.globalData.publicUrl}/courtAdmin/api/match`,
  104. method: 'post',
  105. data: param,
  106. success(res) {
  107. if (res.data.errcode == 0) {
  108. wx.showToast({ title: `创建比赛成功`, icon: 'success', duration: 2000 })
  109. wx.navigateTo({ url: '/pages/administration/index' })
  110. } else {
  111. wx.showToast({ title: res.data.errmsg, icon: 'none', duration: 2000 })
  112. }
  113. }
  114. })
  115. }
  116. },
  117. /**
  118. * 生命周期函数--监听页面加载
  119. */
  120. onLoad: function (options) {
  121. const that = this;
  122. //获取当前时间
  123. let date = moment().format('YYYY-MM-DD');
  124. this.setData({ date: date, singledate: date });
  125. //验证规则函数
  126. this.initValidate();
  127. // 计算高度
  128. this.searchHeight();
  129. // 监听用户是否登录
  130. this.watchLogin();
  131. // 初始化数据
  132. that.search();
  133. },
  134. // 监听用户是否登录
  135. watchLogin: function () {
  136. wx.getStorage({
  137. key: 'token',
  138. success: res => {
  139. },
  140. fail: res => {
  141. return wx.redirectTo({ url: '/pages/login/index', })
  142. }
  143. })
  144. },
  145. //查找选择器的值
  146. search: function () {
  147. const that = this;
  148. let data = that.data.levelArray;
  149. that.setData({ valueList: [data[0], data[1]] })
  150. },
  151. // 计算高度
  152. searchHeight: function () {
  153. let frameStyle = this.data.frameStyle;
  154. let client = app.globalData.client;
  155. let infoHeight = client.windowHeight;
  156. // 是否去掉状态栏
  157. if (frameStyle.useTop) infoHeight = infoHeight - (client.statusBarHeight + client.getMenu.height + (client.getMenu.top - client.statusBarHeight) * 2);
  158. // 是否减去底部菜单
  159. if (frameStyle.useBar) infoHeight = infoHeight - 50;
  160. if (infoHeight) this.setData({ infoHeight: infoHeight })
  161. },
  162. /**
  163. * 生命周期函数--监听页面初次渲染完成
  164. */
  165. onReady: function () {
  166. },
  167. /**
  168. * 生命周期函数--监听页面显示
  169. */
  170. onShow: function () {
  171. },
  172. /**
  173. * 生命周期函数--监听页面隐藏
  174. */
  175. onHide: function () {
  176. },
  177. /**
  178. * 生命周期函数--监听页面卸载
  179. */
  180. onUnload: function () {
  181. },
  182. /**
  183. * 页面相关事件处理函数--监听用户下拉动作
  184. */
  185. onPullDownRefresh: function () {
  186. },
  187. /**
  188. * 页面上拉触底事件的处理函数
  189. */
  190. onReachBottom: function () {
  191. },
  192. /**
  193. * 用户点击右上角分享
  194. */
  195. onShareAppMessage: function () {
  196. }
  197. })