From 08114b7451615854cb01556a7c477e32e17f520e Mon Sep 17 00:00:00 2001
From: zhuguifei <312353457@qq.com>
Date: 星期五, 03 四月 2026 09:47:04 +0800
Subject: [PATCH] refactor: 调整储丝单柜卷包产量计算逻辑

---
 ruoyi-plus-soybean/src/views/qm/checkitem/modules/checkitem-operate-drawer.vue |  230 ++++++++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 187 insertions(+), 43 deletions(-)

diff --git a/ruoyi-plus-soybean/src/views/qm/checkitem/modules/checkitem-operate-drawer.vue b/ruoyi-plus-soybean/src/views/qm/checkitem/modules/checkitem-operate-drawer.vue
old mode 100644
new mode 100755
index 54c4ccc..529aa4e
--- a/ruoyi-plus-soybean/src/views/qm/checkitem/modules/checkitem-operate-drawer.vue
+++ b/ruoyi-plus-soybean/src/views/qm/checkitem/modules/checkitem-operate-drawer.vue
@@ -1,7 +1,8 @@
 <script setup lang="ts">
 import { computed, ref, watch } from 'vue';
 import { jsonClone } from '@sa/utils';
-import { fetchCreateCheckitem, fetchUpdateCheckitem } from '@/service/api/qm/checkitem';
+import { fetchCreateCheckitem, fetchGetRid, fetchUpdateCheckitem } from '@/service/api/qm/checkitem';
+import { fetchGetInstrumentList } from '@/service/api/md/instrument';
 import { useFormRules, useNaiveForm } from '@/hooks/common/form';
 import { $t } from '@/locales';
 
@@ -14,6 +15,8 @@
   operateType: NaiveUI.TableOperateType;
   /** the edit row data */
   rowData?: Api.Qm.Checkitem | null;
+  /** preset stdCode for add */
+  stdCode?: string | null;
 }
 
 const props = defineProps<Props>();
@@ -39,45 +42,122 @@
   return titles[props.operateType];
 });
 
+const enableOptions = [
+  { label: '鍚敤', value: 1 },
+  { label: '鍋滅敤', value: 0 }
+];
+
+const categoryOptions = [
+  { label: '鎴愬搧', value: 0 },
+  { label: '杈呮枡', value: 1 }
+];
+
+const checkLevelOptions = [
+  { label: 'A', value: 'A' },
+  { label: 'B', value: 'B' },
+  { label: 'C', value: 'C' },
+  { label: 'D', value: 'D' }
+];
+
+const ismixOptions = [
+  { label: '鏄�', value: 1 },
+  { label: '鍚�', value: 0 }
+];
+
+const delOptions = [
+  { label: '姝e父', value: 0 },
+  { label: '鍒犻櫎', value: 1 }
+];
+
 type Model = Api.Qm.CheckitemOperateParams;
 
 const model = ref<Model>(createDefaultModel());
+const ridOptions = ref<{ label: string; value: string | number }[]>([]);
+const instrumentOptions = ref<{ label: string; value: string | number }[]>([]);
+
+async function fetchRidOptions(searchText?: string) {
+  const params: any = {};
+  if (searchText) {
+    params.itemName = searchText;
+  }
+  if (props.stdCode) {
+    params.stdCode = props.stdCode;
+  }
+
+  const { data } = await fetchGetRid(params);
+  if (data) {
+    ridOptions.value = data;
+  } else {
+    ridOptions.value = [];
+  }
+}
+
+function handleRidSelectSearch(query: string) {
+  fetchRidOptions(query);
+}
+
+async function fetchInstrumentOptions(searchText?: string) {
+  const params: any = {};
+  if (searchText) {
+    params.instrumentName = searchText;
+  }
+  const { data } = await fetchGetInstrumentList(params);
+  if (data && data.rows) {
+    instrumentOptions.value = data.rows.map(item => ({
+      label: item.instrumentName,
+      value: item.instrumentCode
+    }));
+  } else {
+    instrumentOptions.value = [];
+  }
+}
+
+function handleInstrumentSelectSearch(query: string) {
+  fetchInstrumentOptions(query);
+}
 
 function createDefaultModel(): Model {
   return {
-      id: '',
-      itemCode: '',
-      itemName: '',
-      unit: '',
-      enable: null,
-      del: null,
-      itemDes: '',
-      stdCode: '',
-      instrumentDes: '',
-      location: '',
-      checkLevel: '',
-      ismix: null,
-      rid: '',
-      category: null,
-      instrumentCode: '',
-      score: null
+    id: '',
+    itemCode: '',
+    itemName: '',
+    unit: '',
+    enable: 1,
+    del: 0,
+    itemDes: '',
+    stdCode: '',
+    instrumentDes: '',
+    location: '',
+    checkLevel: '',
+    ismix: null,
+    rid: null,
+    category: null,
+    instrumentCode: '',
+    score: null
   };
 }
 
