index.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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. initValidate() {
  33. const rules = { name: { required: true }, match_time: { required: true, }, single_time: { required: true }, address: { required: true, }, format: { required: true } }
  34. // 验证字段的提示信息,若不传则调用默认的信息
  35. const messages = { name: { required: '请输入比赛名称', }, match_time: { required: '请输入时间', }, single_time: { required: '请输入单场时间', }, address: { required: '请输入地点', }, format: { required: '请选择赛制', } };
  36. this.WxValidate = new WxValidate(rules, messages)
  37. },
  38. // 监听用户是否登录
  39. watchLogin: function () {
  40. wx.getStorage({
  41. key: 'token',
  42. success: res => {
  43. console.log(res);
  44. },
  45. fail: res => {
  46. return wx.redirectTo({ url: '/pages/login/index', })
  47. }
  48. })
  49. },
  50. // 提交创建
  51. onSubmit: function (e) {
  52. var name = this.data.names;
  53. var match_time = this.data.date + ' - ' + this.data.date2;
  54. var single_time = this.data.singledate + ' ' + this.data.time;
  55. var address = this.data.address;
  56. var format = this.data.szList;
  57. const params = {
  58. "name": name,
  59. "match_time": match_time,
  60. "single_time": single_time,
  61. "address": address,
  62. "format": format,
  63. };
  64. if (!this.WxValidate.checkForm(params)) {
  65. const error = this.WxValidate.errorList[0];
  66. wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
  67. return false
  68. } else {
  69. wx.request({
  70. url: `${app.globalData.publicUrl}/courtAdmin/api/match`, //接口地址
  71. method: 'post',
  72. data: params,
  73. success(res) {
  74. console.log(res.data);
  75. if (res.data.errcode == 0) {
  76. wx.showToast({ title: `创建比赛成功`, icon: 'success', duration: 2000 }) //创建成功提示
  77. wx.navigateTo({ url: '/pages/administration/index' })// 跳转页面
  78. } else {
  79. wx.showToast({
  80. title: res.data.errmsg,
  81. icon: 'none',
  82. duration: 2000
  83. })
  84. }
  85. }
  86. })
  87. }
  88. },
  89. //input改变值
  90. onChangenames(e) {
  91. this.data.names = e.detail
  92. },
  93. //input改变值
  94. onChangeaddress(e) {
  95. this.data.address = e.detail
  96. },
  97. // 确定选择
  98. szChange: function (e) {
  99. const that = this;
  100. let value = e.detail.value;
  101. let list = that.data.valueList;
  102. let data = []
  103. for (let [index, val] of value.entries()) {
  104. if (list[index][val]) data.push(list[index][val])
  105. else data.push(list[index][0])
  106. }
  107. //存值
  108. let sz = [...that.data.szList, { type: data[0], name: data[1] }]
  109. that.setData({ szList: sz })
  110. that.setData({ szValue: data })
  111. that.search();
  112. },
  113. // 列值改变时
  114. columnChange: function (e) {
  115. const that = this;
  116. let array = that.data.levelArray;
  117. let list = that.data.valueList;
  118. if (e.detail.column == '0') list[1] = array[parseInt(e.detail.value) + 1];
  119. that.setData({ valueList: list });
  120. },
  121. //删除
  122. toDel: function (e) {
  123. const that = this;
  124. let list = that.data.szList;
  125. let value = e.currentTarget.dataset.index;
  126. let data = list.filter((i, index) => index != value)
  127. this.setData({ szList: data })
  128. },
  129. search: function () {
  130. const that = this;
  131. let data = that.data.levelArray;
  132. that.setData({ valueList: [data[0], data[1]] })
  133. },
  134. bindDateChange3: function (e) {
  135. console.log('picker发送选择改变,携带值为', e.detail.value)
  136. this.setData({
  137. singledate: e.detail.value
  138. })
  139. },
  140. bindTimeChange: function (e) {
  141. console.log('picker发送选择改变,携带值为', e.detail.value)
  142. this.setData({
  143. time: e.detail.value
  144. })
  145. },
  146. // 时间段选择
  147. bindDateChange(e) {
  148. let that = this;
  149. console.log(e.detail.value)
  150. that.setData({
  151. date: e.detail.value,
  152. })
  153. },
  154. bindDateChange2(e) {
  155. let that = this;
  156. that.setData({
  157. date2: e.detail.value,
  158. })
  159. },
  160. back: function () {
  161. wx.navigateBack({ url: '/pages/home/index' })
  162. },
  163. /**
  164. * 生命周期函数--监听页面加载
  165. */
  166. onLoad: function (options) {
  167. // 监听用户是否登录
  168. this.watchLogin();
  169. //验证规则函数
  170. this.initValidate()
  171. // 计算高度
  172. this.searchHeight()
  173. const that = this;
  174. // 初始化数据
  175. that.search();
  176. },
  177. // 计算高度
  178. searchHeight: function () {
  179. let frameStyle = this.data.frameStyle;
  180. let client = app.globalData.client;
  181. // 减去状态栏
  182. let infoHeight = client.windowHeight - (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. })