张诺
2 天以前 ccd67e291e00a2ad9c29ad8df43de6fab5a4afed
src/views/productionManagement/productionProcess/index.vue
@@ -30,7 +30,9 @@
           class="mb10">
        <el-button type="primary"
                   @click="showNewModal">新增工序</el-button>
        <el-button type="info" plain @click="handleImport">导入</el-button>
        <el-button type="info"
                   plain
                   @click="handleImport">导入</el-button>
        <el-button type="danger"
                   @click="handleDelete"
                   :disabled="selectedRows.length === 0"
@@ -53,29 +55,33 @@
                  v-model:visible="isShowEditModal"
                  :record="record"
                  @completed="getList" />
    <ImportDialog
      ref="importDialogRef"
      v-model="importDialogVisible"
      title="导入工序"
      :action="importAction"
      :headers="importHeaders"
      :auto-upload="false"
      :on-success="handleImportSuccess"
      :on-error="handleImportError"
      @confirm="handleImportConfirm"
      @download-template="handleDownloadTemplate"
      @close="handleImportClose"
    />
    <ImportDialog ref="importDialogRef"
                  v-model="importDialogVisible"
                  title="导入工序"
                  :action="importAction"
                  :headers="importHeaders"
                  :auto-upload="false"
                  :on-success="handleImportSuccess"
                  :on-error="handleImportError"
                  @confirm="handleImportConfirm"
                  @download-template="handleDownloadTemplate"
                  @close="handleImportClose" />
  </div>
</template>
<script setup>
  import { onMounted, ref, reactive, toRefs, getCurrentInstance } from "vue";
  import { onMounted, ref, reactive, toRefs, getCurrentInstance, computed } from "vue";
  import NewProcess from "@/views/productionManagement/productionProcess/New.vue";
  import EditProcess from "@/views/productionManagement/productionProcess/Edit.vue";
  import ImportDialog from "@/components/Dialog/ImportDialog.vue";
  import { listPage, del, importData, downloadTemplate } from "@/api/productionManagement/productionProcess.js";
  import {
    listPage,
    del,
    importData,
    downloadTemplate,
  } from "@/api/productionManagement/productionProcess.js";
  import { getToken } from "@/utils/auth";
  import { getDeviceLedger } from "@/api/equipmentManagement/ledger";
  const data = reactive({
    searchForm: {
@@ -93,16 +99,34 @@
      label: "工序名称",
      prop: "name",
    },
    {
      label: "工序机台",
      prop: "deviceName",
    },
    {
      label: "工序类型",
      prop: "typeText",
    },
    {
      label: "工资定额",
      prop: "salaryQuota",
    },
    // {
    //   label: "工序",
    //   prop: "process",
    // },
    {
      label: "是否质检",
      prop: "isQuality",
      formatData: (params) => {
        return params ? "是" : "否";
      },
    },
    {
      label: "备注",
      prop: "remark",
    },
     {
    {
      label: "更新时间",
      prop: "updateTime",
    },
@@ -125,6 +149,15 @@
  ]);
  const tableData = ref([]);
  const selectedRows = ref([]);
  const deviceList = ref([]);
  const deviceNameMap = computed(() => {
    const map = new Map();
    (deviceList.value || []).forEach((d) => {
      if (d?.id == null) return;
      map.set(d.id, d.deviceName ?? "");
    });
    return map;
  });
  const tableLoading = ref(false);
  const isShowNewModal = ref(false);
  const isShowEditModal = ref(false);
@@ -137,9 +170,19 @@
    total: 0,
  });
  const { proxy } = getCurrentInstance();
  const loadDeviceList = async () => {
    try {
      const res = await getDeviceLedger();
      deviceList.value = Array.isArray(res?.data) ? res.data : [];
    } catch (e) {
      deviceList.value = [];
    }
  };
  // 导入相关配置
  const importAction = import.meta.env.VITE_APP_BASE_API + "/productProcess/importData";
  const importAction =
    import.meta.env.VITE_APP_BASE_API + "/productProcess/importData";
  const importHeaders = { Authorization: "Bearer " + getToken() };
  // 查询列表
@@ -161,9 +204,16 @@
    listPage(params)
      .then(res => {
        tableLoading.value = false;
        tableData.value = res.data.records.map(item => ({
          ...item,
        }));
        const records = Array.isArray(res?.data?.records) ? res.data.records : [];
        const map = deviceNameMap.value;
        tableData.value = records.map(item => {
          const deviceName = item?.deviceName ?? map.get(item?.deviceId) ?? "";
          return {
            ...item,
            deviceName,
            typeText: item.type !== undefined && item.type !== null ? (item.type === 0 ? "计时" : "计件") : "",
          };
        });
        page.total = res.data.total;
      })
      .catch(err => {
@@ -233,9 +283,8 @@
      importDialogRef.value.submit();
    }
  };
  // 导入成功
  const handleImportSuccess = (response) => {
  const handleImportSuccess = response => {
    if (response.code === 200) {
      proxy.$modal.msgSuccess("导入成功");
      importDialogVisible.value = false;
@@ -249,7 +298,7 @@
  };
  // 导入失败
  const handleImportError = (error) => {
  const handleImportError = error => {
    proxy.$modal.msgError("导入失败:" + (error.message || "未知错误"));
  };
@@ -295,7 +344,9 @@
  // };
  onMounted(() => {
    getList();
    loadDeviceList().finally(() => {
      getList();
    });
  });
</script>