edit.hbs 1.7 KB

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