add.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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" labelWidth="auto" @save="toSave">
  10. <template #fields>
  11. <el-option v-for="item in fieldList" :key="item.dict_value" :label="item.dict_label" :value="item.dict_value"></el-option>
  12. </template>
  13. <template #is_use>
  14. <el-option v-for="item in isuseList" :key="item.dict_value" :label="item.dict_label" :value="item.dict_value"></el-option>
  15. </template>
  16. <template #file>
  17. <component :is="CFile" model="file" :limit="limit" :url="url" :list="form.file" @change="onChange"></component>
  18. </template>
  19. <template #content>
  20. <component :is="WangEditor" v-model="form.content" url="/files/studioadmin/other/upload"></component>
  21. </template>
  22. </component>
  23. </el-col>
  24. </el-col>
  25. </el-row>
  26. </div>
  27. </template>
  28. <script setup lang="ts">
  29. import store from '@/stores/counter';
  30. // #region 组件
  31. import partsSearch from '@common/src/components/frame/c-search.vue';
  32. import CForm from '@common/src/components/frame/c-form.vue';
  33. import CFile from '@common/src/components/frame/c-upload.vue';
  34. import WangEditor from '@common/src/components/frame/wang-editor.vue';
  35. // #endregion
  36. import type { Ref } from 'vue';
  37. import { ref, onMounted, reactive } from 'vue';
  38. import type { FormRules } from 'element-plus';
  39. import { ElMessage } from 'element-plus';
  40. import { useRoute } from 'vue-router';
  41. // #region 接口
  42. import { TecholsupportStore } from '@common/src/stores/studio/supplydemand/techolsupport'; //技术支持
  43. import { DictDataStore } from '@common/src/stores/users/sysdictdata'; // 字典表
  44. import { UserStudioApplyStore } from '@common/src/stores/studio/role/userStudioApply'; //个人账号申请科学家工作室权限表
  45. import type { IQueryResult } from '@/util/types.util';
  46. const techolsupport = TecholsupportStore();
  47. const sysdictdata = DictDataStore();
  48. const userStudioApply = UserStudioApplyStore();
  49. let route = useRoute();
  50. // 必填项
  51. const rules = reactive<FormRules>({
  52. scientist_name: [{ required: true, message: '请输入科学家姓名', trigger: 'blur' }],
  53. phone: [{ required: true, message: '请输入联系方式', trigger: 'blur' }],
  54. company_name: [{ required: true, message: '请输入单位名称', trigger: 'blur' }],
  55. title: [{ required: true, message: '请输入标题', trigger: 'blur' }],
  56. date: [{ required: true, message: '请选择发布时间', trigger: 'change' }],
  57. fields: [{ required: true, message: '请选择行业领域', trigger: 'change' }],
  58. file: [{ required: true, message: '请上传文件信息', trigger: 'change' }],
  59. content: [{ required: true, message: '请输入信息内容', trigger: 'blur' }],
  60. });
  61. // 表单
  62. let fields: Ref<any[]> = ref([
  63. { label: '科学家姓名', model: 'scientist_name' },
  64. { label: '联系方式', model: 'phone' },
  65. { label: '单位名称', model: 'company_name' },
  66. { label: '标题', model: 'title' },
  67. { label: '发布时间', model: 'date', type: 'date' },
  68. { label: '行业领域', model: 'fields', type: 'selectMany' },
  69. { label: '文件信息', model: 'file', custom: true },
  70. { label: '信息内容', model: 'content', custom: true },
  71. { label: '是否启用', model: 'is_use', type: 'select' },
  72. ]);
  73. let limit: Ref<number> = ref(1);
  74. let url: Ref<string> = ref('/files/studioadmin/support/upload');
  75. // 用户信息
  76. let user: Ref<{ _id: string; name: string; unit_name: string; nick_name: string }> = ref({ _id: '', name: '', unit_name: '', nick_name: '' });
  77. // 个人用户信息
  78. let userInfo: Ref<{ name: string; _id: String; user_id: String; status: String; company: String; phone: { phone: String } }> = ref({
  79. _id: '',
  80. user_id: '',
  81. status: '',
  82. name: '',
  83. company: '',
  84. phone: { phone: '' },
  85. });
  86. // 表单
  87. let form: Ref<{ content: string; file: Array<[]> }> = ref({ content: '', file: [] });
  88. // 行业领域
  89. let fieldList: Ref<any[]> = ref([]);
  90. // 是否启用
  91. let isuseList: Ref<any[]> = ref([]);
  92. onMounted(async () => {
  93. user.value = store.state.user as { _id: string; name: string; unit_name: string; nick_name: string };
  94. await searchOther();
  95. await searchUser();
  96. await search();
  97. });
  98. // 查询个人用户信息
  99. const searchUser = async () => {
  100. const res: IQueryResult = await userStudioApply.query({ user_id: user.value._id });
  101. let list = res.data as any[];
  102. if (res.total > 0) userInfo.value = list[0];
  103. };
  104. // 查询
  105. const search = async () => {
  106. let data = {
  107. file: [],
  108. content: '',
  109. user_id: user.value._id,
  110. scientist_name: userInfo.value.name,
  111. phone: userInfo.value.phone.phone,
  112. company_name: userInfo.value.company,
  113. };
  114. if (route.query && route.query.id) {
  115. let id = route.query.id;
  116. const res: IQueryResult = await techolsupport.fetch(id);
  117. if (res.errcode == 0) {
  118. if (res.data) form.value = res.data as { content: string; file: Array<[]> };
  119. }
  120. } else {
  121. form.value = { ...data };
  122. }
  123. };
  124. // 返回
  125. const toBack = () => {
  126. window.history.go(-1);
  127. };
  128. // 上传
  129. const onChange = (e: { model: string; value: Array<[]> }) => {
  130. const { model, value } = e;
  131. form.value[model] = value;
  132. };
  133. // 添加
  134. const toSave = async (data: { _id: string }) => {
  135. let res: IQueryResult;
  136. if (data._id) res = await techolsupport.update(data);
  137. else res = await techolsupport.create(data);
  138. if (res.errcode == 0) {
  139. ElMessage({ type: 'success', message: '维护信息成功' });
  140. toBack();
  141. } else ElMessage({ type: 'warning', message: `${res.errmsg}` });
  142. };
  143. // 查询其他信息
  144. const searchOther = async () => {
  145. // 领域
  146. const p1: IQueryResult = await sysdictdata.query({ dict_type: 'studio_field' });
  147. fieldList.value = p1.data as [];
  148. // 角色
  149. const p2: IQueryResult = await sysdictdata.query({ dict_type: 'sys_yes_no' });
  150. isuseList.value = p2.data as [];
  151. };
  152. </script>
  153. <style scoped></style>