-type RuleKey = Extract<
-  keyof Model,
-  | 'id'
->;
+type RuleKey = Extract<keyof Model, 'id'>;
 
 const rules: Record<RuleKey, App.Global.FormRule> = {
-  id: createRequiredRule('缂栫爜涓嶈兘涓虹┖'),
+  id: createRequiredRule('缂栫爜涓嶈兘涓虹┖')
 };
 
-function handleUpdateModelWhenEdit() {
+async function handleUpdateModelWhenEdit() {
   model.value = createDefaultModel();
+  ridOptions.value = []; // Clear options initially
 
   if (props.operateType === 'edit' && props.rowData) {
     Object.assign(model.value, jsonClone(props.rowData));
+  }
+
+  // Fetch options for rid
+  await fetchRidOptions();
+  // Fetch options for instrument
+  await fetchInstrumentOptions();
+
+  if (props.operateType === 'add' && props.stdCode) {
+    model.value.stdCode = props.stdCode;
   }
 }
 
@@ -88,16 +168,68 @@
 async function handleSubmit() {
   await validate();
 
-  const { id, itemCode, itemName, unit, enable, del, itemDes, stdCode, instrumentDes, location, checkLevel, ismix, rid, category, instrumentCode, score } = model.value;
+  const {
+    id,
+    itemCode,
+    itemName,
+    unit,
+    enable,
+    del,
+    itemDes,
+    stdCode,
+    instrumentDes,
+    location,
+    checkLevel,
+    ismix,
+    rid,
+    category,
+    instrumentCode,
+    score
+  } = model.value;
 
   // request
   if (props.operateType === 'add') {
-    const { error } = await fetchCreateCheckitem({ itemCode, itemName, unit, enable, del, itemDes, stdCode, instrumentDes, location, checkLevel, ismix, rid, category, instrumentCode, score });
+    const payload = {
+      itemCode,
+      itemName,
+      unit,
+      enable,
+      del,
+      itemDes,
+      stdCode,
+      instrumentDes,
+      location,
+      checkLevel,
+      ismix,
+      rid,
+      category,
+      instrumentCode,
+      score
+    };
+    const { error } = await fetchCreateCheckitem(payload);
     if (error) return;
   }
 
   if (props.operateType === 'edit') {
-    const { error } = await fetchUpdateCheckitem({ id, itemCode, itemName, unit, enable, del, itemDes, stdCode, instrumentDes, location, checkLevel, ismix, rid, category, instrumentCode, score });
+    const payload = {
+      id,
+      itemCode,
+      itemName,
+      unit,
+      enable,
+      del,
+      itemDes,
+      stdCode,
+      instrumentDes,
+      location,
+      checkLevel,
+      ismix,
+      rid,
+      category,
+      instrumentCode,
+      score
+    };
+    const { error } = await fetchUpdateCheckitem(payload);
     if (error) return;
   }
 
@@ -110,7 +242,6 @@
   if (visible.value) {
     handleUpdateModelWhenEdit();
     restoreValidation();
-    getTreeList();
   }
 });
 </script>
@@ -129,40 +260,53 @@
           <NInput v-model:value="model.unit" placeholder="璇疯緭鍏ュ崟浣�" />
         </NFormItem>
         <NFormItem label="鍚敤" path="enable">
-          <NInput v-model:value="model.enable" placeholder="璇疯緭鍏ュ惎鐢�" />
+          <NSelect v-model:value="model.enable" :options="enableOptions" placeholder="璇烽�夋嫨鍚敤" clearable />
         </NFormItem>
         <NFormItem label="鍒犻櫎" path="del">
