index.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. // pages/login/login.js
  2. import WxValidate from '../../utils/wxValidate'
  3. const app = getApp()
  4. var type = "";//用来保存picker组件选中的类别id
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. frameStyle: { useTop: true, name: '比赛修改', leftArrow: true, useBar: false },
  11. // 主体高度
  12. infoHeight: '',
  13. ids: '',
  14. form: {},
  15. cateArray: [
  16. { id: '0', type: '未开始' }, { id: '1', type: '报名中' }, { id: '2', type: '待比赛' }, { id: '3', type: '进行中' }, { id: '4', type: '已结束' }],
  17. cateIndex: 0,
  18. starttime: '2018-01-01',//默认起始时间
  19. endtime: '2018-01-24',//默认结束时间
  20. timedate: '2018-09-01',
  21. time: '12:01',
  22. // 赛制信息
  23. // 默认值
  24. szValue: [],
  25. // 赛制选择信息
  26. valueList: [],
  27. // 原数据
  28. levelArray: [
  29. ['淘汰制', '循环制'],
  30. ['单败淘汰', '双败淘汰', '交叉淘汰'],
  31. ['单循环', '双循环', '四循环']
  32. ],
  33. // 赛制储存信息
  34. szList: [],
  35. },
  36. //当用户点击确定时,执行的事件
  37. bindCatePickerChange: function (e) {
  38. var cid = this.data.cateArray[e.detail.value].id;
  39. type = cid
  40. //下面重新赋值必须有,页面显示的信息才会改为刚刚选中的值
  41. this.setData({
  42. cateIndex: e.detail.value,
  43. })
  44. },
  45. // 确定选择
  46. szChange: function (e) {
  47. const that = this;
  48. let value = e.detail.value;
  49. let list = that.data.valueList;
  50. let data = []
  51. for (let [index, val] of value.entries()) {
  52. if (list[index][val]) data.push(list[index][val])
  53. else data.push(list[index][0])
  54. }
  55. //存值
  56. let sz = [...that.data.szList, { type: data[0], name: data[1] }]
  57. that.setData({ szList: sz })
  58. that.setData({ szValue: data })
  59. that.search();
  60. },
  61. // 列值改变时
  62. columnChange: function (e) {
  63. const that = this;
  64. let array = that.data.levelArray;
  65. let list = that.data.valueList;
  66. if (e.detail.column == '0') list[1] = array[parseInt(e.detail.value) + 1];
  67. that.setData({ valueList: list });
  68. },
  69. //删除
  70. toDel: function (e) {
  71. const that = this;
  72. let list = that.data.szList;
  73. let value = e.currentTarget.dataset.index;
  74. let data = list.filter((i, index) => index != value)
  75. this.setData({ szList: data })
  76. },
  77. bindDateChange3: function (e) {
  78. this.setData({
  79. timedate: e.detail.value
  80. })
  81. },
  82. bindTimeChange: function (e) {
  83. this.setData({
  84. time: e.detail.value
  85. })
  86. },
  87. // 时间段选择
  88. bindDateChange(e) {
  89. let that = this;
  90. that.setData({
  91. starttime: e.detail.value,
  92. })
  93. },
  94. bindDateChange2(e) {
  95. let that = this;
  96. that.setData({
  97. endtime: e.detail.value,
  98. })
  99. },
  100. //提交
  101. formSubmit: function (e) {
  102. const value = e.detail.value;
  103. var form = this.data.form
  104. var id = this.ids;
  105. var name = value.name;
  106. var match_time = this.data.starttime + ' - ' + this.data.endtime;
  107. var single_time = this.data.timedate + ' ' + this.data.time;
  108. var address = value.address;
  109. var format = this.data.szList;
  110. // var match_team = this.form.match_team;
  111. const params = {
  112. "id": id,
  113. "name": name,
  114. "match_time": match_time,
  115. "single_time": single_time,
  116. "address": address,
  117. "format": format,
  118. "match_team": [],
  119. "status": type
  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.getStorage({
  127. key: 'token',
  128. success: function (res) {
  129. wx.request({
  130. url: `${app.globalData.publicUrl}/courtAdmin/api/match/${id}`, //接口地址
  131. method: 'post',
  132. data: params,
  133. success(res) {
  134. if (res.data.errcode == 0) {
  135. wx.showToast({ title: `修改比赛成功`, icon: 'success', duration: 2000 }) //创建成功提示
  136. // wx.navigateTo({ url: '/pages/administration/index' })// 跳转页面
  137. } else {
  138. wx.showToast({
  139. title: res.data.errmsg,
  140. icon: 'none',
  141. duration: 2000
  142. })
  143. }
  144. }
  145. })
  146. }
  147. })
  148. }
  149. },
  150. back: function () {
  151. wx.navigateBack({ url: '/pages/home/index' })
  152. },
  153. /**
  154. * 生命周期函数--监听页面加载
  155. */
  156. onLoad: function (options) {
  157. this.ids = options.id;
  158. //选择器
  159. var cindex = this.data.cateIndex
  160. type = this.data.cateArray[cindex].id
  161. // 监听用户是否登录
  162. this.watchLogin();
  163. //验证规则函数
  164. this.initValidate()
  165. // 计算高度
  166. this.searchHeight()
  167. const that = this;
  168. // 初始化数据
  169. that.search();
  170. },
  171. //验证是否输入
  172. initValidate() {
  173. const rules = { name: { required: true }, match_time: { required: true, }, single_time: { required: true }, address: { required: true, }, format: { required: true } }
  174. // 验证字段的提示信息,若不传则调用默认的信息
  175. const messages = { name: { required: '请输入比赛名称', }, match_time: { required: '请输入时间', }, single_time: { required: '请输入单场时间', }, address: { required: '请输入地点', }, format: { required: '请选择赛制', } };
  176. this.WxValidate = new WxValidate(rules, messages)
  177. },
  178. // 监听用户是否登录
  179. watchLogin: function () {
  180. wx.getStorage({
  181. key: 'token',
  182. success: res => {
  183. var that = this;
  184. var id = that.ids;
  185. wx.request({
  186. url: `${app.globalData.publicUrl}/courtAdmin/api/match/${id}`, //接口地址
  187. method: 'get',
  188. // data: {},
  189. success(res) {
  190. if (res.data.errcode == 0) {
  191. let datas = res.data.data
  192. let timer = res.data.data.single_time
  193. let date = res.data.data.match_time
  194. let status = res.data.data.status
  195. let szList = res.data.data.format
  196. let timedate = timer.substring(0, 10)
  197. let time = timer.substring(11, 16)
  198. let starttime = date.substring(0, 10)
  199. let endtime = date.substring(12, 28)
  200. that.setData({
  201. form: datas,
  202. timedate: timedate,
  203. time: time,
  204. starttime: starttime,
  205. endtime: endtime,
  206. cateIndex: status,
  207. szList: szList
  208. });
  209. } else {
  210. wx.showToast({
  211. title: res.data.errmsg,
  212. icon: 'none',
  213. duration: 2000
  214. })
  215. }
  216. }
  217. })
  218. },
  219. fail: res => {
  220. return wx.redirectTo({ url: '/pages/login/index', })
  221. }
  222. })
  223. },
  224. //查找选择器的值
  225. search: function () {
  226. const that = this;
  227. let data = that.data.levelArray;
  228. that.setData({ valueList: [data[0], data[1]] })
  229. },
  230. // 计算高度
  231. searchHeight: function () {
  232. let frameStyle = this.data.frameStyle;
  233. let client = app.globalData.client;
  234. // 减去状态栏
  235. let infoHeight = client.windowHeight - (client.statusBarHeight + client.getMenu.height + (client.getMenu.top - client.statusBarHeight) * 2);
  236. // 是否减去底部菜单
  237. if (frameStyle.useBar) infoHeight = infoHeight - 50;
  238. if (infoHeight) this.setData({ infoHeight: infoHeight })
  239. },
  240. /**
  241. * 生命周期函数--监听页面初次渲染完成
  242. */
  243. onReady: function () {
  244. },
  245. /**
  246. * 生命周期函数--监听页面显示
  247. */
  248. onShow: function () {
  249. },
  250. /**
  251. * 生命周期函数--监听页面隐藏
  252. */
  253. onHide: function () {
  254. },
  255. /**
  256. * 生命周期函数--监听页面卸载
  257. */
  258. onUnload: function () {
  259. },
  260. /**
  261. * 页面相关事件处理函数--监听用户下拉动作
  262. */
  263. onPullDownRefresh: function () {
  264. },
  265. /**
  266. * 页面上拉触底事件的处理函数
  267. */
  268. onReachBottom: function () {
  269. },
  270. /**
  271. * 用户点击右上角分享
  272. */
  273. onShareAppMessage: function () {
  274. }
  275. })