leaveForm.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <template>
  2. <view class="content">
  3. <u-form :model="form" ref="form" label-width="140">
  4. <u-form-item label="请假时间" prop="leaveTime" required>
  5. <u-input v-model="form.leaveTime" placeholder="请选择请假时间" :select-open="leaveTimeShow" type="select" @click="leaveTimeShow = true" />
  6. </u-form-item>
  7. <u-form-item label="请假理由" prop="leaveReason" required>
  8. <u-input v-model="form.leaveReason" placeholder="请输入请假理由" type="textarea" auto-height :height="100" />
  9. </u-form-item>
  10. </u-form>
  11. <u-calendar v-model="leaveTimeShow" mode="date" :active-bg-color="mainColor" btn-type="error" availableText="有课"
  12. :available="availableList" activeText="已请假" :activeList="activeList" @change="setLeaveTime" max-date="2300-12-31"></u-calendar>
  13. <view class="handle-fix-box">
  14. <u-button type="warning" shape="circle" :ripple="true" :custom-style="customStyle" @click="submitForm()">提交</u-button>
  15. </view>
  16. <u-top-tips ref="uTips"></u-top-tips>
  17. </view>
  18. </template>
  19. <script>
  20. import {
  21. mapGetters
  22. } from 'vuex'
  23. const NET = require('@/utils/request')
  24. const API = require('@/config/api')
  25. export default {
  26. computed: {
  27. ...mapGetters([
  28. 'mainColor',
  29. 'customStyle',
  30. ])
  31. },
  32. data() {
  33. return {
  34. classId: '',
  35. studentId: '',
  36. form: {
  37. leaveTime: '',
  38. leaveReason: '',
  39. },
  40. rules: {
  41. leaveTime: [{
  42. required: true,
  43. message: '请选择请假时间',
  44. trigger: 'change'
  45. }],
  46. leaveReason: [{
  47. required: true,
  48. message: '请输入请假理由',
  49. trigger: 'change'
  50. }],
  51. },
  52. leaveTimeShow: false,
  53. availableList: [],
  54. activeList: [],
  55. }
  56. },
  57. onLoad(options) {
  58. this.classId = options.id
  59. this.studentId = options.studentId
  60. NET.request(API.getLeaveList, {
  61. id: this.classId
  62. }, 'POST').then(res => {
  63. this.availableList = res.data.filter(site => site.type == 0).map(site => {
  64. return site.lastDate
  65. })
  66. this.activeList = res.data.filter(site => site.type == 1).map(site => {
  67. return site.lastDate
  68. })
  69. }).catch(error => {
  70. this.$refs.uTips.show({
  71. title: error.message,
  72. type: 'warning',
  73. })
  74. })
  75. },
  76. onReady() {
  77. this.$refs.form.setRules(this.rules);
  78. },
  79. methods: {
  80. // 设置请假日期
  81. setLeaveTime(object) {
  82. let date = object.year + '-' + object.month + '-' + object.day
  83. if (this.availableList.filter(site => site == date).length) {
  84. this.form.leaveTime = date
  85. } else {
  86. this.form.leaveTime = ''
  87. this.$refs.uTips.show({
  88. title: '请选择可用日期',
  89. type: 'error',
  90. })
  91. }
  92. },
  93. // 提交表单
  94. submitForm() {
  95. this.$refs.form.validate(valid => {
  96. if (valid) {
  97. NET.request(API.submitLevelForm, {
  98. classId: this.classId,
  99. studentId: this.studentId,
  100. ...this.form
  101. }, 'POST').then(res => {
  102. this.$refs.uTips.show({
  103. title: '请假成功',
  104. type: 'success',
  105. })
  106. setTimeout(() => {
  107. uni.navigateBack()
  108. }, 1000)
  109. }).catch(error => {
  110. this.$refs.uTips.show({
  111. title: error.message,
  112. type: 'warning',
  113. })
  114. })
  115. }
  116. });
  117. },
  118. },
  119. }
  120. </script>
  121. <style>
  122. page {
  123. width: 100%;
  124. height: 100%;
  125. position: relative;
  126. }
  127. </style>
  128. <style lang="scss" scoped>
  129. @import "@/static/css/themes.scss";
  130. .content {
  131. width: 100%;
  132. float: left;
  133. padding: 0 15px 60px 15px;
  134. box-sizing: border-box;
  135. }
  136. </style>