CreateForm.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <template>
  2. <div>
  3. <a-drawer
  4. :title="title"
  5. placement="right"
  6. :closable="true"
  7. @close="onClose"
  8. :visible="drawerVisible"
  9. :width="950">
  10. <a-form @submit="handleSubmit" :form="commentForm" class="form">
  11. <a-row class="form-row" :gutter="16">
  12. <a-col :lg="24" :md="12" :sm="24">
  13. <a-form-item label="回复内容">
  14. <a-input
  15. placeholder="请输入回复内容"
  16. v-decorator="['content', { rules: [{ required: true, message: '请输入回复内容', whitespace: true }] }]"
  17. />
  18. </a-form-item>
  19. </a-col>
  20. </a-row>
  21. <div
  22. :style="{
  23. position: 'absolute',
  24. left: 0,
  25. bottom: 0,
  26. width: '100%',
  27. borderTop: '1px solid #e9e9e9',
  28. padding: '10px 16px',
  29. background: '#fff',
  30. textAlign: 'right',
  31. zIndex: '10'
  32. }"
  33. >
  34. <a-button :style="{marginRight: '8px'}" @click="onClose">取消</a-button>
  35. <a-button type="primary" @click="handleSubmit">提交</a-button>
  36. </div>
  37. </a-form>
  38. </a-drawer>
  39. </div>
  40. </template>
  41. <script>
  42. import {
  43. replyComment
  44. } from '@/api/comment'
  45. import { fetchTagsList } from '@/api/tags'
  46. export default {
  47. name: 'CreateCommentForm',
  48. props: {
  49. formType: {
  50. type: String,
  51. default: 'create'
  52. },
  53. visible: {
  54. type: Boolean
  55. }
  56. },
  57. data () {
  58. return {
  59. dynamicTags: [],
  60. tagsSize: 5,
  61. id: null,
  62. drawerVisible: false,
  63. commentForm: this.$form.createForm(this, { name: 'create_comment' })
  64. }
  65. },
  66. watch: {
  67. visible (val) {
  68. this.drawerVisible = val
  69. },
  70. formType (val) {
  71. this.title = (val === 'create' ? '新增评论' : '更新评论')
  72. }
  73. },
  74. beforeCreate () {
  75. },
  76. created () {
  77. this.getTagsList()
  78. },
  79. methods: {
  80. handleSubmit (e) {
  81. e.preventDefault()
  82. this.commentForm.validateFieldsAndScroll((err, values) => {
  83. if (!err) {
  84. console.log('Received values of form: ', values)
  85. const createParams = { ...values }
  86. const arr = []
  87. createParams['parentId'] = this.id
  88. replyComment(createParams)
  89. .then(res => {
  90. this.$emit('refreshTable')
  91. })
  92. .catch(err => {console.log(err)})
  93. }
  94. this.resetForm()
  95. this.drawerVisible = false
  96. this.$emit('resetData', false)
  97. })
  98. },
  99. handleEdit (record) {
  100. this.id = record.id
  101. this.drawerVisible = true
  102. },
  103. onClose () {
  104. this.resetForm()
  105. this.drawerVisible = false
  106. this.$emit('resetData', false)
  107. },
  108. resetForm () {
  109. this.commentForm.resetFields()
  110. },
  111. getTagsList () {
  112. fetchTagsList().then(response => {
  113. this.dynamicTags = response.models
  114. })
  115. },
  116. handleSelectChange (value) {
  117. console.log(`Selected: ${value}`)
  118. }
  119. }
  120. }
  121. </script>
  122. <style>
  123. .edit-input {
  124. padding-right: 100px;
  125. }
  126. .cancel-btn {
  127. position: absolute;
  128. right: 15px;
  129. top: 10px;
  130. }
  131. .ant-upload-select-picture-card i {
  132. font-size: 32px;
  133. color: #999;
  134. }
  135. .ant-upload-select-picture-card .ant-upload-text {
  136. margin-top: 8px;
  137. color: #666;
  138. }
  139. </style>