addressAdd.js 4.2 KB

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