org-form.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <template>
  2. <div>
  3. <el-dialog v-model="state.showDialog" destroy-on-close :title="title" draggable width="600px">
  4. <el-form :model="form" ref="formRef" size="default" label-width="80px">
  5. <el-row :gutter="35">
  6. <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
  7. <el-form-item label="上级部门">
  8. <el-tree-select
  9. v-model="form.parentId"
  10. :data="orgTreeData"
  11. node-key="id"
  12. :props="{ label: 'name' }"
  13. check-strictly
  14. default-expand-all
  15. render-after-expand
  16. fit-input-width
  17. clearable
  18. class="w100"
  19. />
  20. </el-form-item>
  21. </el-col>
  22. <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
  23. <el-form-item label="部门名称" prop="name" :rules="[{ required: true, message: '请输入部门名称', trigger: ['blur', 'change'] }]">
  24. <el-input v-model="form.name" clearable />
  25. </el-form-item>
  26. </el-col>
  27. <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
  28. <el-form-item label="部门编码" prop="code">
  29. <el-input v-model="form.code" clearable />
  30. </el-form-item>
  31. </el-col>
  32. <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
  33. <el-form-item label="部门值" prop="value">
  34. <el-input v-model="form.value" clearable />
  35. </el-form-item>
  36. </el-col>
  37. <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
  38. <el-form-item label="排序">
  39. <el-input-number v-model="form.sort" />
  40. </el-form-item>
  41. </el-col>
  42. <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
  43. <el-form-item label="启用">
  44. <el-switch v-model="form.enabled" />
  45. </el-form-item>
  46. </el-col>
  47. <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
  48. <el-form-item label="说明">
  49. <el-input v-model="form.description" clearable type="textarea" />
  50. </el-form-item>
  51. </el-col>
  52. </el-row>
  53. </el-form>
  54. <template #footer>
  55. <span class="dialog-footer">
  56. <el-button @click="onCancel" size="default">取 消</el-button>
  57. <el-button type="primary" @click="onSure" size="default" :loading="state.sureLoading">确 定</el-button>
  58. </span>
  59. </template>
  60. </el-dialog>
  61. </div>
  62. </template>
  63. <script lang="ts" setup name="admin/org/form">
  64. import { reactive, toRefs, ref, PropType } from 'vue'
  65. import { OrgListOutput, OrgUpdateInput } from '/@/api/admin/data-contracts'
  66. import { OrgApi } from '/@/api/admin/Org'
  67. import eventBus from '/@/utils/mitt'
  68. defineProps({
  69. title: {
  70. type: String,
  71. default: '',
  72. },
  73. orgTreeData: {
  74. type: Array as PropType<OrgListOutput[]>,
  75. default: () => [],
  76. },
  77. })
  78. const formRef = ref()
  79. const state = reactive({
  80. showDialog: false,
  81. sureLoading: false,
  82. form: {
  83. enabled: true,
  84. } as OrgUpdateInput,
  85. })
  86. const { form } = toRefs(state)
  87. // 打开对话框
  88. const open = async (row: any = {}) => {
  89. if (row.id > 0) {
  90. const res = await new OrgApi().get({ id: row.id }, { loading: true })
  91. if (res?.success) {
  92. let formData = res.data as OrgUpdateInput
  93. formData.parentId = formData.parentId && formData.parentId > 0 ? formData.parentId : undefined
  94. state.form = formData
  95. }
  96. } else {
  97. state.form = {
  98. enabled: true,
  99. } as OrgUpdateInput
  100. }
  101. state.showDialog = true
  102. }
  103. // 取消
  104. const onCancel = () => {
  105. state.showDialog = false
  106. }
  107. // 确定
  108. const onSure = () => {
  109. formRef.value.validate(async (valid: boolean) => {
  110. if (!valid) return
  111. state.sureLoading = true
  112. let res = {} as any
  113. state.form.parentId = state.form.parentId && state.form.parentId > 0 ? state.form.parentId : undefined
  114. if (state.form.id != undefined && state.form.id > 0) {
  115. res = await new OrgApi().update(state.form, { showSuccessMessage: true })
  116. } else {
  117. res = await new OrgApi().add(state.form, { showSuccessMessage: true })
  118. }
  119. state.sureLoading = false
  120. if (res?.success) {
  121. eventBus.emit('refreshOrg')
  122. state.showDialog = false
  123. }
  124. })
  125. }
  126. defineExpose({
  127. open,
  128. })
  129. </script>