detail.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <template>
  2. <div id="detail">
  3. <el-row>
  4. <el-col :span="24" class="main animate__animated animate__backInRight" v-loading="loading">
  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="fields" :form="form" :rules="rules" @save="toSave" label-width="auto">
  10. <template #role>
  11. <el-option v-for="i in roleList" :key="i._id" :label="i.name" :value="i._id"></el-option>
  12. </template>
  13. <template #region>
  14. <el-option v-for="i in regionList" :key="i._id" :label="i.name" :value="i._id"></el-option>
  15. </template>
  16. </cForm>
  17. </el-col>
  18. </el-col>
  19. </el-row>
  20. </div>
  21. </template>
  22. <script setup lang="ts">
  23. // 基础
  24. import type { Ref } from 'vue';
  25. import { ref, reactive, onMounted } from 'vue';
  26. import { ElMessage } from 'element-plus';
  27. import type { FormRules } from 'element-plus';
  28. import { useRoute } from 'vue-router';
  29. // 接口
  30. import { AdminStore } from '@/stores/users/admin';
  31. import { RoleStore } from '@/stores/basic/role'; // 角色
  32. import { RegionStore } from '@/stores/basic/region'; // 区域
  33. import { DictDataStore } from '@/stores/basic/dictData'; // 字典表
  34. import type { IQueryResult } from '@/util/types.util';
  35. const adminAxios = AdminStore();
  36. const dictAxios = DictDataStore();
  37. const roleAxios = RoleStore();
  38. const regionAxios = RegionStore();
  39. // 路由
  40. const route = useRoute();
  41. // 加载中
  42. const loading: Ref<any> = ref(false);
  43. // 表单
  44. let form: Ref<any> = ref({});
  45. let fields: Ref<any[]> = ref([
  46. { label: '账号', model: 'account', options: { disabled: true } },
  47. { label: '姓名', model: 'name' },
  48. { label: '手机号', model: 'phone' },
  49. { label: '角色', model: 'role', type: 'select' },
  50. { label: '区域', model: 'region', type: 'select' }
  51. ]);
  52. const rules = reactive<FormRules>({
  53. name: [{ required: true, message: '请输入姓名', trigger: 'blur' }],
  54. phone: [{ required: true, message: '请输入手机号', trigger: 'blur' }],
  55. role: [{ required: true, message: '请输入角色', trigger: 'blur' }]
  56. });
  57. // 字典表
  58. const roleList: Ref<any> = ref([]);
  59. const regionList: Ref<any> = ref([]);
  60. const statusList: Ref<any> = ref([]);
  61. // 请求
  62. onMounted(async () => {
  63. loading.value = true;
  64. await searchOther();
  65. await search();
  66. loading.value = false;
  67. });
  68. const search = async () => {
  69. let id = route.query.id;
  70. if (id) {
  71. let res: IQueryResult = await adminAxios.fetch(id);
  72. if (res.errcode == '0') form.value = res.data as {};
  73. }
  74. };
  75. // 保存
  76. const toSave = async (data: any) => {
  77. let res: IQueryResult;
  78. if (data._id) res = await adminAxios.update(data);
  79. else res = await adminAxios.create(data);
  80. if (res.errcode == 0) {
  81. ElMessage({ type: `success`, message: `维护信息成功` });
  82. toBack();
  83. }
  84. };
  85. // 查询其他信息
  86. const searchOther = async () => {
  87. let res: IQueryResult;
  88. // 角色
  89. res = await roleAxios.query({ is_use: '0' });
  90. if (res.errcode == '0') roleList.value = res.data;
  91. // 状态
  92. res = await dictAxios.query({ type: 'exam_status', is_use: '0' });
  93. if (res.errcode == '0') statusList.value = res.data;
  94. // 区域
  95. res = await regionAxios.query({ is_use: '0' });
  96. if (res.errcode == '0') regionList.value = res.data;
  97. };
  98. // 返回上一页
  99. const toBack = () => {
  100. window.history.go(-1);
  101. };
  102. </script>
  103. <style scoped lang="scss"></style>