evaluateForm.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <template>
  2. <view class="content">
  3. <u-form :model="form" ref="form" label-width="140">
  4. <u-form-item label="评价星级" prop="level" required>
  5. <u-rate :count="5" v-model="form.level" :active-color="mainColor"></u-rate>
  6. </u-form-item>
  7. <u-form-item label="评价内容" prop="estimateContent" required>
  8. <u-input v-model="form.estimateContent" placeholder="请输入评价内容" type="textarea" auto-height :height="100" />
  9. </u-form-item>
  10. </u-form>
  11. <view class="handle-fix-box">
  12. <u-button type="warning" shape="circle" :ripple="true" :custom-style="customStyle" @click="submitForm()">提交</u-button>
  13. </view>
  14. <u-top-tips ref="uTips"></u-top-tips>
  15. </view>
  16. </template>
  17. <script>
  18. import {
  19. mapGetters
  20. } from 'vuex'
  21. const NET = require('@/utils/request')
  22. const API = require('@/config/api')
  23. export default {
  24. computed: {
  25. ...mapGetters([
  26. 'mainColor',
  27. 'customStyle',
  28. ])
  29. },
  30. data() {
  31. return {
  32. classId: '',
  33. form: {
  34. level: 0,
  35. estimateContent: '',
  36. },
  37. rules: {
  38. level: [{
  39. required: true,
  40. type: 'number',
  41. message: '请选择评价星级',
  42. trigger: 'change'
  43. }],
  44. estimateContent: [{
  45. required: true,
  46. message: '请输入评价内容',
  47. trigger: 'change'
  48. }],
  49. },
  50. }
  51. },
  52. onLoad(options) {
  53. this.classId = options.id
  54. },
  55. onReady() {
  56. this.$refs.form.setRules(this.rules);
  57. },
  58. methods: {
  59. // 提交表单
  60. submitForm() {
  61. this.$refs.form.validate(valid => {
  62. if (valid) {
  63. NET.request(API.submitEvaluateForm, {
  64. classId: this.classId,
  65. ...this.form
  66. }, 'POST').then(res => {
  67. this.$refs.uTips.show({
  68. title: '评价成功',
  69. type: 'success',
  70. })
  71. setTimeout(() => {
  72. uni.navigateBack()
  73. }, 1000)
  74. }).catch(error => {
  75. this.$refs.uTips.show({
  76. title: error.message,
  77. type: 'warning',
  78. })
  79. })
  80. }
  81. });
  82. },
  83. },
  84. }
  85. </script>
  86. <style>
  87. page {
  88. width: 100%;
  89. height: 100%;
  90. position: relative;
  91. }
  92. </style>
  93. <style lang="scss" scoped>
  94. @import "@/static/css/themes.scss";
  95. .content {
  96. width: 100%;
  97. float: left;
  98. padding: 0 15px 60px 15px;
  99. box-sizing: border-box;
  100. }
  101. </style>