organization-add.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <template>
  2. <!-- "ancestors": "",
  3. "contact": "",
  4. "orderNum": 0,
  5. "orgId": 0,
  6. "orgName": "",
  7. "parentId": 0,
  8. "password": "",
  9. "type": 0,
  10. "userName": "" -->
  11. <el-form label-width="100px" :model="data" :rules="rules" ref="baseFormRef">
  12. <el-form-item label="单位名称" prop="orgName" required>
  13. <el-input
  14. v-model.trim="data.orgName"
  15. style="width: 300px"
  16. :maxlength="50"
  17. placeholder="请输入"
  18. />
  19. </el-form-item>
  20. <el-form-item label="类型" prop="type" required>
  21. <!-- <el-input v-model="data.type" style="width: 300px" :maxlength="500" placeholder="请输入" /> -->
  22. <el-select style="width: 300px" v-model="data.type">
  23. <el-option
  24. :value="Number(key)"
  25. :label="type"
  26. v-for="(type, key) in OrganizationTypeDesc"
  27. />
  28. </el-select>
  29. </el-form-item>
  30. <el-form-item label="上级单位" prop="parentId">
  31. <el-tree-select
  32. :check-strictly="true"
  33. :props="{
  34. value: 'orgId',
  35. label: (data: any) => data.orgName,
  36. }"
  37. style="width: 300px"
  38. v-model="data.parentId"
  39. :data="allOrgs"
  40. node-key="orgId"
  41. clearable
  42. >
  43. </el-tree-select>
  44. </el-form-item>
  45. <el-form-item label="联系人" prop="contact" required>
  46. <el-input
  47. v-model.trim="data.contact"
  48. style="width: 300px"
  49. :maxlength="50"
  50. placeholder="请输入"
  51. />
  52. </el-form-item>
  53. <el-form-item label="账号" prop="userName" required>
  54. <el-input
  55. v-model.trim="data.userName"
  56. style="width: 300px"
  57. :maxlength="11"
  58. placeholder="请输入手机号"
  59. />
  60. </el-form-item>
  61. <el-form-item label="密码" prop="password" required>
  62. <el-input
  63. autocomplete="off"
  64. readonly
  65. onfocus="this.removeAttribute('readonly');"
  66. v-model.trim="data.password"
  67. :type="addPassFlag ? 'text' : 'password'"
  68. style="width: 300px"
  69. :maxlength="500"
  70. placeholder="请输入8-16位数字、字母大小写组合"
  71. >
  72. <template #suffix>
  73. <span @click="addPassFlag = !addPassFlag" style="cursor: pointer">
  74. <el-icon v-if="addPassFlag">
  75. <View />
  76. </el-icon>
  77. <el-icon v-else>
  78. <Hide />
  79. </el-icon>
  80. </span>
  81. </template>
  82. </el-input>
  83. </el-form-item>
  84. </el-form>
  85. </template>
  86. <script setup lang="ts">
  87. import { QuiskExpose } from "@/helper/mount";
  88. import type { FormInstance, FormRules } from "element-plus";
  89. // import { ElMessage } from "element-plus";
  90. import type { OrganizationType } from "@/request/organization";
  91. import { OrganizationTypeDesc } from "@/store/organization";
  92. import { globalPasswordRex } from "@/util/regex";
  93. import { ref, reactive, unref, watch, onMounted } from "vue";
  94. import { View, Hide } from "@element-plus/icons-vue";
  95. // import { user } from '@/store/user'
  96. import { getOrgListFetchList } from "@/request";
  97. const addPassFlag = ref(true); //图标显示标识
  98. type SelectType = {
  99. orgName: string;
  100. orgId: number;
  101. children: SelectType[];
  102. };
  103. const baseFormRef = ref<FormInstance>();
  104. const allOrgs = ref<SelectType[]>([]);
  105. const rules = reactive<FormRules>({
  106. orgName: [{ required: true, message: "请输入单位名称", trigger: "blur" }],
  107. type: [{ required: true, message: "请选择类型", trigger: "change" }],
  108. contact: [{ required: true, message: "请输入联系人", trigger: "blur" }],
  109. userName: [
  110. {
  111. required: true,
  112. pattern: /^1[3456789]\d{9}$/,
  113. message: "请输入正确手机号",
  114. trigger: "blur",
  115. },
  116. ],
  117. password: [
  118. {
  119. required: true,
  120. pattern: globalPasswordRex,
  121. message: "请输入8-16位数字、字母大小写组合",
  122. trigger: "blur",
  123. },
  124. { required: true, min: 8, message: "密码太短!", trigger: "blur" },
  125. ],
  126. });
  127. const props = defineProps<{
  128. submit: (data: OrganizationType) => Promise<any>;
  129. }>();
  130. const data = ref<OrganizationType & {}>({
  131. ancestors: "",
  132. contact: "",
  133. orderNum: 0,
  134. orgId: 0,
  135. orgName: "",
  136. parentId: null,
  137. password: "",
  138. type: null,
  139. userName: "",
  140. });
  141. // const setParentId = () => {
  142. // if (user.value) {
  143. // const isSuper = user.value.roles.filter(item => item.roleKey === "super_admin").length > 0;
  144. // data.value.parentId = isSuper ? 0 : Number(data.value.parentId)
  145. // }
  146. // }
  147. onMounted(async () => {
  148. const data = await getOrgListFetchList();
  149. // console.log('allOrgs', data);
  150. allOrgs.value = data as any as SelectType[];
  151. });
  152. watch(
  153. data,
  154. (newValue) => {
  155. data.value.userName = newValue.userName.replace(/[^0-9]/g, "");
  156. },
  157. {
  158. immediate: true,
  159. deep: true,
  160. }
  161. );
  162. defineExpose<QuiskExpose>({
  163. async submit() {
  164. if (unref(baseFormRef)) {
  165. // setParentId();
  166. const res = await unref(baseFormRef)?.validate();
  167. if (res) {
  168. console.log("data", data.value);
  169. await props.submit(data.value as any as OrganizationType);
  170. }
  171. } else {
  172. throw "";
  173. }
  174. },
  175. });
  176. </script>