Browse Source

修改依托单位

zs 2 years ago
parent
commit
36cca4f8cc

+ 78 - 53
src/components/account/unit-1.vue

@@ -20,7 +20,7 @@
           <el-col :span="24" class="two_2">
             <component :is="CForm" :fields="ufields" :rules="rules" :form="uform" labelWidth="auto" @save="utoSave" @dataChange="dataChange">
               <template #card>
-                <component :is="CFile" model="card" limit="2" url="/files/studioadmin/register/upload" :list="uform.card" @change="onChange"></component>
+                <component :is="CFile" model="card" limit="2" url="/files/studioadmin/register/upload" :list="uform.card" @change="uonChange"></component>
               </template>
               <template #unit_phone>
                 <el-col :span="12">
@@ -72,13 +72,13 @@
                 </el-col>
               </template>
               <template #audit_report>
-                <component :is="CFile" model="audit_report" :limit="limit" :url="url" :list="uform.audit_report" @change="onChange"></component>
+                <component :is="CFile" model="audit_report" :limit="limit" :url="url" :list="uform.audit_report" @change="uonChange"></component>
               </template>
               <template #special_report>
-                <component :is="CFile" model="special_report" :limit="limit" :url="url" :list="uform.special_report" @change="onChange"></component>
+                <component :is="CFile" model="special_report" :limit="limit" :url="url" :list="uform.special_report" @change="uonChange"></component>
               </template>
               <template #prove_file>
-                <component :is="CFile" model="prove_file" :limit="limit" :url="url" :list="uform.prove_file" @change="onChange"></component>
+                <component :is="CFile" model="prove_file" :limit="limit" :url="url" :list="uform.prove_file" @change="uonChange"></component>
               </template>
             </component>
           </el-col>
@@ -157,13 +157,12 @@ let ufields: Ref<any[]> = ref([
 ]);
 let limit: Ref<number> = ref(1);
 let url: Ref<string> = ref('/files/jcyjdt/unit/upload');
-let status: Ref<string> = ref('待审中');
 // 用户信息
