CommentAdd.vue 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <template>
  2. <el-dialog
  3. title="评论"
  4. :visible.sync="selfVisible"
  5. width="500px"
  6. @open="open"
  7. @close="close">
  8. <el-form ref="form" label-width="80px" :model="form" :rules="rules">
  9. <el-row>
  10. <el-col :span="24">
  11. <el-form-item label="评论" prop="content">
  12. <el-input type="textarea" v-model="form.content" placeholder="请输入评论"/>
  13. </el-form-item>
  14. </el-col>
  15. </el-row>
  16. </el-form>
  17. <template #footer>
  18. <el-button @click="selfVisible = false">取 消</el-button>
  19. <el-button type="primary" @click="save">确 定</el-button>
  20. </template>
  21. </el-dialog>
  22. </template>
  23. <script>
  24. import taskApi from '@/api/plat/task'
  25. export default {
  26. name: 'CommentAdd',
  27. props: {
  28. selfVisible: {
  29. type: Boolean,
  30. default: false
  31. },
  32. theTask: {
  33. type: Object,
  34. default: {}
  35. },
  36. doRefresh: {
  37. type: Function,
  38. default: undefined,
  39. },
  40. },
  41. watch: {
  42. selfVisible (val) {
  43. this.$emit('update:selfVisible', val)
  44. }
  45. },
  46. data() {
  47. return {
  48. // 新增数据表单
  49. form: {
  50. taskId: '',
  51. content: '',
  52. remark: ''
  53. },
  54. // 校验规则
  55. rules: {
  56. content: [
  57. { required: true, message: '评论不能为空', trigger: 'blur' },
  58. ],
  59. },
  60. }
  61. },
  62. methods: {
  63. // 打开弹窗
  64. open() {
  65. this.getData()
  66. if (this.$refs['form']) {
  67. this.$refs['form'].resetFields()
  68. }
  69. this.form.taskId = ''
  70. this.form.content = ''
  71. this.form.remark = ''
  72. },
  73. // 关闭弹窗
  74. close() {
  75. if (this.$refs['form']) {
  76. this.$refs['form'].resetFields()
  77. }
  78. this.selfVisible = false
  79. },
  80. // 保存数据
  81. save() {
  82. this.$refs['form'].validate(async (valid) => {
  83. if (valid) {
  84. this.selfVisible = false
  85. this.form.taskId = this.theTask.id
  86. const { msg } = await taskApi.createTaskComment(this.form)
  87. this.$baseMessage(msg, 'success', 'vab-hey-message-success')
  88. if (this.doRefresh) {
  89. this.doRefresh()
  90. }
  91. }
  92. })
  93. },
  94. }
  95. }
  96. </script>