add.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. const app = getApp();
  2. import WxValidate from '../../utils/wxValidate';
  3. import { isuse } from '../../utils/dict'
  4. Page({
  5. data: {
  6. frameStyle: { useTop: true, name: '信息管理', leftArrow: true, useBar: false },
  7. form: {},
  8. // 裁判信息
  9. refereeList: [],
  10. // 是否启用
  11. isuseList: isuse
  12. },
  13. initValidate() {
  14. const rules = { name: { required: true }, is_use: { required: true } }
  15. // 验证字段的提示信息,若不传则调用默认的信息
  16. const messages = { name: { required: '请输入场地名称' }, is_use: { required: '请选择是否启用' } };
  17. this.WxValidate = new WxValidate(rules, messages)
  18. },
  19. back: function () {
  20. wx.navigateBack({
  21. delta: 1,
  22. })
  23. },
  24. // 选择裁判
  25. referee_idChange: function (e) {
  26. const that = this;
  27. let index = e.detail.value;
  28. let value = that.data.refereeList[index];
  29. that.setData({ 'form.referee_id': value.openid });
  30. that.setData({ 'form.referee_name': value.name });
  31. },
  32. // 是否使用
  33. is_useChange: function (e) {
  34. const that = this;
  35. let index = e.detail.value;
  36. let value = that.data.isuseList[index];
  37. that.setData({ 'form.is_use': value.value });
  38. },
  39. toSubmit: async function (e) {
  40. const that = this;
  41. const form = that.data.form;
  42. const params = e.detail.value;
  43. if (!this.WxValidate.checkForm(params)) {
  44. const error = this.WxValidate.errorList[0];
  45. wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
  46. return false
  47. } else {
  48. let arr;
  49. if (form.id) arr = await app.$post(`/newCourt/api/ground/${form.id}`, params);
  50. else arr = await app.$post(`/newCourt/api/ground`, params);
  51. if (arr.errcode == '0') { wx.showToast({ title: `维护信息成功`, icon: 'success', duration: 2000 }); that.back() }
  52. else { wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 }) }
  53. }
  54. },
  55. /**
  56. * 生命周期函数--监听页面加载
  57. */
  58. onLoad: function (options) {
  59. const that = this;
  60. console.log(options);
  61. //验证规则函数
  62. that.initValidate();
  63. },
  64. // 监听用户是否登录
  65. watchLogin: async function () {
  66. const that = this;
  67. // 监听用户是否登录,
  68. // wx.getStorage({
  69. // key: 'user',
  70. // success: async res => {
  71. // // if (res.data) wx.redirectTo({ url: '/pages/home/index' })
  72. // },
  73. // fail: async res => {
  74. // // wx.redirectTo({ url: '/pages/index/index' })
  75. // }
  76. // })
  77. // 查询裁判信息
  78. let arr;
  79. arr = await app.$get(`/newCourt/api/user`, { type: '-1' });
  80. if (arr.errcode == '0') { that.setData({ refereeList: arr.data }) }
  81. else { wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 }) }
  82. },
  83. /**
  84. * 生命周期函数--监听页面初次渲染完成
  85. */
  86. onReady: function () {
  87. },
  88. /**
  89. * 生命周期函数--监听页面显示
  90. */
  91. onShow: function () {
  92. const that = this;
  93. // 监听用户是否登录
  94. that.watchLogin();
  95. },
  96. /**
  97. * 生命周期函数--监听页面隐藏
  98. */
  99. onHide: function () {
  100. },
  101. /**
  102. * 生命周期函数--监听页面卸载
  103. */
  104. onUnload: function () {
  105. },
  106. /**
  107. * 页面相关事件处理函数--监听用户下拉动作
  108. */
  109. onPullDownRefresh: function () {
  110. },
  111. /**
  112. * 页面上拉触底事件的处理函数
  113. */
  114. onReachBottom: function () {
  115. },
  116. /**
  117. * 用户点击右上角分享
  118. */
  119. onShareAppMessage: function () {
  120. }
  121. })