-let user: Ref<{ _id: string; name: string; unit_name: string; nick_name: string; unit_address: string; email: string }> = ref({
+let user: Ref<{ _id: string; name: string; unit_name: string; account: string; unit_address: string; email: string }> = ref({
   _id: '',
   name: '',
   unit_name: '',
-  nick_name: '',
+  account: '',
   unit_address: '',
   email: '',
 });
@@ -205,56 +204,51 @@ let studioList: Ref<any[]> = ref([]);
 // 状态
 let statusList: Ref<any[]> = ref([]);
 onMounted(async () => {
-  user.value = store.state.user as { _id: string; name: string; unit_name: string; nick_name: string; unit_address: string; email: string };
+  user.value = store.state.user as { _id: string; name: string; unit_name: string; account: string; unit_address: string; email: string };
   await searchOther();
+  await searchBasic();
   await search();
 });
-// 查询
-const search = async () => {
-  let res: IQueryResult;
-  res = await unit.fetch(user.value._id);
+// 基本信息查询
+const searchBasic = async () => {
+  let res: IQueryResult = await unit.fetch(user.value._id);
   if (res.errcode == 0) {
     if (res.data) {
       form.value = res.data as { is_studio: ''; prove: []; direction: [] };
     }
   }
-  let uform: any = {
-    company: '',
-    unit_id: '',
-    unit_contact: '',
-    address: '',
-    card: [],
-    unit_phone: {},
-    unit_email: {},
-    fields: [],
-    direction: [],
-    audit_report: [],
-    special_report: [],
-    prove_file: [],
-  };
-  if (user && user.value._id) {
-    uform.unit_id = user.value._id;
-    uform.company = user.value.unit_name || '';
-    uform.address = user.value.unit_address || '';
-    uform.unit_contact = user.value.name || '';
-    uform.unit_email = { email: user.value.email || '' };
-  }
-  uform.value = uform;
+};
+// 查询
+const search = async () => {
   // 查询已申请数据状态
-  res = await unitStudioApply.query({ unit_id: user.value._id });
-  if (res.errcode == '0') {
+  let res: IQueryResult = await unitStudioApply.query({ unit_id: user.value._id });
+  if (res.errcode == 0) {
     if (res.total > 0) {
-      let data = res.data[0];
-      searchStatus(data.status);
-      uform.value = data;
+      uform.value = res.data[0] as {
+        card: [];
+        unit_phone: { phone: ''; is_show: '' };
+        unit_email: { email: ''; is_show: '' };
+        company: '';
+        unit_id: '';
+        unit_contact: '';
+        address: '';
+        fields: [];
+        direction: [];
+        audit_report: [];
+        special_report: [];
+        prove_file: [];
+      };
+    } else {
+      if (user && user.value._id) {
+        uform.value.unit_id = user.value._id;
+        uform.value.company = user.value.unit_name || '';
+        uform.value.address = user.value.unit_address || '';
+        uform.value.unit_contact = user.value.name || '';
+        uform.value.unit_email = { email: user.value.email || '', is_show: '' };
+      }
     }
   }
 };
-// 状态
-const searchStatus = (e: string) => {
-  let data = statusList.value.find((i) => i.dict_value == e);
-  if (data) status.value = data.dict_label;
-};
 // 改变基础信息关联
 const changeForm = (val: { name: string; phone: string; email: string; unit_name: string; unit_address: string }) => {
   uform.value.unit_contact = val.name;
@@ -279,7 +273,26 @@ const delDriection = (e: { id: '' }) => {
   form.value.direction = direction;
 };
 // 依托单位添加
-const utoSave = () => {};
+const utoSave = async (data: any) => {
+  let res: IQueryResult;
+  if (data.status == '2') data.status = '0';
+  if (data._id) res = await unitStudioApply.update(data);
+  else {
+    res = await unitStudioApply.update(data);
+    // 入住科学工作室 修改unit表中的is_studio
+    updateBasic();
+  }
+  if (res.errcode == 0) {
+    ElMessage({ message: `维护信息成功`, type: 'success' });
+    search();
+  }
+};
+// 修改基础信息
+const updateBasic = async () => {
+  let res: IQueryResult = await unit.update({ _id: user.value._id, is_studio: 'Y', account: user.value.account });
+  console.log(res);
+};
+// 监听数据
 const dataChange = (model: string, value: Array<[]>) => {
   if (model == 'fields') {
     if (value.length > 2) {
@@ -287,18 +300,22 @@ const dataChange = (model: string, value: Array<[]>) => {
     }
   }
 };
-// 上传
+// 基础信息上传
 const onChange = (e: { model: string; value: Array<[]> }) => {
   const { model, value } = e;
   form.value[model] = value;
 };
+// 依托单位上传
+const uonChange = (e: { model: string; value: Array<[]> }) => {
+  const { model, value } = e;
+  uform.value[model] = value;
+};
 // 添加
-const toSave = async (data: { _id: string }) => {
-  let res: IQueryResult;
-  if (data._id) res = await unit.update(data);
-  else res = await unit.create(data);
+const toSave = async (data: object) => {
+  let res: IQueryResult = await unit.update(data);
   if (res.errcode == 0) {
     ElMessage({ type: 'success', message: '维护信息成功' });
+    search();
   } else ElMessage({ type: 'warning', message: `${res.errmsg}` });
 };
 // 查询其他信息
@@ -316,9 +333,17 @@ const searchOther = async () => {
   const p4: IQueryResult = await sysdictdata.query({ dict_type: 'studio_status' });
   statusList.value = p4.data as [];
 };
-watch(form, async (newVal: any) => {
-  if (newVal && newVal._id) changeForm(newVal);
-});
+watch(
+  form,
+  (newVal: any) => {
+    if (newVal && newVal._id) {
+      changeForm(newVal);
+    }
+  },
+  {
+    deep: true,
+  }
+);
 </script>
 <style lang="scss" scoped>
 .main {

+ 11 - 5
src/components/studio-one-green/homeParts2/sidebar-1.vue

@@ -93,12 +93,18 @@ const getMenu = async () => {
     ElMessage({ message: `${res.errmsg}`, type: 'error' });
   }
 };
-watch(user, (newVal) => {
-  if (newVal && newVal._id) {
-    if (newVal && newVal._id) getMenu();
-    else ElMessage({ message: `暂无用户信息,无法获取菜单信息`, type: 'error' });
+watch(
+  user,
+  (newVal) => {
+    if (newVal && newVal._id) {
+      if (newVal && newVal._id) getMenu();
+      else ElMessage({ message: `暂无用户信息,无法获取菜单信息`, type: 'error' });
+    }
+  },
+  {
+    deep: true,
   }
-});
+);
 </script>
 
 <style scoped>