张田田 3 месяцев назад
Родитель
Сommit
461315ef6f
1 измененных файлов с 20 добавлено и 12 удалено
  1. 20 12
      src/components/EditSupplier.vue

+ 20 - 12
src/components/EditSupplier.vue

@@ -1,5 +1,5 @@
 <script setup lang="ts">
-import { nextTick, watch, computed, ref, watchEffect } from 'vue';
+import { nextTick, watch, computed, ref, watchEffect, reactive, onBeforeMount } from 'vue';
 import { VxeUI, type VxeFormProps, type VxeFormListeners } from 'vxe-pc-ui';
 import type { SupplierModel } from '@/model/care.model';
 import { useRequest } from 'alova/client';
@@ -175,7 +175,7 @@ const { loading: submitting, send: submit } = useRequest(supplierEditMethod, { i
 const projectList = ref<Array<{ label: string; value: string }>>([]);
 // 线上权益
 const onlineCPList = ref<Array<{ label: string; value: string }>>([]);
-// 营业时间相关方法
+// 营业时间
 // 全选/取消全选
 const selectAllBusinessHours = computed({
   get: () => {
@@ -183,11 +183,13 @@ const selectAllBusinessHours = computed({
     return days.every(day => model.value.businessHours[day]?.enabled);
   },
   set: (value: boolean) => {
+    // 编辑模式下不允许修改
+    if (isEditMode.value) return;
     if (!model.value.businessHours) return;
     days.forEach(day => {
       if (model.value.businessHours[day]) {
         model.value.businessHours[day].enabled = value;
-        // 如果启用日期,初始化时间范围值
+        // 初始化时间范围值
         if (value && !timeRangeValues.value[day]) {
           const dayData = model.value.businessHours[day];
           if (dayData.start && dayData.end) {
@@ -211,6 +213,8 @@ const selectAllBusinessHours = computed({
 
 // 处理单个日期选择
 const handleDayToggle = (day: string) => {
+  // 编辑模式下不允许修改
+  if (isEditMode.value) return;
   if (!model.value.businessHours || !model.value.businessHours[day]) return;
   const wasEnabled = model.value.businessHours[day].enabled;
   model.value.businessHours[day].enabled = !wasEnabled;
@@ -237,6 +241,8 @@ const handleDayToggle = (day: string) => {
 
 // 处理时间范围变化
 const handleTimeRangeChange = (day: string, timeRange: [Dayjs, Dayjs] | null) => {
+  // 编辑模式下不允许修改
+  if (isEditMode.value) return;
   if (!model.value.businessHours || !model.value.businessHours[day]) return;
   if (timeRange && timeRange.length === 2) {
     model.value.businessHours[day].start = timeRange[0].format('HH:mm');
@@ -289,7 +295,7 @@ initTimeRangeValues();
 
 const formRef = ref<any>(null);
 
-// 基础表单项(不包含营业时间)
+
 const baseFormItems = [
   {
     field: 'name',
@@ -473,7 +479,6 @@ const formProps = reactive<VxeFormProps<FormModel>>({
         validator: () => {
           const depts = model.value.collaborateDepts;
           if (!depts || !Array.isArray(depts) || depts.length === 0) {
-            // throw new Error('请选择合作机构');
             notification.error({
               message: '请选择合作机构',
             });
@@ -525,7 +530,11 @@ const showBusinessHours = computed<boolean>(() => {
   return !!(offlineCPTypes && Array.isArray(offlineCPTypes) && offlineCPTypes.length > 0);
 });
 
-// 跟踪线下服务之前的值,用于检测清除后再次选择的情况
+// 判断是否是编辑模式
+const isEditMode = computed<boolean>(() => {
+  return !!(props.data?.id);
+});
+
 const prevOfflineCPTypes = ref<string[] | undefined>(undefined);
 let wasCleared = false;
 
@@ -606,7 +615,6 @@ const formEmits: VxeFormListeners<FormModel> = {
   },
 };
 
-// 统一用 change 事件集中处理(父选子,取消独立),避免在 select 阶段改值导致弹层关闭
 function onDeptChange(
   newVal: Array<{ value: string | number; label: string }>,
   _labels: Array<string>,
@@ -619,7 +627,7 @@ function onDeptChange(
 
   const final = new Set(current);
 
-  // 优先使用组件提供的 triggerValue 判定是否为新增(选中)以及哪一个父节点被点击
+  // 判定是否为新增(选中)
   const triggerValue = String(extra?.triggerValue ?? '');
   const isChecked = !!extra?.checked; // true: 勾选, false: 取消
 
@@ -678,7 +686,7 @@ onBeforeMount(async () => {
   if (props.data?.id) load(props.data);
   await getOnlineCPList();
   await getOfflineCPList();
-  // 初始化线下服务的前一个值
+  // 初始化线下服务
   prevOfflineCPTypes.value = formProps.data?.offlineCPTypes ? [...formProps.data.offlineCPTypes] : undefined;
   // 初始化表单
   updateFormItems();
@@ -701,16 +709,16 @@ onBeforeMount(async () => {
       <template #businessHours>
         <div class="business-hours-container">
           <div class="business-hours-header">
-            <Checkbox v-model:checked="selectAllBusinessHours">全选</Checkbox>
+            <Checkbox v-model:checked="selectAllBusinessHours" :disabled="isEditMode">全选</Checkbox>
           </div>
           <div class="business-hours-list">
             <div v-for="(day, index) in days" :key="day" class="business-hours-item">
-              <Checkbox :checked="model.businessHours?.[day]?.enabled || false" @change="() => handleDayToggle(day)">
+              <Checkbox :checked="model.businessHours?.[day]?.enabled || false" :disabled="isEditMode" @change="() => handleDayToggle(day)">
                 {{ model.dayLabels?.[index] || dayLabels[index] }}
               </Checkbox>
               <div class="time-range-wrapper">
                 <a-time-range-picker :value="timeRangeValues[day]" format="HH:mm"
-                  :disabled="!model.businessHours?.[day]?.enabled"
+                  :disabled="isEditMode || !model.businessHours?.[day]?.enabled"
                   @change="(timeRange: any) => handleTimeRangeChange(day, timeRange)" style="width: 200px" />
               </div>
             </div>