Browse Source

fix: 执行方式

lxf 12 hours ago
parent
commit
de5ca4167b
1 changed files with 44 additions and 4 deletions
  1. 44 4
      src/views/old_mini/work_detail/index.vue

+ 44 - 4
src/views/old_mini/work_detail/index.vue

@@ -76,8 +76,8 @@
                         </div>
 
                         <!-- 执行方式 -->
-                        <div class="stage-tabs">
-                            <div v-for="tab in executionTabs" :key="tab.value" class="tab-pill"
+                        <div class="stage-tabs" v-if="hasAnyAvailableExecutionMethod(prescription)">
+                            <div v-for="tab in getAvailableExecutionTabs(prescription)" :key="tab.value" class="tab-pill"
                                 :class="{ active: getStageExecutionMethod(index) === tab.value }"
                                 @click="changeExecutionMethod(index, tab.value)">
                                 {{ tab.label }}
@@ -86,7 +86,7 @@
 
                         <!-- 药物处方表 -->
                         <div class="prescription-wrap"
-                            v-if="prescription.pesticideList && prescription.pesticideList.length">
+                            v-if="prescription.pesticideList && prescription.pesticideList.length && hasAnyAvailableExecutionMethod(prescription)">
                             <div class="prescription-table">
                                 <div class="table-header">
                                     <div class="col col-type">使用功效</div>
@@ -295,6 +295,32 @@ const executionTabs = [
 const stageExecutionMethods = ref({});
 const executePopupRef = ref(null);
 
+const hasTextValue = (val) => {
+    if (val === null || val === undefined) return false;
+    return String(val).trim() !== "";
+};
+
+const hasValidParamForMethod = (item, methodValue) => {
+    if (!item?.params || !Array.isArray(item.params)) return false;
+    const methodParam = item.params.find(
+        (param) => Number(param.executionMethod) === Number(methodValue)
+    );
+    if (!methodParam) return false;
+    return hasTextValue(methodParam.ratio) || hasTextValue(methodParam.remark);
+};
+
+const getAvailableExecutionTabs = (prescription) => {
+    const list = prescription?.pesticideList;
+    if (!Array.isArray(list) || !list.length) return [];
+    return executionTabs.filter((tab) =>
+        list.some((item) => hasValidParamForMethod(item, tab.value))
+    );
+};
+
+const hasAnyAvailableExecutionMethod = (prescription) => {
+    return getAvailableExecutionTabs(prescription).length > 0;
+};
+
 
 const triggerDateText = computed(() => {
     if (!detail.value.executeDate) return "";
@@ -392,8 +418,15 @@ const handleConvert = () => {
 
 // 获取当前段的执行方式
 const getStageExecutionMethod = (stageIndex) => {
+    const stage = stageList.value?.[stageIndex];
+    const availableTabs = getAvailableExecutionTabs(stage);
+    if (!availableTabs.length) return 1;
+
     const val = stageExecutionMethods.value[stageIndex];
-    return val || 1;
+    const isValidSelected = availableTabs.some(
+        (tab) => Number(tab.value) === Number(val)
+    );
+    return isValidSelected ? val : availableTabs[0].value;
 };
 
 // 根据当前执行方式,获取对应的参数(配比、单亩用量、备注)
@@ -411,6 +444,13 @@ const getParamRemark = (item, stageIndex) => {
 };
 
 const changeExecutionMethod = (stageIndex, value) => {
+    const stage = stageList.value?.[stageIndex];
+    const availableTabs = getAvailableExecutionTabs(stage);
+    const isAllowed = availableTabs.some(
+        (tab) => Number(tab.value) === Number(value)
+    );
+    if (!isAllowed) return;
+
     stageExecutionMethods.value = {
         ...stageExecutionMethods.value,
         [stageIndex]: value