index.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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. // 主体高度
  11. infoHeight: '',
  12. frameStyle: { useTop: true, name: '新增赛程编排', leftArrow: true, useBar: false },
  13. form: {
  14. },
  15. // 上传图片
  16. fileList: [],
  17. //比赛id
  18. id: '',
  19. grades: [],
  20. cateArray: [],
  21. cateIndex: 0,
  22. objectArray: [],
  23. index: 0,
  24. date: '2022-05-01',
  25. time: '08:00',
  26. red: {},
  27. blue: {},
  28. },
  29. //当用户点击确定时,执行的事件
  30. bindCatePickerChange: function (e) {
  31. //下面重新赋值必须有,页面显示的信息才会改为刚刚选中的值
  32. this.setData({
  33. cateIndex: e.detail.value,
  34. })
  35. },
  36. //蓝方
  37. bindShowMsg() {
  38. this.setData({
  39. select: !this.data.select
  40. })
  41. },
  42. mySelect(e) {
  43. var name = e.currentTarget.dataset.name
  44. var blue = e.currentTarget.dataset.data
  45. this.setData({
  46. blue: blue,
  47. grade_name: name,
  48. select: false
  49. })
  50. },
  51. //红方
  52. bindShowMsg1() {
  53. this.setData({
  54. select1: !this.data.select
  55. })
  56. },
  57. mySelect1(e) {
  58. var name = e.currentTarget.dataset.name1
  59. var red = e.currentTarget.dataset.data1
  60. this.setData({
  61. red: red,
  62. grade_name1: name,
  63. select1: false
  64. })
  65. },
  66. //选择时间
  67. bindDateChange: function (e) {
  68. this.setData({
  69. date: e.detail.value
  70. })
  71. },
  72. bindTimeChange: function (e) {
  73. this.setData({
  74. time: e.detail.value
  75. })
  76. },
  77. //上传图片
  78. imgUpload: function (e) {
  79. const that = this;
  80. let data = that.data.fileList;
  81. data.push(e.detail)
  82. that.setData({ fileList: data })
  83. },
  84. //删除图片
  85. imgDel: function (e) {
  86. const that = this;
  87. let data = that.data.fileList;
  88. let arr = data.filter((i, index) => index != e.detail.index)
  89. that.setData({ fileList: arr })
  90. },
  91. back: function () {
  92. wx.navigateBack({ url: '/pages/me/index' })
  93. },
  94. //提交
  95. formSubmit: function (e) {
  96. var match_time = this.data.date + ' ' + this.data.time;
  97. const value = e.detail.value;
  98. value.match_id = this.data.id;
  99. value.red_id = this.data.red._id;
  100. value.red_name = this.data.red.team_name;
  101. value.red_logo = this.data.red.logo;
  102. value.red_members = this.data.red.members;
  103. value.blue_id = this.data.blue._id;
  104. value.blue_name = this.data.blue.team_name;
  105. value.blue_logo = this.data.blue.logo;
  106. value.blue_members = this.data.blue.members;
  107. value.match_time = match_time;
  108. if (!this.WxValidate.checkForm(value)) {
  109. const error = this.WxValidate.errorList[0];
  110. wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
  111. return false
  112. } else {
  113. wx.request({
  114. url: `${app.globalData.publicUrl}/courtAdmin/api/schedule`, //接口地址
  115. method: "post",
  116. data: value,
  117. header: {},
  118. success: res => {
  119. if (res.data.errcode == 0) {
  120. wx.showToast({
  121. title: '保存成功',
  122. icon: 'success',
  123. duration: 2000//延迟两秒
  124. })
  125. } else {
  126. wx.showToast({
  127. title: '保存失败',
  128. icon: 'success',
  129. duration: 2000
  130. })
  131. }
  132. },
  133. })
  134. }
  135. },
  136. /**
  137. * 生命周期函数--监听页面加载
  138. */
  139. onLoad: function (options) {
  140. this.setData({ id: options.id })
  141. // 计算高度
  142. this.searchHeight();
  143. // 监听用户是否登录
  144. this.watchLogin();
  145. //验证规则函数
  146. this.initValidate();
  147. },
  148. // 监听用户是否登录
  149. watchLogin: function () {
  150. const that = this;
  151. let id = that.data.id;
  152. wx.getStorage({
  153. key: 'token',
  154. success: res => {
  155. wx.request({
  156. url: `${app.globalData.publicUrl}/courtAdmin/api/match/${id}`, //接口地址
  157. method: 'get',
  158. data: {},
  159. success(res) {
  160. that.setData({ form: res.data.data })
  161. }
  162. })
  163. wx.request({
  164. url: `${app.globalData.publicUrl}/courtAdmin/api/matchteam`, //接口地址
  165. method: 'get',
  166. data: { match_id: id },
  167. success(res) {
  168. let datas = res.data.data;
  169. console.log(datas);
  170. that.setData({ cateArray: datas })
  171. }
  172. })
  173. },
  174. fail: res => {
  175. return wx.redirectTo({ url: '/pages/login/index', })
  176. }
  177. })
  178. },
  179. //验证必填项
  180. initValidate() {
  181. const rules = { match_name: { required: true }, }
  182. // 验证字段的提示信息,若不传则调用默认的信息
  183. const messages = { match_name: { required: '请输入比赛名称' }, };
  184. this.WxValidate = new WxValidate(rules, messages)
  185. },
  186. // 计算高度
  187. searchHeight: function () {
  188. let frameStyle = this.data.frameStyle;
  189. let client = app.globalData.client;
  190. // 减去状态栏
  191. let infoHeight = client.windowHeight - (client.statusBarHeight + client.getMenu.height + (client.getMenu.top - client.statusBarHeight) * 2);
  192. // 是否减去底部菜单
  193. if (frameStyle.useBar) infoHeight = infoHeight - 50;
  194. if (infoHeight) this.setData({ infoHeight: infoHeight })
  195. },
  196. /**
  197. * 生命周期函数--监听页面初次渲染完成
  198. */
  199. onReady: function () {
  200. },
  201. /**
  202. * 生命周期函数--监听页面显示
  203. */
  204. onShow: function () {
  205. },
  206. /**
  207. * 生命周期函数--监听页面隐藏
  208. */
  209. onHide: function () {
  210. },
  211. /**
  212. * 生命周期函数--监听页面卸载
  213. */
  214. onUnload: function () {
  215. },
  216. /**
  217. * 页面相关事件处理函数--监听用户下拉动作
  218. */
  219. onPullDownRefresh: function () {
  220. },
  221. /**
  222. * 页面上拉触底事件的处理函数
  223. */
  224. onReachBottom: function () {
  225. },
  226. /**
  227. * 用户点击右上角分享
  228. */
  229. onShareAppMessage: function () {
  230. }
  231. })