From 4929ce0e87c60a2786ceb3bffeea867690920127 Mon Sep 17 00:00:00 2001
From: yuan <123@>
Date: 星期二, 24 三月 2026 17:52:46 +0800
Subject: [PATCH] feat(生产管理): 新增工序设备绑定管理功能

---
 src/views/productionManagement/productionProcess/index.vue |  436 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 434 insertions(+), 2 deletions(-)

diff --git a/src/views/productionManagement/productionProcess/index.vue b/src/views/productionManagement/productionProcess/index.vue
index 67430cb..5bf92e4 100644
--- a/src/views/productionManagement/productionProcess/index.vue
+++ b/src/views/productionManagement/productionProcess/index.vue
@@ -48,6 +48,90 @@
                 @pagination="pagination"
                 :total="page.total"></PIMTable>
     </div>
+
+    <!-- 宸ュ簭鐢熶骇璁板綍鍒楄〃寮规 -->
+    <el-dialog v-model="isShowProcessParamModal"
+               title="鐢熶骇璁板綍"
+               width="800px">
+      <div style="text-align: right"
+           class="mb10">
+        <el-button type="primary"
+                   @click="showSelectProductParamModal">鏂板</el-button>
+        <el-button type="danger"
+                   plain
+                   @click="handleDeleteProcessParam"
+                   :disabled="processParamSelectedRows.length === 0">鎵归噺鍒犻櫎</el-button>
+      </div>
+      <PIMTable rowKey="id"
+                :column="processParamColumns"
+                :tableData="processParamTableData"
+                :page="processParamPage"
+                :isSelection="true"
+                @selection-change="handleProcessParamSelectionChange"
+                @pagination="processParamPagination"
+                :total="processParamPage.total"></PIMTable>
+    </el-dialog>
+
+    <!-- 閫夋嫨鐢熶骇璁板綍寮规 -->
+    <el-dialog v-model="isShowSelectParamModal"
+               title="閫夋嫨鐢熶骇璁板綍"
+               width="800px">
+      <PIMTable rowKey="id"
+                :column="productParamColumns"
+                :tableData="productParamTableData"
+                :page="productParamPage"
+                :isSelection="true"
+                @selection-change="handleProductParamSelectionChange"
+                @pagination="productParamPagination"
+                :total="productParamPage.total"></PIMTable>
+      <template #footer>
+        <div class="dialog-footer">
+          <el-button type="primary"
+                     @click="handleAddProcessParam">纭畾</el-button>
+          <el-button @click="isShowSelectParamModal = false">鍙栨秷</el-button>
+        </div>
+      </template>
+    </el-dialog>
+
+    <!-- 鏌ョ湅璁惧寮规 -->
+    <el-dialog v-model="isShowDeviceModal"
+               title="璁惧鍒楄〃"
+               width="900px">
+      <div style="text-align: right"
+           class="mb10">
+        <el-button type="primary"
+                   @click="showAddDeviceModal">娣诲姞璁惧</el-button>
+      </div>
+      <PIMTable rowKey="id"
+                :column="deviceColumns"
+                :tableData="deviceTableData"
+                :page="devicePage"
+                :isSelection="false"
+                @pagination="devicePagination"
+                :total="devicePage.total"></PIMTable>
+    </el-dialog>
+
+    <!-- 娣诲姞璁惧寮规 -->
+    <el-dialog v-model="isShowSelectDeviceModal"
+               title="閫夋嫨璁惧"
+               width="900px">
+      <PIMTable rowKey="id"
+                :column="selectDeviceColumns"
+                :tableData="selectDeviceTableData"
+                :page="selectDevicePage"
+                :isSelection="true"
+                @selection-change="handleSelectDeviceChange"
+                @pagination="selectDevicePagination"
+                :total="selectDevicePage.total"></PIMTable>
+      <template #footer>
+        <div class="dialog-footer">
+          <el-button type="primary"
+                     @click="handleBindDevices">纭畾</el-button>
+          <el-button @click="isShowSelectDeviceModal = false">鍙栨秷</el-button>
+        </div>
+      </template>
+    </el-dialog>
+
     <new-process v-if="isShowNewModal"
                  v-model:visible="isShowNewModal"
                  @completed="getList" />
