info.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. const app = getApp();
  2. Page({
  3. data: {
  4. frameStyle: { useTop: true, name: '详细信息', leftArrow: true, useBar: false },
  5. id: '',
  6. info: {},
  7. statusList: []
  8. },
  9. // 返回
  10. back: function () { wx.navigateBack({ delta: 1 }) },
  11. /**
  12. * 生命周期函数--监听页面加载
  13. */
  14. onLoad: async function (options) {
  15. const that = this;
  16. await that.setData({ id: options.id || null })
  17. // 查询其他信息
  18. await that.searchOther();
  19. // 监听用户是否登录
  20. await that.watchLogin();
  21. },
  22. searchOther: async function () {
  23. const that = this;
  24. let arr;
  25. arr = await app.$get(`/dict`, { code: "schedule_status" });
  26. if (arr.errcode == '0' && arr.total > 0) that.setData({ statusList: arr.data[0].list });
  27. },
  28. // 监听用户是否登录
  29. watchLogin: async function () {
  30. const that = this;
  31. wx.getStorage({
  32. key: 'user',
  33. success: async res => {
  34. if (that.data.id) {
  35. const arr = await app.$get(`/eliminate/${that.data.id}`, {}, 'race');
  36. if (arr.errcode == '0') {
  37. arr.data.zhStatus = that.searchStatus(arr.data.status);
  38. if (arr.data.player_one == arr.data.winner) arr.data.winner_name = arr.data.player_one_name;
  39. else arr.data.winner_name = arr.data.player_two_name;
  40. that.setData({ info: arr.data })
  41. } else {
  42. wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 })
  43. }
  44. }
  45. },
  46. fail: async res => {
  47. wx.redirectTo({ url: '/pages/index/index' })
  48. }
  49. })
  50. },
  51. // 查询状态
  52. searchStatus: function (e) {
  53. const that = this;
  54. let data = that.data.statusList.find(i => i.value == e);
  55. if (data) return data.label;
  56. else return '暂无';
  57. },
  58. /**
  59. * 生命周期函数--监听页面初次渲染完成
  60. */
  61. onReady: function () { },
  62. /**
  63. * 生命周期函数--监听页面显示
  64. */
  65. onShow: function () {
  66. },
  67. /**
  68. * 页面上拉触底事件的处理函数
  69. */
  70. /**
  71. * 生命周期函数--监听页面隐藏
  72. */
  73. onHide: function () {
  74. },
  75. /**
  76. * 生命周期函数--监听页面卸载
  77. */
  78. onUnload: function () {
  79. },
  80. /**
  81. * 页面相关事件处理函数--监听用户下拉动作
  82. */
  83. onPullDownRefresh: function () {
  84. },
  85. /**
  86. * 用户点击右上角分享
  87. */
  88. onShareAppMessage: function () {
  89. }
  90. })