add.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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 #scientist_id>
  11. <el-option v-for="i in scientistList" :key="i.id" :label="i.name" :value="i._id"></el-option>
  12. </template>
  13. <template #fields>
  14. <el-option v-for="i in fieldList" :key="i.dict_value" :label="i.dict_label" :value="i.dict_value"></el-option>
  15. </template>
  16. <template #direction>
  17. <span v-for="(i, index) in form.direction" :key="index" class="direction">
  18. <span>{{ index + 1 }}.</span>{{ i.name }}
  19. </span>
  20. </template>
  21. <template #studio_id>
  22. <el-option v-for="i in studioList" :key="i._id" :label="i.apply_name || i.name" :value="i._id"></el-option>
  23. </template>
  24. <template #settle_file>
  25. <component :is="CFile" model="settle_file" :limit="limit" :url="url" :list="form.settle_file" @change="onChange"></component>
  26. </template>
  27. <template #team>
  28. <el-col :span="24" class="team_1">
  29. <el-button type="primary" size="small" @click="addTeam()">添加团队成员</el-button>
  30. <el-col :span="24" class="team_txt">团队成员人数不可超过15人!</el-col>
  31. </el-col>
  32. <el-col :span="24" class="team_2">
  33. <el-table :data="form.team" border size="small">
  34. <el-table-column type="index" label="序号" width="50" align="center"> </el-table-column>
  35. <el-table-column prop="name" label="姓名" align="center">
  36. <template v-slot="scope">
  37. <el-input v-model="scope.row.name" placeholder="请输入姓名"></el-input>
  38. </template>
  39. </el-table-column>
  40. <el-table-column prop="company" label="工作单位" align="center">
  41. <template v-slot="scope">
  42. <el-input v-model="scope.row.company" placeholder="请输入工作单位"></el-input>
  43. </template>
  44. </el-table-column>
  45. <el-table-column prop="zc" label="职称" align="center">
  46. <template v-slot="scope">
  47. <el-input v-model="scope.row.zc" placeholder="请输入职称"></el-input>
  48. </template>
  49. </el-table-column>
  50. <el-table-column prop="phone" label="手机号码" align="center">
  51. <template v-slot="scope">
  52. <el-input v-model="scope.row.phone" placeholder="请输入手机号码"></el-input>
  53. </template>
  54. </el-table-column>
  55. <el-table-column label="操作" align="center" width="100" v-if="form.status == null">
  56. <template v-slot="scope">
  57. <el-button size="small" type="danger" @click="delTeam(scope.row)">删除</el-button>
  58. </template>
  59. </el-table-column>
  60. </el-table>
  61. </el-col>
  62. </template>
  63. </component>
  64. </el-col>
  65. </el-col>
  66. </el-row>
  67. </div>
  68. </template>
  69. <script setup lang="ts">
  70. import store from '@/stores/counter';
  71. import moment from 'moment';
  72. // #region 组件
  73. import partsSearch from '@common/src/components/frame/c-search.vue';
  74. import CForm from '@common/src/components/frame/c-form.vue';
  75. import CFile from '@common/src/components/frame/c-upload.vue';
  76. // #endregion
  77. import type { Ref } from 'vue';
  78. import { ref, onMounted, reactive } from 'vue';
  79. import type { FormRules } from 'element-plus';
  80. import { ElMessage } from 'element-plus';
  81. import { useRoute } from 'vue-router';
  82. // #region 接口
  83. import { ScientistsettleStore } from '@common/src/stores/studio/studios/scientistsettle'; // 入驻科学家工作室
  84. import { StudioStore } from '@common/src/stores/studio/studios/studio'; // 工作室
  85. import { UnitStudioApplyStore } from '@common/src/stores/studio/role/unitStudioApply'; // 依托单位申请科学家工作室权限表
  86. import { UserStudioApplyStore } from '@common/src/stores/studio/role/userStudioApply'; //个人账号申请科学家工作室权限表
  87. import { DictDataStore } from '@common/src/stores/users/sysdictdata'; // 字典表
  88. import type { IQueryResult } from '@/util/types.util';
  89. const studio = StudioStore();
  90. const unitStudioApply = UnitStudioApplyStore();
  91. const scientistsettle = ScientistsettleStore();
  92. const sysdictdata = DictDataStore();
  93. const userStudioApply = UserStudioApplyStore();
  94. let route = useRoute();
  95. // 必填项
  96. const rules = reactive<FormRules>({});
  97. // 表单
  98. let fields: Ref<any[]> = ref([
  99. { label: '依托单位名称', model: 'company_name', options: { disabled: true } },
  100. {
  101. label: '科学家工作室',
  102. model: 'studio_id',
  103. type: 'select',
  104. format: (i) => {
  105. let data = studioList.value.find((r) => r._id == i);
  106. if (data) return data.name;
  107. },
  108. options: { disabled: true },
  109. },
  110. {
  111. label: '科学家姓名',
  112. model: 'scientist_id',
  113. type: 'select',
  114. format: (i) => {
  115. let data = scientistList.value.find((r) => r._id == i);
  116. if (data) return data.name;
  117. },
  118. options: { disabled: true },
  119. },
  120. { label: '工作单位', model: 'company', options: { disabled: true } },
  121. { label: '职称', model: 'zc', options: { disabled: true } },
  122. { label: '专业领域', model: 'fields', type: 'selectMany', options: { disabled: true } },
  123. { label: '研究方向', model: 'direction', custom: true },
  124. { label: '文件', model: 'settle_file', custom: true },
  125. { label: '团队成员', model: 'team', custom: true },
  126. ]);
  127. let limit: Ref<number> = ref(1);
  128. let url: Ref<string> = ref('/files/studioadmin/support/upload');
  129. // 用户信息
  130. let user: Ref<{ _id: string; name: string; unit_name: string; nick_name: string }> = ref({ _id: '', name: '', unit_name: '', nick_name: '' });
  131. // 依托单位信息
  132. let unitInfo: Ref<{ _id: String; status: String; company: string }> = ref({ _id: '', status: '', company: '' });
  133. // 表单
  134. let form: Ref<{
  135. scientist_name: string;
  136. user_id: string;
  137. company: string;
  138. zc: string;
  139. fields: Array<any>;
  140. direction: Array<any>;
  141. settle_file: Array<any>;
  142. team: Array<any>;
  143. status: string;
  144. }> = ref({
  145. scientist_name: '',
  146. user_id: '',
  147. company: '',
  148. zc: '',
  149. fields: [],
  150. direction: [],
  151. settle_file: [],
  152. status: '',
  153. team: [],
  154. });
  155. // 行业领域
  156. let fieldList: Ref<any[]> = ref([]);
  157. // 科学家信息
  158. let scientistList: Ref<any[]> = ref([]);
  159. // 工作室
  160. let studioList: Ref<any[]> = ref([]);
  161. onMounted(async () => {
  162. user.value = store.state.user as { _id: string; name: string; unit_name: string; nick_name: string };
  163. await searchOther();
  164. await searchUnit();
  165. await search();
  166. });
  167. // 依托单位信息
  168. const searchUnit = async () => {
  169. const res: IQueryResult = await unitStudioApply.query({ unit_id: user.value._id });
  170. let list = res.data as any[];
  171. if (res.total > 0) unitInfo.value = list[0];
  172. };
  173. // 查询
  174. const search = async () => {
  175. let data = {
  176. company_id: unitInfo.value._id,
  177. company_name: unitInfo.value.company,
  178. scientist_name: '',
  179. user_id: '',
  180. company: '',
  181. zc: '',
  182. fields: [],
  183. direction: [],
  184. settle_file: [],
  185. status: '',
  186. team: [],
  187. };
  188. if (route.query && route.query.id) {
  189. let id = route.query.id;
  190. const res: IQueryResult = await scientistsettle.fetch(id);
  191. if (res.errcode == 0) {
  192. if (res.data) {
  193. form.value = res.data as { scientist_name: ''; user_id: ''; company: ''; zc: ''; fields: []; direction: []; settle_file: []; status: ''; team: [] };
  194. }
  195. }
  196. } else {
  197. form.value = { ...data };
  198. }
  199. };
  200. // 添加成员信息
  201. const addTeam = () => {
  202. let team = form.value.team;
  203. if (team.length >= 15) {
  204. ElMessage({ message: `团队成员人数不可超过15人!`, type: 'error' });
  205. } else {
  206. team.push({ id: moment().valueOf(), name: '' });
  207. }
  208. form.value.team = team;
  209. };
  210. // 团队成员信息删除
  211. const delTeam = (e) => {
  212. let team = form.value.team.filter((i: any) => i.id != e.id);
  213. form.value.team = team;
  214. };
  215. const dataChange = (model, value) => {
  216. if (model == 'scientist_id') {
  217. let data = scientistList.value.find((i) => i._id == value);
  218. if (data) {
  219. form.value.scientist_name = data.name;
  220. form.value.user_id = data.user_id;
  221. form.value.company = data.company;
  222. form.value.zc = data.zc;
  223. form.value.fields = data.fields;
  224. form.value.direction = data.direction;
  225. }
  226. }
  227. };
  228. // 返回
  229. const toBack = () => {
  230. window.history.go(-1);
  231. };
  232. // 上传
  233. const onChange = (e: { model: string; value: Array<[]> }) => {
  234. const { model, value } = e;
  235. form.value[model] = value;
  236. };
  237. // 添加
  238. const toSave = async (data: { _id: string }) => {
  239. let res: IQueryResult;
  240. if (data._id) res = await scientistsettle.update(data);
  241. else res = await scientistsettle.create(data);
  242. if (res.errcode == 0) {
  243. ElMessage({ type: 'success', message: '维护信息成功' });
  244. toBack();
  245. } else ElMessage({ type: 'warning', message: `${res.errmsg}` });
  246. };
  247. // 查询其他信息
  248. const searchOther = async () => {
  249. //科学家信息
  250. const p1: IQueryResult = await userStudioApply.query({ status: '1' });
  251. scientistList.value = p1.data as [];
  252. // 领域
  253. const p2: IQueryResult = await sysdictdata.query({ dict_type: 'studio_field' });
  254. fieldList.value = p2.data as [];
  255. // 工作室
  256. const p3: IQueryResult = await studio.query({ user_id: user.value._id });
  257. studioList.value = p3.data as [];
  258. };
  259. </script>
  260. <style scoped></style>