index.js 6.1 KB

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