add.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <template>
  2. <div id="add">
  3. <el-row>
  4. <el-col :span="24" class="main animate__animated animate__backInRight">
  5. <el-col :span="24" class="one">
  6. <component :is="partsSearch" :is_back="true" @toBack="toBack"></component>
  7. </el-col>
  8. <el-col :span="24" class="two">
  9. <component :is="CForm" :fields="fields" :rules="rules" :form="form" @dataChange="dataChange" labelWidth="auto" @save="toSave">
  10. <template #studio_id>
  11. <el-option v-for="i in studioList" :key="i._id" :label="i.name" :value="i._id"></el-option>
  12. </template>
  13. <template #file>
  14. <component :is="CFile" model="file" :limit="limit" :url="url" :list="form.file" @change="onChange"></component>
  15. </template>
  16. </component>
  17. </el-col>
  18. </el-col>
  19. </el-row>
  20. </div>
  21. </template>
  22. <script setup lang="ts">
  23. import store from '@/stores/counter';
  24. // #region 组件
  25. import partsSearch from '@common/src/components/frame/c-search.vue';
  26. import CForm from '@common/src/components/frame/c-form.vue';
  27. import CFile from '@common/src/components/frame/c-upload.vue';
  28. // #endregion
  29. import type { Ref } from 'vue';
  30. import { ref, onMounted, reactive } from 'vue';
  31. import type { FormRules } from 'element-plus';
  32. import { ElMessage } from 'element-plus';
  33. import { useRoute } from 'vue-router';
  34. // #region 接口
  35. import { ApplyflairStore } from '@common/src/stores/studio/studios/applyflair'; //申请保留资质
  36. import { StudioStore } from '@common/src/stores/studio/studios/studio'; // 工作室
  37. import { UnitStudioApplyStore } from '@common/src/stores/studio/role/unitStudioApply'; //个人账号申请科学家工作室权限表
  38. import type { IQueryResult } from '@/util/types.util';
  39. const applyflair = ApplyflairStore();
  40. const studio = StudioStore();
  41. const unitStudioApply = UnitStudioApplyStore();
  42. let route = useRoute();
  43. // 必填项
  44. const rules = reactive<FormRules>({
  45. studio_id: [{ required: true, message: '请选择工作室名称', trigger: 'change' }],
  46. file: [{ required: true, message: '请上传评估文件', trigger: 'change' }],
  47. apply_time: [{ required: true, message: '请选择申请时间', trigger: 'change' }],
  48. });
  49. // 表单
  50. let fields: Ref<any[]> = ref([
  51. { label: '依托单位名称', model: 'company_name', options: { readonly: true } },
  52. { label: '工作室名称', model: 'studio_id', type: 'select' },
  53. { label: '评估文件', model: 'file', custom: true },
  54. { label: '申请时间', model: 'apply_time', type: 'date' },
  55. ]);
  56. let limit: Ref<number> = ref(1);
  57. let url: Ref<string> = ref('/files/studioadmin/applyflair/upload');
  58. // 用户信息
  59. let user: Ref<{ _id: string; name: string; unit_name: string; nick_name: string }> = ref({ _id: '', name: '', unit_name: '', nick_name: '' });
  60. // 依托单位信息
  61. let unitInfo: Ref<{ _id: String; status: String; company: string; phone: string }> = ref({ _id: '', status: '', company: '', phone: '' });
  62. // 表单
  63. let form: Ref<{ file: Array<[]>; studio_name: string }> = ref({ file: [], studio_name: '' });
  64. // 工作室列表
  65. let studioList: Ref<any[]> = ref([]);
  66. onMounted(async () => {
  67. user.value = store.state.user as { _id: string; name: string; unit_name: string; nick_name: string };
  68. await searchUnit();
  69. await searchOther();
  70. await search();
  71. });
  72. // 依托单位信息
  73. const searchUnit = async () => {
  74. const res: IQueryResult = await unitStudioApply.query({ unit_id: user.value._id });
  75. let list = res.data as any[];
  76. if (res.total > 0) unitInfo.value = list[0];
  77. };
  78. // 查询
  79. const search = async () => {
  80. let data = {
  81. user_id: unitInfo.value._id,
  82. company_name: unitInfo.value.company,
  83. file: [],
  84. studio_name: '',
  85. };
  86. if (route.query && route.query.id) {
  87. let id = route.query.id;
  88. const res: IQueryResult = await applyflair.fetch(id);
  89. if (res.errcode == 0) {
  90. if (res.data) form.value = res.data as { content: string; file: Array<[]>; studio_name: string };
  91. }
  92. } else {
  93. form.value = { ...data };
  94. }
  95. };
  96. // 返回
  97. const toBack = () => {
  98. window.history.go(-1);
  99. };
  100. // 数据选择
  101. const dataChange = ({ model, value }) => {
  102. if (model == 'studio_id') {
  103. let data = studioList.value.find((i) => i._id == value);
  104. if (data) form.value.studio_name = data.name;
  105. }
  106. };
  107. // 上传
  108. const onChange = (e: { model: string; value: Array<[]> }) => {
  109. const { model, value } = e;
  110. form.value[model] = value;
  111. };
  112. // 添加
  113. const toSave = async (data: { _id: string }) => {
  114. let res: IQueryResult;
  115. if (data._id) res = await applyflair.update(data);
  116. else res = await applyflair.create(data);
  117. if (res.errcode == 0) {
  118. ElMessage({ type: 'success', message: '维护信息成功' });
  119. toBack();
  120. } else ElMessage({ type: 'warning', message: `${res.errmsg}` });
  121. };
  122. // 查询其他信息
  123. const searchOther = async () => {
  124. // 工作室
  125. const p1: IQueryResult = await studio.query({ status: '1', user_id: user.value._id });
  126. studioList.value = p1.data as [];
  127. };
  128. </script>
  129. <style scoped></style>