-          <NInput v-model:value="model.del" placeholder="璇疯緭鍏ュ垹闄�" />
+          <NSelect v-model:value="model.del" :options="delOptions" placeholder="璇烽�夋嫨鍒犻櫎" clearable />
         </NFormItem>
         <NFormItem label="妫�楠岄」鎻忚堪" path="itemDes">
           <NInput v-model:value="model.itemDes" placeholder="璇疯緭鍏ユ楠岄」鎻忚堪" />
         </NFormItem>
-        <NFormItem label="瑙勭▼浠g爜" path="stdCode">
-          <NInput v-model:value="model.stdCode" placeholder="璇疯緭鍏ヨ绋嬩唬鐮�" />
+        <NFormItem label="妫�娴嬩华鍣�" path="instrumentCode">
+          <NSelect
+            v-model:value="model.instrumentCode"
+            :options="instrumentOptions"
+            placeholder="璇烽�夋嫨妫�娴嬩华鍣�"
+            clearable
+            filterable
+            @search="handleInstrumentSelectSearch"
+            @focus="() => fetchInstrumentOptions()"
+          />
         </NFormItem>
         <NFormItem label="浠櫒鎻忚堪" path="instrumentDes">
           <NInput v-model:value="model.instrumentDes" placeholder="璇疯緭鍏ヤ华鍣ㄦ弿杩�" />
         </NFormItem>
-        <NFormItem label="缂洪櫡浣嶇疆-澶栬鐢�" path="location">
+        <NFormItem label="缂洪櫡浣嶇疆" path="location">
           <NInput v-model:value="model.location" placeholder="璇疯緭鍏ョ己闄蜂綅缃�-澶栬鐢�" />
         </NFormItem>
-        <NFormItem label="鍒咥,B,C,D鍥涗釜绾у埆" path="checkLevel">
-          <NInput v-model:value="model.checkLevel" placeholder="璇疯緭鍏ュ垎A,B,C,D鍥涗釜绾у埆" />
+        <NFormItem label="绾у埆" path="checkLevel">
+          <NSelect v-model:value="model.checkLevel" :options="checkLevelOptions" placeholder="璇烽�夋嫨绾у埆" clearable />
         </NFormItem>
         <NFormItem label="鏄惁鍚堟垚椤�" path="ismix">
-          <NInput v-model:value="model.ismix" placeholder="璇疯緭鍏ユ槸鍚﹀悎鎴愰」" />
+          <NSelect v-model:value="model.ismix" :options="ismixOptions" placeholder="璇烽�夋嫨鏄惁鍚堟垚椤�" clearable />
         </NFormItem>
-        <NFormItem label="鍏宠仈椤笽D" path="rid">
-          <NInput v-model:value="model.rid" placeholder="璇疯緭鍏ュ叧鑱旈」ID" />
+        <NFormItem label="涓婄骇椤�" path="rid">
+          <NSelect
+            v-model:value="model.rid"
+            :options="ridOptions"
+            placeholder="璇烽�夋嫨涓婄骇椤�"
+            clearable
+            filterable
+            @search="handleRidSelectSearch"
+            @focus="() => fetchRidOptions()"
+          />
         </NFormItem>
-        <NFormItem label="绫诲埆 0:鎴愬搧 1杈呮枡" path="category">
-          <NInput v-model:value="model.category" placeholder="璇疯緭鍏ョ被鍒� 0:鎴愬搧 1杈呮枡" />
-        </NFormItem>
-        <NFormItem label="浠櫒缂栫爜" path="instrumentCode">
-          <NInput v-model:value="model.instrumentCode" placeholder="璇疯緭鍏ヤ华鍣ㄧ紪鐮�" />
+        <NFormItem label="绫诲埆" path="category">
+          <NSelect v-model:value="model.category" :options="categoryOptions" placeholder="璇烽�夋嫨绫诲埆" clearable />
         </NFormItem>
         <NFormItem label="鍒嗗��" path="score">
-          <NInput v-model:value="model.score" placeholder="璇疯緭鍏ュ垎鍊�" />
+          <NInputNumber v-model:value="model.score" placeholder="璇疯緭鍏ュ垎鍊�" :precision="2" />
         </NFormItem>
       </NForm>
       <template #footer>

--
Gitblit v1.9.3