Просмотр исходного кода

feat: 物资申领通知新增通知分组选择

ai0187 1 месяц назад
Родитель
Сommit
ca5e08e27c

+ 5 - 0
src/components/PersonGroup/SelectGroup.vue

@@ -45,8 +45,13 @@
     });
   };
 
+  const clearValidate = () => {
+    ruleFormRef.value?.resetFields();
+  };
+
   defineExpose({
     validateForm,
+    clearValidate,
   });
 
   onMounted(() => {

+ 1 - 0
src/types/emergency-supplier/index.ts

@@ -213,4 +213,5 @@ export interface NotifyDepartmentForm {
   noticeScope: number; // 通知范围: 1-通知此物资所有需求部门 2-仅通知此物资当前需求部门
   requestTime: string; // 通知领用时间
   requestLocation: string; // 通知领用地点
+  userGroupIds: number[];
 }

+ 37 - 4
src/views/emergency/emergency-supplies/src/components/NotifyDepartmentDialog.vue

@@ -10,6 +10,11 @@
           </el-radio-group>
         </template>
       </BasicForm>
+      <SelectGroup
+        ref="selectGroupRef"
+        :user-group-list="ruleFormData.userGroupIds || []"
+        @user-group-list-change="handleUserGroupListChange"
+      />
     </template>
     <template #footer>
       <el-button @click="basicDialogRef?.closeDialog">取消</el-button>
@@ -23,6 +28,7 @@
   import { ElMessage, ElRadioGroup, ElRadio } from 'element-plus';
   import BasicDialog from '@/components/BasicDialog.vue';
   import BasicForm from '@/components/BasicForm.vue';
+  import SelectGroup from '@/components/PersonGroup/SelectGroup.vue';
   import { useFormConfigHook } from '@/hooks/useFormConfigHook';
   import { NOTIFY_DEPARTMENT_FORM_CONFIG, NOTIFY_DEPARTMENT_FORM_DATA, NOTIFY_DEPARTMENT_FORM_RULES } from '../config';
   import { NOTIFY_RANGE, NOTIFY_RANGE_OPTIONS } from '../constant';
@@ -34,7 +40,7 @@
 
   const basicDialogRef = ref<InstanceType<typeof BasicDialog>>();
   const basicFormRef = ref<InstanceType<typeof BasicForm>>();
-  const tmpDetailId = ref<number | undefined>(undefined);
+  const selectGroupRef = ref<InstanceType<typeof SelectGroup>>();
 
   const { ruleFormConfig, ruleFormData, formRules } = useFormConfigHook(
     NOTIFY_DEPARTMENT_FORM_CONFIG,
@@ -42,6 +48,7 @@
     NOTIFY_DEPARTMENT_FORM_RULES,
   );
 
+  const tmpDetailId = ref<number | undefined>(undefined);
   const notifyRangeOptions = ref<{ label: string; value: number }[]>(NOTIFY_RANGE_OPTIONS);
 
   // 打开对话框
@@ -50,10 +57,20 @@
     basicDialogRef.value?.openDialog();
   };
 
+  // 处理分组列表变化
+  const handleUserGroupListChange = (userGroupIds: number[]) => {
+    ruleFormData.userGroupIds = userGroupIds;
+  };
+
   // 提交表单
   const handleSubmit = async () => {
-    const validate = await basicFormRef.value?.validateForm();
-    if (!validate) return;
+    if (!basicFormRef.value) return;
+    const parentValidateResult = await basicFormRef.value.validateForm();
+    let childValidateResult = true;
+    if (selectGroupRef.value) {
+      childValidateResult = (await selectGroupRef.value.validateForm()) as boolean;
+    }
+    if (!parentValidateResult || !childValidateResult) return;
 
     if (!tmpDetailId.value) {
       ElMessage.error('缺少必要参数');
@@ -66,6 +83,7 @@
         noticeScope: ruleFormData.noticeScope,
         requestTime: ruleFormData.requestTime,
         requestLocation: ruleFormData.requestLocation,
+        userGroupIds: ruleFormData.userGroupIds,
       });
       ElMessage.success('通知成功');
       basicDialogRef.value?.closeDialog();
@@ -74,6 +92,7 @@
       ruleFormData.noticeScope = NOTIFY_RANGE.ALL;
       ruleFormData.requestTime = '';
       ruleFormData.requestLocation = '';
+      ruleFormData.userGroupIds = [];
       // 触发父组件刷新列表
       emits('success');
     } catch (error) {
@@ -85,6 +104,9 @@
   // 刷新表单数据(在对话框打开时调用,用于清除验证状态)
   const refreshFormData = () => {
     basicFormRef.value?.clearValidate();
+    if (selectGroupRef.value) {
+      selectGroupRef.value.clearValidate();
+    }
   };
 
   defineExpose({
@@ -92,4 +114,15 @@
   });
 </script>
 
-<style scoped lang="scss"></style>
+<style scoped lang="scss">
+  .select-group-container {
+    width: 600px;
+    margin: 32px 0;
+
+    :deep(.el-form) {
+      .el-form-item__label {
+        padding: 0;
+      }
+    }
+  }
+</style>

+ 1 - 0
src/views/emergency/emergency-supplies/src/config/form.ts

@@ -434,6 +434,7 @@ export const NOTIFY_DEPARTMENT_FORM_DATA = {
   noticeScope: NOTIFY_RANGE.ALL,
   requestTime: '',
   requestLocation: '',
+  userGroupIds: [] as number[],
 };
 
 // 物资领用通知表单规则