index.js 6.0 KB

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