@@ -79,7 +163,17 @@
     del,
     importData,
     downloadTemplate,
+    getBindDevices,
+    bindDevices,
+    unbindDevice,
   } from "@/api/productionManagement/productionProcess.js";
+  import {
+    listPage as listProcessParamPage,
+    del as delProcessParam,
+    addProductProcessParameter,
+  } from "@/api/productionManagement/productProcessParameter.js";
+  import { listPage as listProductParamPage } from "@/api/productionManagement/productionRecords.js";
+  import { getLedgerPage } from "@/api/equipmentManagement/ledger.js";
   import { getToken } from "@/utils/auth";
 
   const data = reactive({
@@ -98,10 +192,20 @@
       label: "宸ュ簭鍚嶇О",
       prop: "name",
     },
-
+    {
+      label: "宸ュ簭绫诲瀷",
+      prop: "typeText",
+    },
     {
       label: "宸ヨ祫瀹氶",
       prop: "salaryQuota",
+    },
+    {
+      label: "鏄惁璐ㄦ",
+      prop: "isQuality",
+      formatData: (params) => {
+        return params ? "鏄�" : "鍚�";
+      },
     },
     {
       label: "澶囨敞",
@@ -116,8 +220,22 @@
       label: "鎿嶄綔",
       align: "center",
       fixed: "right",
-      width: 280,
+      width: 350,
       operation: [
+        {
+          name: "鏌ョ湅",
+          type: "text",
+          clickFun: row => {
+            showProcessParamModal(row);
+          },
+        },
+        {
+          name: "鏌ョ湅璁惧",
+          type: "text",
+          clickFun: row => {
+            showDeviceModal(row);
+          },
+        },
         {
           name: "缂栬緫",
           type: "text",
@@ -128,15 +246,127 @@
       ],
     },
   ]);
