courseForm.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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 :height="100" />
  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. classId: '',
  33. form: {
  34. content: '',
  35. fileId: [],
  36. },
  37. uploadUrl: API.uploadFile,
  38. uploadHeader: {
  39. Authorization: uni.getStorageSync('token')
  40. },
  41. rules: {
  42. content: [{
  43. required: true,
  44. message: '请输入评价内容',
  45. trigger: 'change'
  46. }],
  47. },
  48. }
  49. },
  50. onLoad(options) {
  51. this.classId = options.id
  52. },
  53. onReady() {
  54. this.$refs.form.setRules(this.rules);
  55. },
  56. methods: {
  57. // 文件上传成功回调
  58. uploadSuccess(res, index, lists, name) {
  59. this.form.fileId.push(res.data.id)
  60. this.$refs.uTips.show({
  61. title: '文件上传成功',
  62. type: 'success',
  63. })
  64. return true
  65. },
  66. // 文件上传失败回调
  67. uploadError(res, index, lists, name) {
  68. this.$refs.uTips.show({
  69. title: '文件上传失败',
  70. type: 'warning',
  71. })
  72. },
  73. // 移除文件回调
  74. uploadRemove(index, lists, name) {
  75. this.form.fileId.splice(index, 1)
  76. },
  77. // 提交表单
  78. submitForm() {
  79. this.$refs.form.validate(valid => {
  80. if (valid) {
  81. NET.request(API.submitGrowForm, {
  82. id: this.classId,
  83. ...this.form
  84. }, 'POST').then(res => {
  85. this.$refs.uTips.show({
  86. title: '填写成功',
  87. type: 'success',
  88. })
  89. setTimeout(() => {
  90. uni.navigateBack()
  91. }, 1000)
  92. }).catch(error => {
  93. this.$refs.uTips.show({
  94. title: error.message,
  95. type: 'warning',
  96. })
  97. })
  98. }
  99. });
  100. },
  101. },
  102. }
  103. </script>
  104. <style>
  105. page {
  106. width: 100%;
  107. height: 100%;
  108. position: relative;
  109. }
  110. </style>
  111. <style lang="scss" scoped>
  112. @import "@/static/css/themes.scss";
  113. .content {
  114. width: 100%;
  115. float: left;
  116. padding: 0 15px 60px 15px;
  117. box-sizing: border-box;
  118. }
  119. </style>