edit.hbs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <template>
  2. <el-dialog
  3. append-to-body
  4. :title="title"
  5. :visible.sync="dialogFormVisible"
  6. width="500px"
  7. @close="close"
  8. >
  9. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  10. <el-form-item label="标题" prop="title">
  11. <el-input v-model="form.title" />
  12. </el-form-item>
  13. </el-form>
  14. <div slot="footer" class="dialog-footer">
  15. <el-button @click="close">取 消</el-button>
  16. <el-button type="primary" @click="save">确 定</el-button>
  17. </div>
  18. </el-dialog>
  19. </template>
  20. <script>
  21. import {{ camelCase name }}Api from '@/api/{{moduleName}}/{{ camelCase name }}'
  22. export default {
  23. name: '{{ properCase name }}Edit',
  24. data() {
  25. return {
  26. form: {
  27. title: '',
  28. },
  29. rules: {
  30. title: [{ required: true, trigger: 'blur', message: '请输入标题' }],
  31. },
  32. title: '',
  33. dialogFormVisible: false,
  34. }
  35. },
  36. created() {},
  37. methods: {
  38. showEdit(row) {
  39. if (!row) {
  40. this.title = '添加'
  41. } else {
  42. this.title = '编辑'
  43. this.form = Object.assign({}, row)
  44. }
  45. this.dialogFormVisible = true
  46. },
  47. close() {
  48. this.$refs['form'].resetFields()
  49. this.form = this.$options.data().form
  50. this.dialogFormVisible = false
  51. },
  52. save() {
  53. this.$refs['form'].validate(async (valid) => {
  54. if (valid) {
  55. const { msg } = await {{ camelCase name }}Api.doEdit(this.form)
  56. this.$baseMessage(msg, 'success')
  57. this.$emit('fetch-data')
  58. this.close()
  59. } else {
  60. return false
  61. }
  62. })
  63. },
  64. },
  65. }
  66. </script>