list.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. const app = getApp();
  2. import WxValidate from '../../../utils/wxValidate';
  3. Page({
  4. data: {
  5. frameStyle: { useTop: true, name: '淘汰赛管理', leftArrow: true, useBar: false },
  6. dialog: { title: '赛程上分', show: false, type: '1' },
  7. form: {},
  8. list: [],
  9. total: 0,
  10. page: 0,
  11. skip: 0,
  12. limit: 5,
  13. statusList: []
  14. },
  15. initValidate() {
  16. const rules = { player_one_score: { required: true }, player_two_score: { required: true } }
  17. // 验证字段的提示信息,若不传则调用默认的信息
  18. const messages = { player_one_score: { required: '选手一比分' }, player_two_score: { required: '选手二比分' } };
  19. this.WxValidate = new WxValidate(rules, messages)
  20. },
  21. // 返回
  22. back: function () { wx.navigateBack({ delta: 1 }) },
  23. // 详细信息
  24. toCommon: function (e) {
  25. const that = this;
  26. const { item, route } = e.currentTarget.dataset;
  27. that.setData({ skip: 0, page: 0, list: [] });
  28. wx.navigateTo({ url: `/pagesMatch/${route}?id=${item && item._id ? item._id : ''}` })
  29. },
  30. // 赛程上分
  31. toScore: function (e) {
  32. const that = this;
  33. const { item } = e.currentTarget.dataset;
  34. that.setData({ form: item })
  35. that.setData({ dialog: { title: '赛程上分', show: true, type: '1' } })
  36. },
  37. // 提交保存
  38. onSubmit: async function (e) {
  39. const that = this;
  40. const params = e.detail.value;
  41. const form = that.data.form;
  42. if (!this.WxValidate.checkForm(params)) {
  43. const error = this.WxValidate.errorList[0];
  44. wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
  45. return false
  46. } else {
  47. let arr = await app.$post(`/eliminate/${form.id}`, params, 'race');
  48. if (arr.errcode == '0') {
  49. wx.showToast({ title: `上分成功`, icon: 'success', duration: 2000 });
  50. that.setData({ skip: 0, page: 0, list: [], form: {} })
  51. that.watchLogin()
  52. that.toClose();
  53. }
  54. else wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 })
  55. }
  56. },
  57. // 删除
  58. toChange: function (e) {
  59. const that = this;
  60. const { item } = e.currentTarget.dataset;
  61. wx.showModal({
  62. title: '提示',
  63. content: '是否确认交换场地?',
  64. async success(res) {
  65. if (res.confirm) {
  66. let arr = await app.$post(`/eliminate/${item._id}`, { is_change: '1' }, 'race');
  67. if (arr.errcode == '0') {
  68. wx.showToast({ title: `交换场地成功`, icon: 'success', duration: 2000 });
  69. that.setData({ skip: 0, page: 0, list: [] })
  70. that.watchLogin();
  71. }
  72. else wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 })
  73. }
  74. }
  75. })
  76. },
  77. // 分页
  78. toPage: function () {
  79. const that = this;
  80. let list = that.data.list;
  81. let limit = that.data.limit;
  82. if (that.data.total > list.length) {
  83. wx.showLoading({ title: '加载中', mask: true })
  84. let page = that.data.page + 1;
  85. that.setData({ page: page })
  86. let skip = page * limit;
  87. that.setData({ skip: skip })
  88. that.watchLogin();
  89. wx.hideLoading()
  90. } else { wx.showToast({ title: '没有更多数据了', icon: 'none', duration: 2000 }) }
  91. },
  92. // 关闭弹框
  93. toClose: function () {
  94. const that = this;
  95. that.setData({ dialog: { title: '赛程上分', show: false, type: '1' } })
  96. },
  97. /**
  98. * 生命周期函数--监听页面加载
  99. */
  100. onLoad: function (options) { },
  101. /**
  102. * 生命周期函数--监听页面初次渲染完成
  103. */
  104. onReady: function () { },
  105. /**
  106. * 生命周期函数--监听页面显示
  107. */
  108. onShow: async function () {
  109. const that = this;
  110. //验证规则函数
  111. that.initValidate();
  112. // 查询其他信息
  113. await that.searchOther();
  114. // 监听用户是否登录
  115. await that.watchLogin();
  116. },
  117. searchOther: async function () {
  118. const that = this;
  119. let arr;
  120. arr = await app.$get(`/dict`, { code: "schedule_status" });
  121. if (arr.errcode == '0' && arr.total > 0) that.setData({ statusList: arr.data[0].list });
  122. },
  123. // 监听用户是否登录
  124. watchLogin: async function () {
  125. const that = this;
  126. wx.getStorage({
  127. key: 'raceuser',
  128. success: async res => {
  129. let info = { skip: that.data.skip, limit: that.data.limit, referee_id: res.data._id };
  130. let arr = await app.$get(`/eliminate`, { ...info }, 'race');
  131. if (arr.errcode == '0') {
  132. let list = [...that.data.list, ...arr.data]
  133. for (const val of list) {
  134. let status = that.data.statusList.find(i => i.value == val.status)
  135. if (status) val.zhStatus = status.label;
  136. }
  137. that.setData({ list })
  138. that.setData({ total: arr.total })
  139. } else { wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 }) }
  140. },
  141. fail: async res => {
  142. wx.redirectTo({ url: '/pages/index/index' })
  143. }
  144. })
  145. },
  146. /**
  147. * 页面上拉触底事件的处理函数
  148. */
  149. /**
  150. * 生命周期函数--监听页面隐藏
  151. */
  152. onHide: function () {
  153. const that = this;
  154. that.setData({ skip: 0, page: 0, list: [] })
  155. },
  156. /**
  157. * 生命周期函数--监听页面卸载
  158. */
  159. onUnload: function () {
  160. },
  161. /**
  162. * 页面相关事件处理函数--监听用户下拉动作
  163. */
  164. onPullDownRefresh: function () {
  165. },
  166. /**
  167. * 用户点击右上角分享
  168. */
  169. onShareAppMessage: function () {
  170. }
  171. })