organization-edit.vue 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <template>
  2. <el-form label-width="100px" :model="data" :rules="rules" ref="baseFormRef">
  3. <el-form-item label="单位名称" prop="orgName" required>
  4. <el-input v-model="data.orgName" style="width: 300px" :maxlength="500" placeholder="请输入" />
  5. </el-form-item>
  6. <el-form-item label="类型" prop="type" required>
  7. <!-- <el-input v-model="data.type" style="width: 300px" :maxlength="500" placeholder="请输入" /> -->
  8. <el-select style="width: 300px" v-model="data.type">
  9. <el-option :value="Number(key)" :label="type" v-for="(type, key) in OrganizationTypeDesc" />
  10. </el-select>
  11. </el-form-item>
  12. </el-form>
  13. </template>
  14. <script setup lang="ts">
  15. import { QuiskExpose } from "@/helper/mount";
  16. import type { FormInstance, FormRules } from "element-plus";
  17. import type { OrganizationType } from "@/request/organization";
  18. import { OrganizationTypeDesc } from '@/store/organization'
  19. import { ref, reactive, unref, watchEffect } from "vue";
  20. import { user } from '@/store/user'
  21. const baseFormRef = ref<FormInstance>();
  22. const rules = reactive<FormRules>({
  23. orgName: [
  24. { required: true, message: "请输入单位名称", trigger: "blur" },
  25. ],
  26. type: [
  27. { required: true, message: "请选择类型", trigger: "change" },
  28. ],
  29. contact: [
  30. { required: true, message: "请输入联系人", trigger: "blur" },
  31. ],
  32. userName: [
  33. { required: true, pattern: /^1[3456789]\d{9}$/, message: "请输入正确手机号", trigger: "blur" },
  34. ],
  35. password: [
  36. { required: true, pattern: /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[\s\S]{8,16}$/, message: "请输入8-16位数字、字母大小写组合", trigger: "blur" },
  37. { required: true, min: 8, message: '密码太短!', trigger: "blur" },
  38. ],
  39. },)
  40. const props = defineProps<{
  41. org: OrganizationType,
  42. submit: (data: OrganizationType) => Promise<any>;
  43. }>();
  44. const data = ref<OrganizationType & {}>({
  45. ancestors: "",
  46. contact: "",
  47. orderNum: 0,
  48. orgId: 0,
  49. orgName: "",
  50. parentId: 0,
  51. password: "",
  52. type: null,
  53. userName: ""
  54. });
  55. const setParentId = () => {
  56. if (user.value) {
  57. const isSuper = user.value.roles.filter(item => item.roleKey === "super_admin").length > 0;
  58. data.value.parentId = isSuper ? 0 : Number(user.value.orgId)
  59. }
  60. }
  61. watchEffect(() => {
  62. if (props.org) {
  63. data.value = { ...props.org }
  64. }
  65. })
  66. defineExpose<QuiskExpose>({
  67. async submit() {
  68. if (unref(baseFormRef)) {
  69. setParentId();
  70. const res = await unref(baseFormRef)?.validate();
  71. if (res) {
  72. await props.submit(data.value as any as OrganizationType);
  73. }
  74. } else {
  75. throw "";
  76. }
  77. },
  78. });
  79. </script>