+  // 宸ュ簭宸茬粦瀹氱殑鐢熶骇璁板綍鍒楄〃鍒楅厤缃�
+  const processParamColumns = ref([
+    { label: "鍙傛暟缂栫爜", prop: "code" },
+    { label: "鍙傛暟椤�", prop: "parameterItem" },
+    {
+      label: "鍙傛暟绫诲瀷",
+      prop: "type",
+      formatData: val => {
+        const dictList = (proxy.useDict && proxy.useDict("parameter_tyep")?.parameter_tyep) || [];
+        const list = dictList.value || dictList;
+        const hit = (list || []).find(d => d.value === val);
+        return hit ? hit.label : val;
+      },
+    },
+    { label: "鍗曚綅", prop: "unit" },
+    { label: "鍙傛暟鏍煎紡", prop: "parameterFormat" },
+    {
+      label: "鏄惁蹇呭~",
+      prop: "isRequired",
+      formatData: v => (v === "1" || v === 1 ? "鏄�" : "鍚�"),
+    },
+  ]);
+  // 鍙�夋嫨鐨勭敓浜ц褰曞垪琛ㄥ垪閰嶇疆
+  const productParamColumns = ref([
+    { label: "鍙傛暟缂栫爜", prop: "code" },
+    { label: "鍙傛暟椤�", prop: "parameterItem" },
+    {
+      label: "鍙傛暟绫诲瀷",
+      prop: "type",
+      formatData: val => {
+        const dictList = (proxy.useDict && proxy.useDict("parameter_tyep")?.parameter_tyep) || [];
+        const list = dictList.value || dictList;
+        const hit = (list || []).find(d => d.value === val);
+        return hit ? hit.label : val;
+      },
+    },
+    { label: "鍗曚綅", prop: "unit" },
+    { label: "鍙傛暟鏍煎紡", prop: "parameterFormat" },
+    {
+      label: "鏄惁蹇呭~",
+      prop: "isRequired",
+      formatData: v => (v === "1" || v === 1 ? "鏄�" : "鍚�"),
+    },
+  ]);
+
+  // 璁惧鍒楄〃鍒楅厤缃�
+  const deviceColumns = ref([
+    { label: "璁惧鍚嶇О", prop: "deviceName" },
+    { label: "瑙勬牸鍨嬪彿", prop: "deviceModel" },
+    { label: "璁惧鍝佺墝", prop: "deviceBrand" },
+    { label: "璁惧绫诲瀷", prop: "type" },
+    { label: "渚涘簲鍟�", prop: "supplierName" },
+    {
+      dataType: "action",
+      label: "鎿嶄綔",
+      align: "center",
+      width: 100,
+      operation: [
+        {
+          name: "鍒犻櫎",
+          type: "text",
+          typeAttrs: { danger: true },
+          clickFun: row => {
+            handleUnbindDevice(row);
+          },
+        },
+      ],
+    },
+  ]);
+
+  // 鍙�夎澶囧垪琛ㄥ垪閰嶇疆
+  const selectDeviceColumns = ref([
+    { label: "璁惧鍚嶇О", prop: "deviceName" },
+    { label: "瑙勬牸鍨嬪彿", prop: "deviceModel" },
+    { label: "璁惧鍝佺墝", prop: "deviceBrand" },
+    { label: "璁惧绫诲瀷", prop: "type" },
+    { label: "渚涘簲鍟�", prop: "supplierName" },
+  ]);
   const tableData = ref([]);
   const selectedRows = ref([]);
   const tableLoading = ref(false);
   const isShowNewModal = ref(false);
   const isShowEditModal = ref(false);
+  const isShowProcessParamModal = ref(false);
+  const isShowSelectParamModal = ref(false);
   const record = ref({});
+  const currentProcess = ref(null);
   const importDialogVisible = ref(false);
   const importDialogRef = ref(null);
   const page = reactive({
+    current: 1,
+    size: 100,
+    total: 0,
+  });
+  const processParamPage = reactive({
+    current: 1,
+    size: 100,
+    total: 0,
+  });
+  const productParamPage = reactive({
+    current: 1,
+    size: 100,
+    total: 0,
+  });
+  const processParamTableData = ref([]);
+  const productParamTableData = ref([]);
+  const processParamSelectedRows = ref([]);
+  const productParamSelectedRows = ref([]);
+
+  // 璁惧鐩稿叧鍙橀噺
+  const isShowDeviceModal = ref(false);
+  const isShowSelectDeviceModal = ref(false);
+  const deviceTableData = ref([]);
+  const selectDeviceTableData = ref([]);
+  const selectedDeviceRows = ref([]);
+  const devicePage = reactive({
+    current: 1,
+    size: 100,
+    total: 0,
+  });
+  const selectDevicePage = reactive({
     current: 1,
     size: 100,
     total: 0,
@@ -160,6 +390,16 @@
     page.size = obj.limit;
     getList();
   };
+  const processParamPagination = obj => {
+    processParamPage.current = obj.page;
+    processParamPage.size = obj.limit;
+    getProcessParamList();
+  };
+  const productParamPagination = obj => {
+    productParamPage.current = obj.page;
+    productParamPage.size = obj.limit;
+    getProductParamList();
+  };
   const getList = () => {
     tableLoading.value = true;
     const params = { ...searchForm.value, ...page };
@@ -169,6 +409,7 @@
         tableLoading.value = false;
         tableData.value = res.data.records.map(item => ({
           ...item,
+          typeText: item.type !== undefined && item.type !== null ? (item.type === 0 ? "璁℃椂" : "璁′欢") : "",
         }));
         page.total = res.data.total;
       })
