فهرست منبع

居家/线下项目明确的项目在确认时也不需要再次选择

张田田 10 ماه پیش
والد
کامیت
6d081beb02
2فایلهای تغییر یافته به همراه95 افزوده شده و 14 حذف شده
  1. 0 1
      src/service/AddItems.vue
  2. 95 13
      src/service/ConfirmItems.vue

+ 0 - 1
src/service/AddItems.vue

@@ -405,7 +405,6 @@ function handleSelect(value: string, node: any, extra: any) {
       <a-form-item label="机构名称:" v-if="form?.addType === 'itemsList'" required name="institutionId">
         <a-tree-select
           v-model:value="form.institutionId"
-          show-search
           style="width: 100%"
           :dropdown-style="{ maxHeight: '400px', overflow: 'auto' }"
           placeholder="请选择"

+ 95 - 13
src/service/ConfirmItems.vue

@@ -1,5 +1,5 @@
 <script setup lang="ts">
-import { ref, reactive, watch, onMounted, defineEmits } from 'vue';
+import { ref, reactive, watch, onMounted, defineEmits, nextTick } from 'vue';
 import { message } from 'ant-design-vue';
 import { PlusOutlined } from '@ant-design/icons-vue';
 import { branchMethod } from '@/request/api/system.api';
@@ -20,22 +20,31 @@ const unitOptions = [
   { label: '次', value: '次' },
 ];
 const fileList = ref<UploadFile[]>([]);
-const orgOptions = ref<any[]>([]);
 // 获取所有的机构
-const { data: branch, loading: branchLoading } = useRequest(branchMethod).onSuccess(({ data }) => {
-  if (data?.length > 0) {
-    orgOptions.value = data.map((item: any) => ({
-      label: item.label,
-      value: item.id,
-    }));
-  }
+const branch = ref<any[]>([]);
+const { loading: branchLoading } = useRequest(branchMethod).onSuccess(({ data }) => {
+  const to = (data?: any[]): any[] => {
+    return Array.isArray(data)
+      ? data.map((item) => {
+          return {
+            ...item,
+            value: item.id,
+            key: item.id.toString(),
+            children: to(item.children),
+          };
+        })
+      : [];
+  };
+  branch.value = to(data);
 });
 
 const supplierOptions = ref<any[]>([]);
 // 获取所有的供应商
+const supplierArr = ref<any[]>([]);
 function getSupplier(params: any) {
   getAllSupplierMethod(params).then((res) => {
     if (res?.length > 0) {
+      supplierArr.value = res;
       supplierOptions.value = res.map((item: any) => ({
         label: item.name,
         value: item.id,
@@ -57,6 +66,63 @@ watch(
   },
   { immediate: true }
 );
+let showOffLine = ref<boolean>(false);
+function getIsonline(newSupplierId: any) {
+  // 早期返回:检查必要条件
+  if (!supplierArr.value?.length || !newSupplierId || !props.data?.conditioningProgramType) {
+    return;
+  }
+
+  // 使用 find 替代 filter,性能更好
+  const supplier = supplierArr.value.find(item => item.id === newSupplierId);
+  if (!supplier) {
+    return;
+  }
+
+  const { offlineCPTypes, onlineCPTypes } = supplier;
+  const programType = props.data.conditioningProgramType;
+
+  // 检查是否同时支持线上和线下
+  const supportsOffline = offlineCPTypes?.includes(programType);
+  const supportsOnline = onlineCPTypes?.includes(programType);
+
+  if (supportsOffline && supportsOnline) {
+    showOffLine.value = true;
+    return;
+  }
+
+  // 设置显示状态
+  showOffLine.value = false;
+
+  // 根据支持情况设置项目类型
+  if (supportsOffline) {
+    props.data.isOffline = 'Y';
+  } else if (supportsOnline) {
+    props.data.isOffline = 'N';
+  } else {
+    props.data.isOffline = null;
+  }
+}
+
+watch(
+  () => props.data.conditioningProgramSupplierId,
+  async (newSupplierId: any) => {
+    if (newSupplierId) {
+      // 等待下一个 tick,确保数据更新
+      await nextTick();
+      if (supplierArr.value && supplierArr.value.length > 0) {
+        getIsonline(newSupplierId);
+      } else {
+        // 如果数据还没加载,等待一段时间后重试
+        setTimeout(() => {
+          if (supplierArr.value && supplierArr.value.length > 0) {
+            getIsonline(newSupplierId);
+          }
+        }, 200);
+      }
+    }
+  },
+);
 const uploadProps = reactive({ showRemoveIcon: true });
 function customUpload(e: any) {
   // uploadApi 你的二次封装上传接口
@@ -99,6 +165,9 @@ const emit = defineEmits<{
 }>();
 
 function handleOk() {
+  if (showOffLine.value && !props.data.isOffline) {
+    props.data.isOffline = 'N';
+  }
   confirmOrgConfirmMethod(props.data).then(() => {
     emit('submit', props.data);
     VxeUI.modal.close('confirm-item-modal');
@@ -115,6 +184,7 @@ onMounted(async () => {
   if (props.data.id) {
     const res = await getConditioningSchemeDetailMethod(props.data);
     Object.assign(props.data, res);
+    getIsonline(props.data.conditioningProgramSupplierId);
   }
   fileList.value = props.data?.photo
     ? [
@@ -129,6 +199,10 @@ onMounted(async () => {
     : [];
   isOffline.value = props.data.isOffline === 'Y';
 });
+function handleSelect(value: string, node: any, extra: any) {
+  props.data.institutionId = value;
+  props.data.institutionName = node.label;
+}
 </script>
 
 <template>
@@ -212,13 +286,21 @@ onMounted(async () => {
     </div>
     <div class="form-row">
       <label>机构名称:</label>
-      <a-select v-model:value="data.institutionId" :options="orgOptions" placeholder="请选择机构" style="width: 200px" allow-clear />
+      <a-tree-select
+        v-model:value="data.institutionId"
+        style="width: 400px"
+        :dropdown-style="{ maxHeight: '400px', overflow: 'auto' }"
+        placeholder="请选择"
+        allow-clear
+        tree-default-expand-all
+        :tree-data="branch"
+        @select="handleSelect"
+      ></a-tree-select>
     </div>
     <div class="form-row">
       <label>供应商:</label>
-      <a-select v-model:value="data.conditioningProgramSupplierId" :options="supplierOptions" placeholder="请选择供应商" style="width: 200px" allow-clear class="mr-10" />
-      <a-checkbox v-model:checked="isOffline" style="margin-right: 8px" @change="toggleOnlineStatus"> 线下项目 </a-checkbox>
-    
+      <a-select v-model:value="data.conditioningProgramSupplierId" :options="supplierOptions" placeholder="请选择供应商" style="width: 400px" allow-clear class="mr-10" />
+      <a-checkbox v-model:checked="isOffline" style="margin-right: 8px" @change="toggleOnlineStatus" v-show="showOffLine"> 线下项目 </a-checkbox>
     </div>
     <div class="form-row">
       <label>图片:</label>