statusadd.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. const app = getApp()
  2. import WxValidate from '../../../utils/wxValidate';
  3. Page({
  4. data: {
  5. frameStyle: { useTop: true, name: '信息维护', leftArrow: true, useBar: false },
  6. form: { img_url: [] },
  7. // 课程信息
  8. lesson_id: '',
  9. // 学校信息
  10. schoolInfo: {},
  11. // 学生列表
  12. studentList: [],
  13. },
  14. initValidate() {
  15. const rules = { student_id: { required: true }, money: { required: true }, img_url: { required: true } }
  16. // 验证字段的提示信息,若不传则调用默认的信息
  17. const messages = { student_id: { required: '请选择学生' }, money: { required: '课程费用' }, img_url: { required: '证据图片' } };
  18. this.WxValidate = new WxValidate(rules, messages)
  19. },
  20. // 返回
  21. back: function () {
  22. wx.navigateBack({ delta: 1 })
  23. },
  24. // 选择学生
  25. stuChange: function (e) {
  26. const that = this;
  27. let data = that.data.studentList[e.detail.value];
  28. if (data) {
  29. that.setData({ 'form.student_id': data.student_id })
  30. that.setData({ 'form.student_id_name': data.student_id_name })
  31. }
  32. },
  33. imgUpl: function (e) {
  34. const that = this;
  35. let data = that.data.form.img_url;
  36. data.push(e.detail)
  37. that.setData({ 'form.img_url': data })
  38. },
  39. // 删除图片
  40. imgDel: function (e) {
  41. const that = this;
  42. let list = that.data.form.img_url;
  43. let arr = list.filter((i, index) => index != e.detail.index)
  44. that.setData({ 'form.img_url': arr })
  45. },
  46. //提交
  47. onSubmit: async function (e) {
  48. const that = this;
  49. const params = e.detail.value;
  50. const form = that.data.form;
  51. form.img_url = form.img_url;
  52. if (!this.WxValidate.checkForm(params)) {
  53. const error = this.WxValidate.errorList[0];
  54. wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
  55. return false
  56. } else {
  57. console.log(params);
  58. //  config: { type: Object, required: false, zh: '设置' }, // 打折方式 discount_type:fixed 固定;subtract 减; discount折 ;number
  59. }
  60. },
  61. /**
  62. * 生命周期函数--监听页面加载
  63. */
  64. onLoad: async function (options) {
  65. const that = this;
  66. that.setData({ lesson_id: options.id || '' })
  67. //验证规则函数
  68. that.initValidate();
  69. // 监听用户是否登录
  70. await that.watchLogin();
  71. },
  72. // 监听用户是否登录
  73. watchLogin: async function () {
  74. const that = this;
  75. wx.getStorage({
  76. key: 'user',
  77. success: async res => {
  78. let data = res.data;
  79. let arr;
  80. // 学员与学校的关系
  81. arr = await app.$get(`/rss`);
  82. if (arr.errcode == '0') that.setData({ studentList: arr.data });
  83. // 教练与学校的关系
  84. arr = await app.$get(`/rcs`, { coach_id: data.info.id });
  85. if (arr.errcode == '0' && arr.total > 0) that.setData({ schoolInfo: arr.data[0] });
  86. let form = { school_id: that.data.schoolInfo.school_id, lesson_id: that.data.lesson_id, coach_id: data.info._id, img_url: [] };
  87. that.setData({ form })
  88. },
  89. fail: async res => {
  90. wx.redirectTo({ url: '/pages/index/index' })
  91. }
  92. })
  93. },
  94. /**
  95. * 生命周期函数--监听页面初次渲染完成
  96. */
  97. onReady: function () {
  98. },
  99. /**
  100. * 生命周期函数--监听页面显示
  101. */
  102. onShow: function () {
  103. },
  104. /**
  105. * 生命周期函数--监听页面隐藏
  106. */
  107. onHide: function () {
  108. },
  109. /**
  110. * 生命周期函数--监听页面卸载
  111. */
  112. onUnload: function () {
  113. },
  114. /**
  115. * 页面相关事件处理函数--监听用户下拉动作
  116. */
  117. onPullDownRefresh: function () {
  118. },
  119. /**
  120. * 页面上拉触底事件的处理函数
  121. */
  122. onReachBottom: function () {
  123. },
  124. /**
  125. * 用户点击右上角分享
  126. */
  127. onShareAppMessage: function () {
  128. }
  129. })