tpStudentadd.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. const app = getApp()
  2. import WxValidate from '../../../utils/wxValidate'
  3. import QRCode from '../../../utils/weapp-qrcode.js';
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. frameStyle: { useTop: true, name: '信息管理', leftArrow: true, useBar: false },
  10. user: {},
  11. lesson_id: '',
  12. lessonInfo: {},
  13. id: '',
  14. form: { file: [] },
  15. studentlist: [],
  16. payUrl: '',
  17. // dialog弹框
  18. dialog: { title: '二维码支付', show: false, type: '1' },
  19. payUrl: ''
  20. },
  21. initValidate() {
  22. const rules = { name: { required: true }, phone: { required: true }, file: { required: true } }
  23. // 验证字段的提示信息,若不传则调用默认的信息
  24. const messages = { name: { required: '学员姓名', }, phone: { required: '联系方式', }, file: { required: '图片', } };
  25. this.WxValidate = new WxValidate(rules, messages)
  26. },
  27. // 跳转菜单
  28. back(e) {
  29. wx.navigateBack({ delta: 1 })
  30. },
  31. // 选择学员
  32. stuChange(e) {
  33. const that = this;
  34. let data = that.data.studentlist[e.detail.value];
  35. if (data) that.setData({ 'form.student_id': data.student_id, 'form.name': data.student_id_name, 'form.phone': data.student_id_phone, })
  36. },
  37. // 上传照片
  38. imgUpl: function (e) {
  39. const that = this;
  40. let data = that.data.form.file;
  41. data.push(e.detail)
  42. that.setData({ 'form.file': data })
  43. },
  44. // 删除图片
  45. imgDel: function (e) {
  46. const that = this;
  47. let list = that.data.form.file;
  48. let arr = list.filter((i, index) => index != e.detail.index)
  49. that.setData({ 'form.file': arr })
  50. },
  51. // 提交登录
  52. onSubmit: async function (e) {
  53. const that = this;
  54. const params = e.detail.value;
  55. const form = that.data.form;
  56. params.file = form.file;
  57. if (!this.WxValidate.checkForm(params)) {
  58. const error = this.WxValidate.errorList[0];
  59. wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
  60. return false
  61. } else {
  62. let res = await app.$post(`/tempLessonApply`, params);
  63. if (res.errcode == '0') {
  64. let data = JSON.parse(res.data);
  65. that.createPayUrl(data.code_url);
  66. that.setData({ dialog: { title: '二维码支付', show: true, type: '1' } })
  67. } else {
  68. wx.showToast({ title: res.errmsg, icon: 'none' })
  69. }
  70. }
  71. },
  72. createPayUrl(e) {
  73. // 生成二维码
  74. const that = this;
  75. const url = `${e}`;
  76. var qrcode = new QRCode(`myQrcode`, {
  77. text: url,
  78. width: 110,
  79. height: 110,
  80. padding: 3,
  81. colorDark: "#000000",
  82. colorLight: "#ffffff",
  83. correctLevel: QRCode.CorrectLevel.L,
  84. });
  85. },
  86. // 关闭弹框
  87. toClose: function () {
  88. const that = this;
  89. that.setData({ dialog: { title: '二维码支付', show: false, type: '1' } })
  90. },
  91. // 付款成功
  92. paySuccess() {
  93. const that = this;
  94. that.setData({ form: {} })
  95. that.toClose();
  96. that.back();
  97. },
  98. /**
  99. * 生命周期函数--监听页面加载
  100. */
  101. onLoad: function (options) {
  102. const that = this;
  103. that.setData({ lesson_id: options.lesson_id || '63563bbd8018a39220eca774', id: options.id || '' });
  104. //验证规则函数
  105. that.initValidate();
  106. // 监听用户是否登录
  107. that.watchLogin();
  108. },
  109. // 监听用户是否登录
  110. watchLogin: async function () {
  111. const that = this;
  112. wx.getStorage({
  113. key: 'user',
  114. success: async res => {
  115. that.setData({ user: res.data });
  116. await that.searchLesson();
  117. await that.search();
  118. await that.searchStu();
  119. },
  120. fail: res => {
  121. wx.redirectTo({ url: '/pages/index/index', })
  122. }
  123. })
  124. },
  125. async searchLesson() {
  126. const that = this;
  127. let lesson_id = that.data.lesson_id;
  128. let res = await app.$get(`/lesson/${lesson_id}`);
  129. if (res.errcode == '0') {
  130. that.setData({ lessonInfo: res.data });
  131. }
  132. else { wx.showToast({ title: res.errmsg, icon: 'none' }) }
  133. },
  134. async search() {
  135. const that = this;
  136. let lessonInfo = that.data.lessonInfo;
  137. let user = that.data.user;
  138. let id = that.data.id;
  139. let form = { school_id: lessonInfo.school_id, coach_id: user.info.id, lesson_id: lessonInfo.id, money: lessonInfo.money, file: [] };
  140. let res;
  141. if (id) {
  142. res = await app.$get(`/tempLessonApply/${id}`);
  143. if (res.errcode == '0') form = res.data
  144. else { wx.showToast({ title: res.errmsg, icon: 'none' }) }
  145. }
  146. that.setData({ form })
  147. },
  148. async searchStu() {
  149. const that = this;
  150. let lessonInfo = that.data.lessonInfo;
  151. let res = await app.$get(`/rss`, { school_id: lessonInfo.school_id });
  152. if (res.errcode == '0') {
  153. that.setData({ studentlist: res.data })
  154. } else { wx.showToast({ title: res.errmsg, icon: 'none' }) }
  155. },
  156. /**
  157. * 生命周期函数--监听页面初次渲染完成
  158. */
  159. onReady: function () {
  160. },
  161. /**
  162. * 生命周期函数--监听页面显示
  163. */
  164. onShow: function () {
  165. },
  166. /**
  167. * 生命周期函数--监听页面隐藏
  168. */
  169. onHide: function () {
  170. },
  171. /**
  172. * 生命周期函数--监听页面卸载
  173. */
  174. onUnload: function () {
  175. },
  176. /**
  177. * 页面相关事件处理函数--监听用户下拉动作
  178. */
  179. onPullDownRefresh: function () {
  180. },
  181. /**
  182. * 页面上拉触底事件的处理函数
  183. */
  184. onReachBottom: function () {
  185. },
  186. /**
  187. * 用户点击右上角分享
  188. */
  189. onShareAppMessage: function () {
  190. }
  191. })