index.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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. names: '',
  13. address: '',
  14. date: '2022-01-01',//默认起始时间
  15. date2: '2022-01-24',//默认结束时间
  16. singledate: '2022-01-01',
  17. time: '12:01',
  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. onChangenames(e) {
  44. this.data.names = e.detail
  45. },
  46. //地点改变值
  47. onChangeaddress(e) {
  48. this.data.address = e.detail
  49. },
  50. // 确定选择
  51. szChange: function (e) {
  52. const that = this;
  53. let value = e.detail.value;
  54. let list = that.data.valueList;
  55. let data = []
  56. for (let [index, val] of value.entries()) {
  57. if (list[index][val]) data.push(list[index][val])
  58. else data.push(list[index][0])
  59. }
  60. //存值
  61. let sz = [...that.data.szList, { type: data[0], name: data[1] }]
  62. that.setData({ szList: sz })
  63. that.setData({ szValue: data })
  64. that.search();
  65. },
  66. // 列值改变时
  67. columnChange: function (e) {
  68. const that = this;
  69. let array = that.data.levelArray;
  70. let list = that.data.valueList;
  71. if (e.detail.column == '0') list[1] = array[parseInt(e.detail.value) + 1];
  72. that.setData({ valueList: list });
  73. },
  74. //删除
  75. toDel: function (e) {
  76. const that = this;
  77. let list = that.data.szList;
  78. let value = e.currentTarget.dataset.index;
  79. let data = list.filter((i, index) => index != value)
  80. this.setData({ szList: data })
  81. },
  82. //日期选择器
  83. bindDateChange3: function (e) {
  84. this.setData({
  85. singledate: e.detail.value
  86. })
  87. },
  88. //时间选择器
  89. bindTimeChange: function (e) {
  90. this.setData({
  91. time: e.detail.value
  92. })
  93. },
  94. // 时间段选择
  95. bindDateChange(e) {
  96. let that = this;
  97. that.setData({
  98. date: e.detail.value,
  99. })
  100. },
  101. bindDateChange2(e) {
  102. let that = this;
  103. that.setData({
  104. date2: e.detail.value,
  105. })
  106. },
  107. // 提交创建
  108. onSubmit: function (e) {
  109. var name = this.data.names;
  110. var match_time = this.data.date + ' - ' + this.data.date2;
  111. var single_time = this.data.singledate + ' ' + this.data.time;
  112. var address = this.data.address;
  113. var format = this.data.szList;
  114. const params = {
  115. "name": name,
  116. "match_time": match_time,
  117. "single_time": single_time,
  118. "address": address,
  119. "format": format,
  120. };
  121. if (!this.WxValidate.checkForm(params)) {
  122. const error = this.WxValidate.errorList[0];
  123. wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
  124. return false
  125. } else {
  126. wx.request({
  127. url: `${app.globalData.publicUrl}/courtAdmin/api/match`,
  128. method: 'post',
  129. data: params,
  130. success(res) {
  131. if (res.data.errcode == 0) {
  132. wx.showToast({ title: `创建比赛成功`, icon: 'success', duration: 2000 })
  133. wx.navigateTo({ url: '/pages/administration/index' })
  134. } else {
  135. wx.showToast({
  136. title: res.data.errmsg,
  137. icon: 'none',
  138. duration: 2000
  139. })
  140. }
  141. }
  142. })
  143. }
  144. },
  145. /**
  146. * 生命周期函数--监听页面加载
  147. */
  148. onLoad: function (options) {
  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. })