@@ -181,6 +422,14 @@
     selectedRows.value = selection;
   };
 
+  const handleProcessParamSelectionChange = selection => {
+    processParamSelectedRows.value = selection;
+  };
+
+  const handleProductParamSelectionChange = selection => {
+    productParamSelectedRows.value = selection;
+  };
+
   // 鎵撳紑鏂板寮规
   const showNewModal = () => {
     isShowNewModal.value = true;
@@ -191,6 +440,189 @@
     record.value = row;
   };
 
+  // 鏌ョ湅褰撳墠宸ュ簭鐨勭敓浜ц褰�
+  const showProcessParamModal = row => {
+    currentProcess.value = row;
+    isShowProcessParamModal.value = true;
+    processParamPage.current = 1;
+    getProcessParamList();
+  };
+
+  const getProcessParamList = () => {
+    if (!currentProcess.value) return;
+    const params = {
+      processId: currentProcess.value.id,
+      ...processParamPage,
+    };
+    listProcessParamPage(params).then(res => {
+      processParamTableData.value = res.data.records || [];
+      processParamPage.total = res.data.total || 0;
+    });
+  };
+
+  // 鍒犻櫎褰撳墠宸ュ簭缁戝畾鐨勭敓浜ц褰�
+  const handleDeleteProcessParam = () => {
+    const ids = processParamSelectedRows.value.map(item => item.id);
+    if (!ids.length) {
+      proxy.$modal.msgWarning("璇烽�夋嫨瑕佸垹闄ょ殑璁板綍");
+      return;
+    }
+    proxy.$modal
+        .confirm("鏄惁纭鍒犻櫎閫変腑鐨勭敓浜ц褰曪紵")
+        .then(() => delProcessParam(ids))
+        .then(() => {
+          proxy.$modal.msgSuccess("鍒犻櫎鎴愬姛");
+          getProcessParamList();
+        })
+        .catch(() => {});
+  };
+
+  // 鎵撳紑閫夋嫨鐢熶骇璁板綍寮规
+  const showSelectProductParamModal = () => {
+    isShowSelectParamModal.value = true;
+    productParamPage.current = 1;
+    getProductParamList();
+  };
+
+  const getProductParamList = () => {
+    const params = {
+      ...productParamPage,
+    };
+    listProductParamPage(params).then(res => {
+      const records = res.data.records || [];
+      // 宸茬粦瀹氬埌褰撳墠宸ュ簭鐨勭敓浜ц褰曪紝涓嶅厑璁稿啀娆¢�夋嫨 -> 鏍规嵁鍙傛暟缂栫爜鎵撲笂 disabled 鏍囪
+      const boundCodeSet = new Set(
+          (processParamTableData.value || [])
+              .map(item => item.code ?? item.parameterCode)
+              .filter(code => !!code)
+      );
+      productParamTableData.value = records.map(item => ({
+        ...item,
+        disabled: item.code ? boundCodeSet.has(item.code) : false,
+      }));
+      productParamPage.total = res.data.total || 0;
+    });
+  };
+
+  // 纭缁欏綋鍓嶅伐搴忔柊澧炵敓浜ц褰�
+  const handleAddProcessParam = () => {
+    if (!currentProcess.value) return;
+    const selectedList = productParamSelectedRows.value || [];
+    if (!selectedList.length) {
+      proxy.$modal.msgWarning("璇烽�夋嫨瑕佺粦瀹氱殑鐢熶骇璁板綍");
+      return;
+    }
+    // processId 鏀惧湪璺緞閲岋紝body 鐩存帴浼犻�変腑鐨勭敓浜ц褰曟暟缁�
+    addProductProcessParameter(currentProcess.value.id, selectedList)
+        .then(() => {
+          proxy.$modal.msgSuccess("鏂板鎴愬姛");
+          isShowSelectParamModal.value = false;
+          getProcessParamList();
+        })
+        .catch(() => {});
+  };
+
+  // 鏌ョ湅璁惧寮规
+  const showDeviceModal = row => {
+    currentProcess.value = row;
+    isShowDeviceModal.value = true;
+    devicePage.current = 1;
+    getDeviceList();
+  };
+
+  // 鑾峰彇宸茬粦瀹氱殑璁惧鍒楄〃
+  const getDeviceList = () => {
+    if (!currentProcess.value) return;
+    getBindDevices(currentProcess.value.id)
+      .then(res => {
+        deviceTableData.value = res.data || [];
+        devicePage.total = res.data?.length || 0;
+      })
+      .catch(() => {});
+  };
+
+  // 璁惧鍒楄〃鍒嗛〉
+  const devicePagination = obj => {
+    devicePage.current = obj.page;
+    devicePage.size = obj.limit;
+    getDeviceList();
+  };
+
+  // 瑙g粦璁惧
+  const handleUnbindDevice = row => {
+    if (!currentProcess.value) return;
+    proxy.$modal.confirm("鏄惁纭瑙g粦璇ヨ澶囷紵")
+      .then(() => {
+        return unbindDevice(currentProcess.value.id, row.id);
+      })
+      .then(() => {
+        proxy.$modal.msgSuccess("瑙g粦鎴愬姛");
+        getDeviceList();
+      })
+      .catch(() => {});
+  };
+
+  // 鎵撳紑娣诲姞璁惧寮规
+  const showAddDeviceModal = () => {
+    isShowSelectDeviceModal.value = true;
+    selectDevicePage.current = 1;
+    selectedDeviceRows.value = [];
+    getSelectDeviceList();
+  };
+
+  // 鑾峰彇鍙�夎澶囧垪琛�
+  const getSelectDeviceList = () => {
+    if (!currentProcess.value) return;
+    // 鍏堣幏鍙栧凡缁戝畾鐨勮澶嘔D
+    getBindDevices(currentProcess.value.id)
+      .then(res => {
+        const boundDeviceIds = new Set(
+          (res.data || []).map(item => item.id).filter(id => !!id)
+        );
+        // 鑾峰彇璁惧鍙拌处鍒嗛〉鍒楄〃
+        return getLedgerPage(selectDevicePage).then(deviceRes => {
+          const allDevices = deviceRes.data?.records || [];
+          // 杩囨护鎺夊凡缁戝畾鐨勮澶囷紝骞舵爣璁颁负disabled
+          selectDeviceTableData.value = allDevices.map(item => ({
+            ...item,
+            disabled: boundDeviceIds.has(item.id),
+          }));
+          selectDevicePage.total = deviceRes.data?.total || 0;
+        });
+      })
+      .catch(() => {});
+  };
+
+  // 閫夋嫨璁惧鍙樺寲
+  const handleSelectDeviceChange = selection => {
+    selectedDeviceRows.value = selection;
+  };
+
+  // 閫夋嫨璁惧鍒嗛〉
+  const selectDevicePagination = obj => {
+    selectDevicePage.current = obj.page;
+    selectDevicePage.size = obj.limit;
+    getSelectDeviceList();
+  };
+
+  // 缁戝畾璁惧
+  const handleBindDevices = () => {
+    if (!currentProcess.value) return;
+    const selectedList = selectedDeviceRows.value || [];
+    if (!selectedList.length) {
+      proxy.$modal.msgWarning("璇烽�夋嫨瑕佺粦瀹氱殑璁惧");
+      return;
+    }
+    const deviceIds = selectedList.map(item => item.id);
+    bindDevices(currentProcess.value.id, deviceIds)
+      .then(() => {
+        proxy.$modal.msgSuccess("缁戝畾鎴愬姛");
+        isShowSelectDeviceModal.value = false;
+        getDeviceList();
+      })
+      .catch(() => {});
+  };
+
   // 鍒犻櫎
   function handleDelete() {
     const no = selectedRows.value.map(item => item.no);

--
Gitblit v1.9.3