index.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. const app = getApp()
  2. import WxValidate from '../../utils/wxValidate'
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. team_id: "",
  9. id: '',
  10. form: {},
  11. // 状态
  12. userList: [],
  13. red_disabled: false,
  14. blue_disabled: false
  15. },
  16. // 过滤字典表
  17. getDict(value, model) {
  18. const that = this;
  19. if (model == 'winner') {
  20. if (value) {
  21. let list = that.data[model + 'List']
  22. let data = list.find(i => i._id == value);
  23. if (data) return data.name
  24. else return '暂无'
  25. }
  26. }
  27. },
  28. // 提交保存
  29. async toSave(e) {
  30. const that = this;
  31. const parmas = e.detail.value;
  32. if (!this.WxValidate.checkForm(parmas)) {
  33. const error = that.WxValidate.errorList[0];
  34. wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
  35. return false
  36. } else {
  37. // 判断id使用
  38. let form = that.data.form;
  39. let res;
  40. if (form._id) res = await app.$api(`course/${form._id}`, 'POST', parmas);
  41. else res = await app.$api('course', 'POST', parmas);
  42. if (res.errcode == '0') {
  43. wx.showToast({ title: `信息提交成功`, icon: 'success' });
  44. wx.navigateBack({ delta: 1 });
  45. } else {
  46. wx.showToast({ title: `${res.errmsg}`, icon: 'none' });
  47. }
  48. }
  49. },
  50. /**
  51. * 生命周期函数--监听页面加载
  52. */
  53. async onLoad(options) {
  54. const that = this;
  55. that.setData({ id: options.id, team_id: options.team_id });
  56. wx.showLoading({ title: '加载中', mask: true })
  57. //验证规则函数
  58. that.initValidate();
  59. await that.searchOther()
  60. await that.search()
  61. wx.hideLoading()
  62. },
  63. initValidate() {
  64. const rules = { red_score: { required: true }, blue_score: { required: true } }
  65. const messages = { red_score: { required: '请输入红方比分' }, blue_score: { required: '请输入蓝方比分' } };
  66. this.WxValidate = new WxValidate(rules, messages)
  67. },
  68. // 查询其他信息
  69. async searchOther() {
  70. const that = this;
  71. let res;
  72. // 团队
  73. res = await app.$api('team', 'GET', { status: '1' })
  74. if (res.errcode == '0') that.setData({ userList: res.data })
  75. },
  76. search() {
  77. const that = this;
  78. wx.getStorage({
  79. key: 'user',
  80. async success(res) {
  81. let form = {}
  82. let aee = await app.$api(`course/${that.data.id}`, 'GET', {})
  83. if (aee.errcode == '0') {
  84. form = aee.data;
  85. if (form && form._id) {
  86. if (form.red_team_id == that.data.team_id) that.setData({ blue_disabled: true })
  87. else if (form.blue_team_id == that.data.team_id) that.setData({ red_disabled: true })
  88. }
  89. } else {
  90. wx.showToast({ title: `${aee.errmsg}`, icon: 'error' });
  91. }
  92. that.setData({ form })
  93. },
  94. fail(err) {
  95. // console.log(err);
  96. }
  97. })
  98. },
  99. /**
  100. * 生命周期函数--监听页面初次渲染完成
  101. */
  102. onReady() {
  103. },
  104. /**
  105. * 生命周期函数--监听页面显示
  106. */
  107. onShow() {
  108. },
  109. /**
  110. * 生命周期函数--监听页面隐藏
  111. */
  112. onHide() {
  113. },
  114. /**
  115. * 生命周期函数--监听页面卸载
  116. */
  117. onUnload() {
  118. },
  119. /**
  120. * 页面相关事件处理函数--监听用户下拉动作
  121. */
  122. onPullDownRefresh() {
  123. },
  124. /**
  125. * 页面上拉触底事件的处理函数
  126. */
  127. onReachBottom() {
  128. },
  129. /**
  130. * 用户点击右上角分享
  131. */
  132. onShareAppMessage() {
  133. }
  134. })