index.js 6.1 KB

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