detail.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <template>
  2. <div id="detail">
  3. <el-row>
  4. <el-col :span="24" class="main">
  5. <el-col :span="24" class="one">
  6. <cSearch :is_back="true" @toBack="toBack"></cSearch>
  7. </el-col>
  8. <el-col :span="24" class="two">
  9. <cForm :span="24" :fields="formFields" :form="form" :rules="rules" @save="onSubmit">
  10. <template #pid>
  11. <el-option v-for="(i, index) in pidList" :key="index" :label="i.name" :value="i.id"></el-option>
  12. </template>
  13. <template #type>
  14. <el-option v-for="(i, index) in typeList" :key="index" :label="i.label" :value="i.value"></el-option>
  15. </template>
  16. <template #code>
  17. <el-option v-for="(i, index) in codeList" :key="index" :label="i.label" :value="i.value"></el-option>
  18. </template>
  19. <template #password>
  20. <el-input v-model="form.password" placeholder="请输入密码" :disabled="form._id ? true : false" show-password></el-input>
  21. </template>
  22. <template #role>
  23. <el-select v-model="form.role" multiple placeholder="请选择角色" style="width: 100%">
  24. <el-option v-for="i in roleList" :key="i._id" :label="i.name" :value="i._id"> </el-option>
  25. </el-select>
  26. </template>
  27. </cForm>
  28. </el-col>
  29. </el-col>
  30. </el-row>
  31. </div>
  32. </template>
  33. <script setup lang="ts">
  34. import type { FormRules } from 'element-plus';
  35. import type { Ref } from 'vue';
  36. import { ref, reactive, onMounted } from 'vue';
  37. import { ElMessage } from 'element-plus';
  38. import { useRoute } from 'vue-router';
  39. import { DictDataStore } from '@common/src/stores/system/dictData'; // 字典表
  40. import { RoleStore } from '@common/src/stores/system/role'; // 角色
  41. import { AdminStore } from '@common/src/stores/admins/admin'; // 角色
  42. import type { IQueryResult } from '@/util/types.util';
  43. const admin = AdminStore();
  44. const dictData = DictDataStore();
  45. const role = RoleStore();
  46. const route = useRoute();
  47. let form: Ref<any> = ref({});
  48. let roleList: Ref<any> = ref([]);
  49. let pidList: Ref<any> = ref([]);
  50. let codeList: Ref<any> = ref([]);
  51. let typeList: Ref<any> = ref([
  52. { label: '超级管理员', value: '0' },
  53. { label: '管理员', value: '1' },
  54. { label: '机构用户', value: '2' },
  55. { label: '业务用户', value: '3' }
  56. ]);
  57. // 表单
  58. let formFields: Ref<any[]> = ref([
  59. { label: '所属上级', model: 'pid', type: 'select' },
  60. { label: '用户类型', model: 'type', type: 'select', options: { disabled: true } },
  61. { label: '邀请码', model: 'code', type: 'select' },
  62. { label: '账号', model: 'account' },
  63. { label: '密码', model: 'password', custom: true },
  64. { label: '名称', model: 'name' },
  65. { label: '手机号', model: 'phone' },
  66. { label: '机构名称', model: 'dept_name' },
  67. { label: '角色', model: 'role', custom: true }
  68. ]);
  69. const rules = reactive<FormRules>({
  70. name: [{ required: true, message: '名称', trigger: 'blur' }],
  71. account: [{ required: true, message: '账号', trigger: 'blur' }],
  72. type: [{ required: true, message: '用户类型', trigger: 'blur' }]
  73. });
  74. onMounted(async () => {
  75. await searchOther();
  76. await search();
  77. });
  78. const search = async () => {
  79. if (route.query.id) {
  80. let res: IQueryResult = await admin.fetch(route.query.id);
  81. if (res.errcode == 0) {
  82. form.value = res.data as {};
  83. }
  84. } else form.value.type = '1';
  85. };
  86. // 提交
  87. const onSubmit = async (data) => {
  88. let res: IQueryResult;
  89. if (data._id) res = await admin.update(data);
  90. else res = await admin.create(data);
  91. if (res.errcode == 0) {
  92. ElMessage({ type: `success`, message: `维护信息成功` });
  93. toBack();
  94. }
  95. };
  96. // 返回上一页
  97. const toBack = () => {
  98. window.history.go(-1);
  99. };
  100. const searchOther = async () => {
  101. let res: IQueryResult;
  102. // 邀请码
  103. res = await dictData.query({ type: 'account_code' });
  104. if (res.errcode == 0) codeList.value = res.data;
  105. // 角色
  106. res = await role.query();
  107. if (res.errcode == 0) roleList.value = res.data;
  108. // 管理员
  109. res = await admin.query({ role: '0' });
  110. if (res.errcode == 0) pidList.value = res.data;
  111. };
  112. </script>
  113. <style scoped lang="scss"></style>