From 453d8c81962520db1e865357a7557b1b83b30dfd Mon Sep 17 00:00:00 2001
From: yyb <995253665@qq.com>
Date: 星期五, 08 五月 2026 13:55:34 +0800
Subject: [PATCH] 车间管理页面

---
 src/api/basicData/workshop.js                    |   28 ++++
 src/views/basicData/workshopManagement/index.vue |  294 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 322 insertions(+), 0 deletions(-)

diff --git a/src/api/basicData/workshop.js b/src/api/basicData/workshop.js
new file mode 100644
index 0000000..abd7167
--- /dev/null
+++ b/src/api/basicData/workshop.js
@@ -0,0 +1,28 @@
+import request from "@/utils/request";
+
+/** 杞﹂棿鍒嗛〉鏌ヨ POST /workshop/page */
+export function workshopPage(data) {
+  return request({
+    url: "/workshop/page",
+    method: "post",
+    data,
+  });
+}
+
+/** 杞﹂棿鏂板/淇敼 POST /workshop/save */
+export function workshopSave(data) {
+  return request({
+    url: "/workshop/save",
+    method: "post",
+    data,
+  });
+}
+
+/** 杞﹂棿鍒犻櫎 POST /workshop/deleteById/{id} */
+export function workshopDeleteById(id) {
+  return request({
+    url: `/workshop/deleteById/${id}`,
+    method: "post",
+    data: {},
+  });
+}
diff --git a/src/views/basicData/workshopManagement/index.vue b/src/views/basicData/workshopManagement/index.vue
new file mode 100644
index 0000000..f625323
--- /dev/null
+++ b/src/views/basicData/workshopManagement/index.vue
@@ -0,0 +1,294 @@
+<template>
+  <div class="app-container">
+    <div class="search_form">
+      <div>
+        <span class="search_title ml10">杞﹂棿鍚嶇О锛�</span>
+        <el-input
+          v-model="searchForm.name"
+          style="width: 180px"
+          placeholder="璇疯緭鍏ヨ溅闂村悕绉�"
+          clearable
+          @keyup.enter="handleQuery"
+        />
+        <span class="search_title ml10">璐熻矗浜猴細</span>
+        <el-input
+          v-model="searchForm.principal"
+          style="width: 160px"
+          placeholder="璇疯緭鍏ヨ礋璐d汉"
+          clearable
+          @keyup.enter="handleQuery"
+        />
+        <el-button type="primary" @click="handleQuery" style="margin-left: 10px">鎼滅储</el-button>
+        <el-button @click="handleReset">閲嶇疆</el-button>
+        <el-button type="primary" @click="handleAdd" style="margin-left: 10px">鏂板杞﹂棿</el-button>
+      </div>
+    </div>
+    <div class="table_list">
+      <PIMTable
+        rowKey="id"
+        :column="tableColumn"
+        :tableData="tableData"
+        :page="page"
+        height="calc(100vh - 320px)"
+        :tableLoading="tableLoading"
+        :isSelection="false"
+        :isShowPagination="true"
+        @pagination="pagination"
+      />
+    </div>
+    <el-dialog v-model="dialogVisible" :title="dialogTitle" width="520px" @close="onDialogClose">
+      <el-form :model="formData" :rules="rules" ref="formRef" label-width="100px">
+        <el-form-item label="杞﹂棿鍚嶇О" prop="name">
+          <el-input v-model="formData.name" placeholder="璇疯緭鍏ヨ溅闂村悕绉�" maxlength="100" show-word-limit clearable />
+        </el-form-item>
+        <el-form-item label="璐熻矗浜�" prop="principal">
+          <el-input v-model="formData.principal" placeholder="璇疯緭鍏ヨ礋璐d汉" maxlength="100" clearable />
+        </el-form-item>
+        <el-form-item label="鑱旂郴鏂瑰紡" prop="contactPhone">
+          <el-input v-model="formData.contactPhone" placeholder="璇疯緭鍏ヨ仈绯绘柟寮�" maxlength="200" clearable />
+        </el-form-item>
+        <el-form-item label="澶囨敞" prop="remark">
+          <el-input v-model="formData.remark" type="textarea" :rows="3" placeholder="璇疯緭鍏ュ娉�" maxlength="500" show-word-limit />
+        </el-form-item>
+      </el-form>
+      <template #footer>
+        <span class="dialog-footer">
+          <el-button type="primary" @click="handleSubmit">纭畾</el-button>
+          <el-button @click="dialogVisible = false">鍙栨秷</el-button>
+        </span>
+      </template>
+    </el-dialog>
+  </div>
+</template>
+
+<script setup>
+  import { onMounted, reactive, ref } from "vue";
+  import { ElMessage, ElMessageBox } from "element-plus";
+  import PIMTable from "@/components/PIMTable/PIMTable.vue";
+  import { workshopPage, workshopSave, workshopDeleteById } from "@/api/basicData/workshop.js";
+
+  const tableColumn = ref([
+    { label: "杞﹂棿鍚嶇О", prop: "name", minWidth: "140" },
+    { label: "璐熻矗浜�", prop: "principal", minWidth: "120" },
+    { label: "鑱旂郴鏂瑰紡", prop: "contactPhone", minWidth: "160" },
+    { label: "澶囨敞", prop: "remark", minWidth: "160" },
+    {
+      label: "鎿嶄綔",
+      dataType: "action",
+      width: "150",
+      fixed: "right",
+      operation: [
+        {
+          name: "缂栬緫",
+          clickFun: row => handleEdit(row),
+        },
+        {
+          name: "鍒犻櫎",
+          clickFun: row => handleDelete(row),
+        },
+      ],
+    },
+  ]);
+
+  const tableData = ref([]);
+  const tableLoading = ref(false);
+  const page = reactive({
+    current: 1,
+    size: 10,
+    total: 0,
+  });
+
+  const searchForm = reactive({
+    name: "",
+    principal: "",
+  });
+
+  const dialogVisible = ref(false);
+  const dialogTitle = ref("");
+  const formRef = ref(null);
+  const formData = reactive({
+    id: null,
+    name: "",
+    principal: "",
+    contactPhone: "",
+    remark: "",
+  });
+
+  const rules = reactive({
+    name: [{ required: true, message: "璇疯緭鍏ヨ溅闂村悕绉�", trigger: "blur" }],
+    principal: [{ required: true, message: "璇疯緭鍏ヨ礋璐d汉", trigger: "blur" }],
+    contactPhone: [{ required: true, message: "璇疯緭鍏ヨ仈绯绘柟寮�", trigger: "blur" }],
+  });
+
+  const isEdit = ref(false);
+
+  function parsePagePayload(res) {
+    const payload = res?.data;
+    if (!payload) {
+      return { records: [], total: 0 };
+    }
+    if (Array.isArray(payload)) {
+      return { records: payload, total: payload.length };
+    }
+    const records = payload.records ?? payload.list ?? payload.rows ?? [];
+    const total = Number(payload.total ?? payload.totalCount ?? 0);
+    return { records: Array.isArray(records) ? records : [], total };
+  }
+
+  const getList = () => {
+    tableLoading.value = true;
+    workshopPage({
+      name: searchForm.name?.trim() ?? "",
+      principal: searchForm.principal?.trim() ?? "",
+      contactPhone: "",
+      current: page.current,
+      size: page.size,
+    })
+      .then(res => {
+        if (res.code === 200) {
+          const { records, total } = parsePagePayload(res);
+          tableData.value = records;
+          page.total = total;
+        } else {
+          ElMessage.error(res.msg || "鏌ヨ澶辫触");
+        }
+      })
+      .catch(() => {
+        ElMessage.error("鏌ヨ澶辫触");
+      })
+      .finally(() => {
+        tableLoading.value = false;
+      });
+  };
+
+  const handleQuery = () => {
+    page.current = 1;
+    getList();
+  };
+
+  const handleReset = () => {
+    searchForm.name = "";
+    searchForm.principal = "";
+    page.current = 1;
+    getList();
+  };
+
+  const pagination = obj => {
+    page.current = obj.page;
+    page.size = obj.limit;
+    getList();
+  };
+
+  const resetFormModel = () => {
+    formData.id = null;
+    formData.name = "";
+    formData.principal = "";
+    formData.contactPhone = "";
+    formData.remark = "";
+  };
+
+  const handleAdd = () => {
+    isEdit.value = false;
+    dialogTitle.value = "鏂板杞﹂棿";
+    resetFormModel();
+    dialogVisible.value = true;
+  };
+
+  const handleEdit = row => {
+    isEdit.value = true;
+    dialogTitle.value = "缂栬緫杞﹂棿";
+    formData.id = row.id;
+    formData.name = row.name ?? "";
+    formData.principal = row.principal ?? "";
+    formData.contactPhone = row.contactPhone ?? "";
+    formData.remark = row.remark ?? "";
+    dialogVisible.value = true;
+  };
+
+  const handleDelete = row => {
+    ElMessageBox.confirm("纭畾瑕佸垹闄よ杞﹂棿鍚楋紵", "鎻愮ず", {
+      confirmButtonText: "纭畾",
+      cancelButtonText: "鍙栨秷",
+      type: "warning",
+    })
+      .then(() => workshopDeleteById(row.id))
+      .then(() => {
+        ElMessage.success("鍒犻櫎鎴愬姛");
+        getList();
+      })
+      .catch(err => {
+        if (err === "cancel" || err === "close") return;
+        ElMessage.error("鍒犻櫎澶辫触");
+      });
+  };
+
+  const onDialogClose = () => {
+    formRef.value?.resetFields?.();
+  };
+
+  const handleSubmit = () => {
+    formRef.value?.validate(valid => {
+      if (!valid) return;
+      const payload = {
+        id: isEdit.value ? formData.id : null,
+        name: formData.name.trim(),
+        principal: formData.principal.trim(),
+        contactPhone: formData.contactPhone.trim(),
+        remark: (formData.remark || "").trim(),
+      };
+      workshopSave(payload)
+        .then(res => {
+          if (res.code === 200) {
+            ElMessage.success(isEdit.value ? "淇敼鎴愬姛" : "鏂板鎴愬姛");
+            dialogVisible.value = false;
+            getList();
+          } else {
+            ElMessage.error(res.msg || "淇濆瓨澶辫触");
+          }
+        })
+        .catch(() => {
+          ElMessage.error("淇濆瓨澶辫触");
+        });
+    });
+  };
+
+  onMounted(() => {
+    getList();
+  });
+</script>
+
+<style scoped lang="scss">
+  .app-container {
+    padding: 24px;
+    background-color: #f0f2f5;
+    min-height: calc(100vh - 48px);
+  }
+
+  .search_form {
+    display: flex;
+    justify-content: space-between;
+    align-items: center;
+    margin-bottom: 24px;
+    padding: 20px;
+    background-color: #ffffff;
+    border-radius: 6px;
+    box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.05);
+
+    .search_title {
+      color: #606266;
+      font-size: 14px;
+      font-weight: 500;
+    }
+
+    .ml10 {
+      margin-left: 10px;
+    }
+  }
+
+  .table_list {
+    background-color: #ffffff;
+    padding: 16px;
+    border-radius: 6px;
+    box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.05);
+  }
+</style>

--
Gitblit v1.9.3