sign.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. const app = getApp()
  2. Page({
  3. data: {
  4. frameStyle: { useTop: true, name: '报名', leftArrow: true, useBar: false },
  5. id: '',
  6. form: {},
  7. user: {},
  8. //状态
  9. statusList: []
  10. },
  11. // 跳转菜单
  12. back(e) {
  13. wx.navigateBack({ delta: 1 })
  14. },
  15. //提交
  16. onSubmit: async function (e) {
  17. const that = this;
  18. const form = that.data.form;
  19. const user = that.data.user;
  20. wx.showModal({
  21. title: '提示',
  22. content: '您是否确定报名?',
  23. async success(res) {
  24. if (res.confirm) {
  25. var student = { id: user.info.id, name: user.info.name }
  26. form.student.push(student);
  27. let arr = await app.$post(`/lessonPublic/${form._id}`, form);
  28. if (arr.errcode == '0') { wx.showToast({ title: `报名完成`, icon: 'success', duration: 2000 }); that.watchLogin(); }
  29. else wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 })
  30. } else if (res.cancel) { }
  31. }
  32. });
  33. },
  34. /**
  35. * 生命周期函数--监听页面加载
  36. */
  37. onLoad: async function (options) {
  38. const that = this;
  39. await that.setData({ id: options.id || null })
  40. // 查询其他信息
  41. await that.searchOther();
  42. // 监听用户是否登录
  43. await that.watchLogin();
  44. },
  45. searchOther: async function () {
  46. const that = this;
  47. let arr;
  48. // 状态
  49. arr = await app.$get(`/dict`, { code: 'lesson_status' });
  50. if (arr.errcode == '0' && arr.total > 0) that.setData({ statusList: arr.data[0].list });
  51. },
  52. // 监听用户是否登录
  53. watchLogin: async function () {
  54. const that = this;
  55. let statusList = that.data.statusList;
  56. wx.getStorage({
  57. key: 'user',
  58. success: async res => {
  59. that.setData({ user: res.data })
  60. if (that.data.id) {
  61. const arr = await app.$get(`/lessonPublic/${that.data.id}`);
  62. if (arr.errcode == '0') {
  63. let status = statusList.find(i => i.value == arr.data.status)
  64. if (status) arr.data.zhStatus = status.label;
  65. that.setData({ form: arr.data })
  66. } else {
  67. wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 })
  68. }
  69. }
  70. },
  71. fail: async res => {
  72. wx.redirectTo({ url: '/pages/index/index' })
  73. }
  74. })
  75. },
  76. /**
  77. * 生命周期函数--监听页面初次渲染完成
  78. */
  79. onReady: function () { },
  80. /**
  81. * 生命周期函数--监听页面显示
  82. */
  83. onShow: function () {
  84. },
  85. /**
  86. * 页面上拉触底事件的处理函数
  87. */
  88. /**
  89. * 生命周期函数--监听页面隐藏
  90. */
  91. onHide: function () {
  92. },
  93. /**
  94. * 生命周期函数--监听页面卸载
  95. */
  96. onUnload: function () {
  97. },
  98. /**
  99. * 页面相关事件处理函数--监听用户下拉动作
  100. */
  101. onPullDownRefresh: function () {
  102. },
  103. /**
  104. * 用户点击右上角分享
  105. */
  106. onShareAppMessage: function () {
  107. }
  108. })