rate.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. var app = getApp()
  2. var api = require('../../utils/api.js');
  3. Page({
  4. data: {
  5. titles: [],
  6. course_name: '',
  7. teacher: '',
  8. teachers: [],
  9. is_new: true
  10. },
  11. onLoad: function (options) {
  12. let that = this;
  13. that.setData({
  14. course_name: options.course_name,
  15. teacher: options.teacher
  16. })
  17. wx.request({
  18. url: api.getRemarkTitlesUrl,
  19. data: {
  20. id: wx.getStorageSync('pt_student').id
  21. },
  22. method: 'GET',
  23. success: res => {
  24. // console.log(res.data)
  25. that.setData({
  26. is_new: res.data.is_new,
  27. titles: res.data.titles,
  28. teachers: res.data.teachers
  29. })
  30. }
  31. })
  32. },
  33. formSubmit: function (e) {
  34. let data = e.detail.value;
  35. for(var i in data) {
  36. if(data[i] === null) {
  37. wx.showModal({
  38. title: '评价失败',
  39. content: '评分不能为空',
  40. })
  41. return false;
  42. }
  43. data[i] = parseInt(data[i])
  44. if (!(data[i] >= 0 && data[i] <= 10)) {
  45. wx.showModal({
  46. title: '评价失败',
  47. content: '评分只能为0到10',
  48. })
  49. return false;
  50. }
  51. }
  52. data.student_id = wx.getStorageSync('pt_student').id
  53. wx.request({
  54. url: api.remarkTeacherUrl,
  55. method: 'GET',
  56. data: data,
  57. success: res => {
  58. if (res.data.status == 'success') {
  59. wx.showModal({
  60. title: '评价成功',
  61. content: '感谢评价',
  62. success: function (res) {
  63. wx.switchTab({
  64. url: '/pages/userinfo/userinfo',
  65. })
  66. }
  67. })
  68. } else {
  69. wx.showToast({
  70. title: res.data.info,
  71. icon: 'none',
  72. duration: 800
  73. })
  74. }
  75. }
  76. })
  77. },
  78. onSubmit: function() {
  79. wx.navigateTo({url: '/pages/rate-review/rate-review'})
  80. }
  81. })