unit-1.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. <template>
  2. <div id="unit-1">
  3. <el-row>
  4. <el-col :span="24" class="main">
  5. <el-col :span="24" class="one">
  6. <el-col :span="24" class="one_1">一、账户信息</el-col>
  7. <el-col :span="24" class="one_2">
  8. <component :is="CForm" :fields="fields" :rules="{}" :form="form" labelWidth="auto" @save="toSave">
  9. <template #is_studio>
  10. <el-option v-for="item in studioList" :key="item.dict_label" :label="item.dict_label" :value="item.dict_value"></el-option>
  11. </template>
  12. <template #prove>
  13. <component :is="CFile" model="prove" :limit="limit" :url="url" :list="form.prove" @change="onChange"></component>
  14. </template>
  15. </component>
  16. </el-col>
  17. </el-col>
  18. <el-col :span="24" class="two" v-show="form.is_studio == 'Y'">
  19. <el-col :span="24" class="two_1">二、基础信息</el-col>
  20. <el-col :span="24" class="two_2">
  21. <component :is="CForm" :fields="ufields" :rules="rules" :form="uform" labelWidth="auto" @save="utoSave" @dataChange="dataChange">
  22. <template #card>
  23. <component :is="CFile" model="card" limit="2" url="/files/studioadmin/register/upload" :list="uform.card" @change="uonChange"></component>
  24. </template>
  25. <template #unit_phone>
  26. <el-col :span="12">
  27. <el-form-item label="内容" label-width="100px" prop="unit_phone.phone">
  28. <el-input v-model="uform.unit_phone.phone" :disabled="true" placeholder="请输入联系电话"></el-input>
  29. </el-form-item>
  30. </el-col>
  31. <el-col :span="12">
  32. <el-form-item label="是否公开" label-width="80px">
  33. <el-select v-model="uform.unit_phone.is_show" placeholder="请选择" style="width: 100%">
  34. <el-option v-for="i in isshowList" :key="i.model" :label="i.dict_label" :value="i.dict_value"></el-option>
  35. </el-select>
  36. </el-form-item>
  37. </el-col>
  38. </template>
  39. <template #unit_email>
  40. <el-col :span="12">
  41. <el-form-item label="内容" label-width="100px" prop="unit_email.email">
  42. <el-input v-model="uform.unit_email.email" :disabled="true" placeholder="请输入单位联系电话"></el-input>
  43. </el-form-item>
  44. </el-col>
  45. <el-col :span="12">
  46. <el-form-item label="是否公开" label-width="80px">
  47. <el-select v-model="uform.unit_email.is_show" placeholder="请选择" style="width: 100%">
  48. <el-option v-for="i in isshowList" :key="i.model" :label="i.dict_label" :value="i.dict_value"></el-option>
  49. </el-select>
  50. </el-form-item>
  51. </el-col>
  52. </template>
  53. <template #fields>
  54. <el-option v-for="i in fieldList" :key="i.dict_value" :label="i.dict_label" :value="i.dict_value"></el-option>
  55. </template>
  56. <template #direction>
  57. <el-button style="margin-bottom: 0.5vw" type="primary" size="small" @click="addDriection()">添加</el-button>
  58. <el-col :span="24">
  59. <el-table :data="uform.direction" border size="small">
  60. <el-table-column type="index" label="序号" width="50" align="center"> </el-table-column>
  61. <el-table-column prop="name" label="名称" align="center">
  62. <template v-slot="scope">
  63. <el-input v-model="scope.row.name" placeholder="请输入技术需求方向名称,名称长度不可超过八个字" maxlength="8"></el-input>
  64. </template>
  65. </el-table-column>
  66. <el-table-column label="操作" align="center" width="100">
  67. <template v-slot="scope">
  68. <el-button size="small" type="danger" @click="delDriection(scope.row)">删除</el-button>
  69. </template>
  70. </el-table-column>
  71. </el-table>
  72. </el-col>
  73. </template>
  74. <template #audit_report>
  75. <component :is="CFile" model="audit_report" :limit="limit" :url="url" :list="uform.audit_report" @change="uonChange"></component>
  76. </template>
  77. <template #special_report>
  78. <component :is="CFile" model="special_report" :limit="limit" :url="url" :list="uform.special_report" @change="uonChange"></component>
  79. </template>
  80. <template #prove_file>
  81. <component :is="CFile" model="prove_file" :limit="limit" :url="url" :list="uform.prove_file" @change="uonChange"></component>
  82. </template>
  83. </component>
  84. </el-col>
  85. </el-col>
  86. </el-col>
  87. </el-row>
  88. </div>
  89. </template>
  90. <script setup lang="ts">
  91. import store from '@/stores/counter';
  92. import moment from 'moment';
  93. // #region 组件
  94. import CForm from '@common/src/components/frame/c-form.vue';
  95. import CFile from '@common/src/components/frame/c-upload.vue';
  96. // #endregion
  97. import type { Ref } from 'vue';
  98. import { ref, onMounted, reactive, watch } from 'vue';
  99. import type { FormRules } from 'element-plus';
  100. import { ElMessage } from 'element-plus';
  101. // #region 接口
  102. import { UnitStore } from '@common/src/stores/users/unit'; //依托单位
  103. import { UnitStudioApplyStore } from '@common/src/stores/studio/role/unitStudioApply'; // 依托单位申请科学家工作室权限表
  104. import { DictDataStore } from '@common/src/stores/users/sysdictdata'; // 字典表
  105. import type { IQueryResult } from '@/util/types.util';
  106. const unitStudioApply = UnitStudioApplyStore();
  107. const unit = UnitStore();
  108. const sysdictdata = DictDataStore();
  109. // 必填项
  110. const rules = reactive<FormRules>({
  111. company: [{ required: true, message: '请输入单位全称', trigger: 'blur' }],
  112. address: [{ required: true, message: '请输入单位地址', trigger: 'blur' }],
  113. name: [{ required: true, message: '请输入单位法人姓名', trigger: 'blur' }],
  114. phone: [
  115. { required: true, message: '单位法人手机号码', trigger: 'change' },
  116. { pattern: /^1[3|5|7|8|9]\d{9}$/, message: '请输入正确的号码格式', trigger: 'change' },
  117. ],
  118. card: [{ required: true, message: '请上传法人身份证', trigger: 'change' }],
  119. unit_contact: [{ required: true, message: '请输入单位联系人', trigger: 'blur' }],
  120. 'unit_phone.phone': [
  121. { required: true, message: '单位联系电话', trigger: 'change' },
  122. { pattern: /^1[3|5|7|8|9]\d{9}$/, message: '请输入正确的号码格式', trigger: 'change' },
  123. ],
  124. 'unit_email.email': [{ required: true, message: '请输入单位电子邮箱', trigger: 'blur' }],
  125. fields: [{ required: true, message: '请选择行业领域', trigger: 'change' }],
  126. direction: [{ required: true, message: '请添加技术需求方向', trigger: 'change' }],
  127. audit_report: [{ required: true, message: '请上传上一年度财务审计报告', trigger: 'change' }],
  128. special_report: [{ required: true, message: '请上传上一年度R&D投入专项', trigger: 'change' }],
  129. prove_file: [{ required: false, message: '请上传其他证明资料', trigger: 'change' }],
  130. });
  131. // 系统表单
  132. let fields: Ref<any[]> = ref([
  133. { label: '登录账号', model: 'account', options: { readonly: true } },
  134. { label: '管理员姓名', model: 'name' },
  135. { label: '管理员手机号', model: 'phone' },
  136. { label: '管理员电子邮箱', model: 'email' },
  137. { label: '单位全称', model: 'unit_name' },
  138. { label: '单位地址', model: 'unit_address' },
  139. { label: '营业执照', model: 'prove', custom: true },
  140. { label: '是否入住科学家工作室', model: 'is_studio', type: 'select' },
  141. ]);
  142. // 依托单位信息表单
  143. let ufields: Ref<any[]> = ref([
  144. { label: '单位全称', model: 'company', options: { readonly: true } },
  145. { label: '单位地址', model: 'address', options: { readonly: true } },
  146. { label: '单位法人姓名', model: 'name' },
  147. { label: '单位法人手机号码', model: 'phone' },
  148. { label: '法人身份证', model: 'card', custom: true },
  149. { label: '单位联系人', model: 'unit_contact', options: { readonly: true } },
  150. { label: '单位手机号', model: 'unit_phone', custom: true },
  151. { label: '单位电子邮箱', model: 'unit_email', custom: true },
  152. { label: '行业领域(2)', model: 'fields', type: 'selectMany', options: { placeholder: '请选择(多选,不超过2个)' } },
  153. { label: '技术需求方向', model: 'direction', custom: true },
  154. { label: '上一年度财务审计报告', model: 'audit_report', custom: true },
  155. { label: '上一年度R&D投入专项', model: 'special_report', custom: true },
  156. { label: '其他证明资料', model: 'prove_file', custom: true },
  157. ]);
  158. let limit: Ref<number> = ref(1);
  159. let url: Ref<string> = ref('/files/jcyjdt/unit/upload');
  160. // 用户信息
  161. let user: Ref<{ _id: string; name: string; unit_name: string; account: string; unit_address: string; email: string }> = ref({
  162. _id: '',
  163. name: '',
  164. unit_name: '',
  165. account: '',
  166. unit_address: '',
  167. email: '',
  168. });
  169. // 表单
  170. let form: Ref<{ is_studio: string; prove: Array<[]>; direction: Array<[]> }> = ref({ is_studio: '', prove: [], direction: [] });
  171. let uform: Ref<{
  172. _id: string;
  173. card: Array<any>;
  174. unit_phone: { phone: string; is_show: string };
  175. unit_email: { email: string; is_show: string };
  176. fields: Array<any>;
  177. direction: Array<any>;
  178. audit_report: Array<any>;
  179. special_report: Array<any>;
  180. prove_file: Array<any>;
  181. company: string;
  182. unit_id: string;
  183. unit_contact: string;
  184. address: string;
  185. }> = ref({
  186. _id: '',
  187. card: [],
  188. unit_phone: { phone: '', is_show: '' },
  189. unit_email: { email: '', is_show: '' },
  190. company: '',
  191. unit_id: '',
  192. unit_contact: '',
  193. address: '',
  194. fields: [],
  195. direction: [],
  196. audit_report: [],
  197. special_report: [],
  198. prove_file: [],
  199. });
  200. // 行业领域
  201. let fieldList: Ref<any[]> = ref([]);
  202. // 是否显示
  203. let isshowList: Ref<any[]> = ref([]);
  204. // 工作室
  205. let studioList: Ref<any[]> = ref([]);
  206. // 状态
  207. let statusList: Ref<any[]> = ref([]);
  208. onMounted(async () => {
  209. user.value = store.state.user as { _id: string; name: string; unit_name: string; account: string; unit_address: string; email: string };
  210. await searchOther();
  211. await searchBasic();
  212. await search();
  213. });
  214. // 基本信息查询
  215. const searchBasic = async () => {
  216. let res: IQueryResult = await unit.fetch(user.value._id);
  217. if (res.errcode == 0) {
  218. if (res.data) {
  219. form.value = res.data as { is_studio: ''; prove: []; direction: [] };
  220. }
  221. }
  222. };
  223. // 查询
  224. const search = async () => {
  225. // 查询已申请数据状态
  226. let res: IQueryResult = await unitStudioApply.query({ unit_id: user.value._id });
  227. if (res.errcode == 0) {
  228. if (res.total > 0) {
  229. uform.value = res.data[0] as {
  230. _id: '';
  231. card: [];
  232. unit_phone: { phone: ''; is_show: '' };
  233. unit_email: { email: ''; is_show: '' };
  234. company: '';
  235. unit_id: '';
  236. unit_contact: '';
  237. address: '';
  238. fields: [];
  239. direction: [];
  240. audit_report: [];
  241. special_report: [];
  242. prove_file: [];
  243. };
  244. } else {
  245. if (user && user.value._id) {
  246. uform.value.unit_id = user.value._id;
  247. uform.value.company = user.value.unit_name || '';
  248. uform.value.address = user.value.unit_address || '';
  249. uform.value.unit_contact = user.value.name || '';
  250. uform.value.unit_email = { email: user.value.email || '', is_show: '' };
  251. }
  252. }
  253. }
  254. };
  255. // 改变基础信息关联
  256. const changeForm = (val: { name: string; phone: string; email: string; unit_name: string; unit_address: string }) => {
  257. uform.value.unit_contact = val.name;
  258. uform.value.unit_phone.phone = val.phone;
  259. uform.value.unit_email.email = val.email;
  260. uform.value.company = val.unit_name;
  261. uform.value.address = val.unit_address;
  262. };
  263. // 研究方向添加
  264. const addDriection = () => {
  265. let direction: any = form.value.direction;
  266. if (direction.length >= 5) {
  267. ElMessage({ message: `研究方向最多添加五个`, type: 'error' });
  268. } else {
  269. direction.push({ id: moment().valueOf(), name: '' });
  270. }
  271. form.value.direction = direction;
  272. };
  273. // 研究方向删除
  274. const delDriection = (e: { id: '' }) => {
  275. let direction = form.value.direction.filter((i: any) => i.id != e.id);
  276. form.value.direction = direction;
  277. };
  278. // 依托单位添加
  279. const utoSave = async (data: any) => {
  280. let res: IQueryResult;
  281. if (data.status == '2') data.status = '0';
  282. if (data._id) res = await unitStudioApply.update(data);
  283. else {
  284. res = await unitStudioApply.update(data);
  285. // 入住科学工作室 修改unit表中的is_studio
  286. updateBasic();
  287. }
  288. if (res.errcode == 0) {
  289. ElMessage({ message: `维护信息成功`, type: 'success' });
  290. search();
  291. }
  292. };
  293. // 修改基础信息
  294. const updateBasic = async () => {
  295. let res: IQueryResult = await unit.update({ _id: user.value._id, is_studio: 'Y', account: user.value.account });
  296. console.log(res);
  297. };
  298. // 监听数据
  299. const dataChange = (model: string, value: Array<[]>) => {
  300. if (model == 'fields') {
  301. if (value.length > 2) {
  302. ElMessage({ message: `数据过多,请重新选择`, type: 'error' });
  303. }
  304. }
  305. };
  306. // 基础信息上传
  307. const onChange = (e: { model: string; value: Array<[]> }) => {
  308. const { model, value } = e;
  309. form.value[model] = value;
  310. };
  311. // 依托单位上传
  312. const uonChange = (e: { model: string; value: Array<[]> }) => {
  313. const { model, value } = e;
  314. uform.value[model] = value;
  315. };
  316. // 添加
  317. const toSave = async (data: any) => {
  318. let res: IQueryResult = await unit.update(data);
  319. if (res.errcode == 0) {
  320. // ElMessage({ type: 'success', message: '维护信息成功' });
  321. // 同步修改依托单位信息
  322. let form = {
  323. _id: uform.value._id,
  324. unit_contact: data.name,
  325. unit_phone: { phone: data.phone },
  326. unit_email: { email: data.email },
  327. company: data.unit_name,
  328. address: data.unit_address,
  329. };
  330. await utoSave(form);
  331. await search();
  332. } else ElMessage({ type: 'warning', message: `${res.errmsg}` });
  333. };
  334. // 查询其他信息
  335. const searchOther = async () => {
  336. //是否公开
  337. const p1: IQueryResult = await sysdictdata.query({ dict_type: 's_is_show' });
  338. isshowList.value = p1.data as [];
  339. // 领域
  340. const p2: IQueryResult = await sysdictdata.query({ dict_type: 'studio_field' });
  341. fieldList.value = p2.data as [];
  342. // 是否入住科学家工作室
  343. const p3: IQueryResult = await sysdictdata.query({ dict_type: 'sys_yes_no' });
  344. studioList.value = p3.data as [];
  345. // 审核状态
  346. const p4: IQueryResult = await sysdictdata.query({ dict_type: 'studio_status' });
  347. statusList.value = p4.data as [];
  348. };
  349. watch(
  350. form,
  351. (newVal: any) => {
  352. if (newVal && newVal._id) {
  353. changeForm(newVal);
  354. }
  355. },
  356. {
  357. deep: true,
  358. }
  359. );
  360. </script>
  361. <style lang="scss" scoped>
  362. .main {
  363. .one {
  364. .one_1 {
  365. font-size: 22px;
  366. margin: 10px 0;
  367. }
  368. }
  369. .two {
  370. .two_1 {
  371. font-size: 22px;
  372. margin: 10px 0;
  373. }
  374. }
  375. }
  376. </style>