OrgModal.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <template>
  2. <a-modal
  3. title="操作"
  4. :width="600"
  5. :visible="visible"
  6. :confirmLoading="confirmLoading"
  7. @ok="handleOk"
  8. @cancel="handleCancel"
  9. >
  10. <a-spin :spinning="confirmLoading">
  11. <a-form :form="form">
  12. <a-form-item
  13. label="父级ID"
  14. >
  15. <a-input v-decorator="['parentId', {}]" disabled />
  16. </a-form-item>
  17. <a-form-item
  18. label="机构名称"
  19. >
  20. <a-input v-decorator="['orgName', {}]" />
  21. </a-form-item>
  22. </a-form>
  23. </a-spin>
  24. </a-modal>
  25. </template>
  26. <script>
  27. export default {
  28. name: 'OrgModal',
  29. data () {
  30. return {
  31. labelCol: {
  32. xs: { span: 24 },
  33. sm: { span: 5 }
  34. },
  35. wrapperCol: {
  36. xs: { span: 24 },
  37. sm: { span: 16 }
  38. },
  39. visible: false,
  40. confirmLoading: false,
  41. mdl: {}
  42. }
  43. },
  44. beforeCreate () {
  45. this.form = this.$form.createForm(this)
  46. console.log('form::', this.form)
  47. },
  48. created () {
  49. },
  50. methods: {
  51. add (id) {
  52. this.edit({ parentId: id })
  53. },
  54. edit (record) {
  55. this.mdl = Object.assign({}, record)
  56. this.visible = true
  57. this.$nextTick(() => {
  58. this.form.setFieldsValue({ ...record })
  59. })
  60. },
  61. close () {
  62. this.$emit('close')
  63. this.visible = false
  64. },
  65. handleOk () {
  66. const _this = this
  67. // 触发表单验证
  68. this.form.validateFields((err, values) => {
  69. // 验证表单没错误
  70. if (!err) {
  71. console.log('form values', values)
  72. _this.confirmLoading = true
  73. // 模拟后端请求 2000 毫秒延迟
  74. new Promise((resolve) => {
  75. setTimeout(() => resolve(), 2000)
  76. }).then(() => {
  77. // Do something
  78. _this.$message.success('保存成功')
  79. _this.$emit('ok')
  80. }).catch(() => {
  81. // Do something
  82. }).finally(() => {
  83. _this.confirmLoading = false
  84. _this.close()
  85. })
  86. }
  87. })
  88. },
  89. handleCancel () {
  90. this.close()
  91. }
  92. }
  93. }
  94. </script>