apply-leave.js 2.4 KB

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