apply-leave.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. var app = getApp()
  2. var api = require('../../utils/api.js');
  3. Page({
  4. data: {
  5. date: '',
  6. typeEnum: [
  7. '短假', '长假'
  8. ],
  9. selectedType: 0
  10. },
  11. onLoad: function () {
  12. let date = this.getNowFormatDate();
  13. this.setData({
  14. date: date
  15. })
  16. },
  17. getNowFormatDate() {
  18. var date = new Date();
  19. var seperator1 = "-";
  20. var year = date.getFullYear();
  21. var month = date.getMonth() + 1;
  22. var strDate = date.getDate();
  23. if(month >= 1 && month <= 9) {
  24. month = "0" + month;
  25. }
  26. if (strDate >= 0 && strDate <= 9) {
  27. strDate = "0" + strDate;
  28. }
  29. var currentdate = year + seperator1 + month + seperator1 + strDate;
  30. return currentdate;
  31. },
  32. bindDateChange: function(e) {
  33. console.log('picker发送选择改变,携带值为', e.detail.value)
  34. this.setData({
  35. date: e.detail.value
  36. })
  37. },
  38. formSubmit: function (e) {
  39. let value = e.detail.value
  40. value.days = parseInt(value.days)
  41. if(value.type == 0) {
  42. if (value.days <= 0 || value.days > 7) {
  43. wx.showModal({
  44. title: '请假失败',
  45. content: '短假可请天数为1到7天',
  46. })
  47. return false;
  48. }
  49. } else {
  50. if (!(value.days >= 7 && value.days <= 60)) {
  51. wx.showModal({
  52. title: '请假失败',
  53. content: '长假可请天数为7到60天',
  54. })
  55. return false;
  56. }
  57. }
  58. wx.request({
  59. url: api.applyLeaveUrl,
  60. method: 'GET',
  61. data: {
  62. 'student_id': wx.getStorageSync('pt_student').id,
  63. 'date': value.date,
  64. 'type': value.type == 0 ? '1' : '2',
  65. 'days': value.days,
  66. 'remark': value.remark
  67. },
  68. success: res => {
  69. if (res.data.status == 'success') {
  70. wx.showModal({
  71. title: '请假成功',
  72. content: '请假成功',
  73. success: function (res) {
  74. wx.switchTab({
  75. url: '/pages/userinfo/userinfo',
  76. })
  77. }
  78. })
  79. } else {
  80. wx.showToast({
  81. title: res.data.info,
  82. icon: 'none',
  83. duration: 800
  84. })
  85. }
  86. }
  87. })
  88. }
  89. })