courseForm.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <template>
  2. <view class="content">
  3. <u-form :model="form" ref="form" label-width="140">
  4. <u-form-item label="记录内容" prop="content" required>
  5. <u-input v-model="form.content" placeholder="请输入记录内容" type="textarea" auto-height />
  6. </u-form-item>
  7. <u-form-item label="上传附件" label-position="top">
  8. <u-upload max-count="5" :multiple="false" :action="uploadUrl" :header="uploadHeader" @on-success="uploadSuccess"
  9. @on-error="uploadError" @on-remove="uploadRemove"></u-upload>
  10. </u-form-item>
  11. </u-form>
  12. <view class="handle-fix-box">
  13. <u-button type="warning" shape="circle" :ripple="true" :custom-style="customStyle" @click="submitForm()">提交</u-button>
  14. </view>
  15. <u-top-tips ref="uTips"></u-top-tips>
  16. </view>
  17. </template>
  18. <script>
  19. import {
  20. mapGetters
  21. } from 'vuex'
  22. const NET = require('@/utils/request')
  23. const API = require('@/config/api')
  24. export default {
  25. computed: {
  26. ...mapGetters([
  27. 'customStyle',
  28. ])
  29. },
  30. data() {
  31. return {
  32. id: '',
  33. classId: '',
  34. form: {
  35. content: '',
  36. fileId: [],
  37. },
  38. uploadUrl: API.uploadFile,
  39. uploadHeader: {
  40. Authorization: uni.getStorageSync('token')
  41. },
  42. rules: {
  43. content: [{
  44. required: true,
  45. message: '请输入评价内容',
  46. trigger: 'change'
  47. }],
  48. },
  49. }
  50. },
  51. onLoad(options) {
  52. this.id = options.id
  53. this.classId = options.classId
  54. },
  55. onReady() {
  56. this.$refs.form.setRules(this.rules);
  57. },
  58. methods: {
  59. // 文件上传成功回调
  60. uploadSuccess(res, index, lists, name) {
  61. this.form.fileId.push(res.data.id)
  62. this.$refs.uTips.show({
  63. title: '文件上传成功',
  64. type: 'success',
  65. })
  66. return true
  67. },
  68. // 文件上传失败回调
  69. uploadError(res, index, lists, name) {
  70. this.$refs.uTips.show({
  71. title: '文件上传失败',
  72. type: 'warning',
  73. })
  74. },
  75. // 移除文件回调
  76. uploadRemove(index, lists, name) {
  77. this.form.fileId.splice(index, 1)
  78. },
  79. // 提交表单
  80. submitForm() {
  81. this.$refs.form.validate(valid => {
  82. if (valid) {
  83. NET.request(API.submitCourseForm, {
  84. studentId: this.id,
  85. id: this.classId,
  86. ...this.form
  87. }, 'POST').then(res => {
  88. this.$refs.uTips.show({
  89. title: '提交成功',
  90. type: 'success',
  91. })
  92. setTimeout(() => {
  93. uni.navigateBack()
  94. }, 1000)
  95. }).catch(error => {
  96. this.$refs.uTips.show({
  97. title: error.message,
  98. type: 'warning',
  99. })
  100. })
  101. }
  102. });
  103. },
  104. },
  105. }
  106. </script>
  107. <style>
  108. page {
  109. width: 100%;
  110. height: 100%;
  111. position: relative;
  112. }
  113. </style>
  114. <style lang="scss" scoped>
  115. @import "@/static/css/themes.scss";
  116. .content {
  117. width: 100%;
  118. float: left;
  119. padding: 0 15px 60px 15px;
  120. box-sizing: border-box;
  121. }
  122. </style>