sign.js 3.3 KB

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