yyb
昨天 d2fb1300564eaa8166f4db1184c521e468cd2ed3
src/views/productionManagement/productionProcess/index.vue
@@ -1,17 +1,38 @@
// 工序
<template>
  <div class="app-container">
    <div class="search_form">
      <el-form :model="searchForm"
               :inline="true">
        <el-form-item label="工序名称:">
        <el-form-item label="产品名称:">
          <el-input v-model="searchForm.name"
                    placeholder="请输入"
                    placeholder="请输入产品名称"
                    clearable
                    prefix-icon="Search"
                    style="width: 200px;"
                    @change="handleQuery" />
        </el-form-item>
        <el-form-item label="工序编号:">
        <el-form-item label="部件类型:">
          <el-select v-model="searchForm.type"
                     placeholder="请选择"
                     clearable
                     style="width: 200px;"
                     @change="handleQuery">
            <el-option label="加工"
                       :value="1" />
            <el-option label="刮板冷芯制作"
                       :value="2" />
            <el-option label="管路组对"
                       :value="3" />
            <el-option label="罐体连接及调试"
                       :value="4" />
            <el-option label="测试打压"
                       :value="5" />
            <el-option label="其他"
                       :value="6" />
          </el-select>
        </el-form-item>
        <el-form-item label="部件编号:">
          <el-input v-model="searchForm.no"
                    placeholder="请输入"
                    clearable
@@ -29,11 +50,14 @@
      <div style="text-align: right"
           class="mb10">
        <el-button type="primary"
                   @click="showNewModal">新增工序</el-button>
                   @click="showNewModal">新增部件</el-button>
        <el-button type="info"
                   plain
                   @click="handleImport">导入</el-button>
        <el-button type="danger"
                   @click="handleDelete"
                   :disabled="selectedRows.length === 0"
                   plain>删除工序</el-button>
                   plain>删除部件</el-button>
      </div>
      <PIMTable rowKey="id"
                :column="tableColumn"
@@ -52,38 +76,84 @@
                  v-model:visible="isShowEditModal"
                  :record="record"
                  @completed="getList" />
    <ImportDialog ref="importDialogRef"
                  v-model="importDialogVisible"
                  title="导入部件"
                  :action="importAction"
                  :headers="importHeaders"
                  :loading="importLoading"
                  :disabled="importLoading"
                  :auto-upload="false"
                  :on-progress="handleImportProgress"
                  :on-success="handleImportSuccess"
                  :on-error="handleImportError"
                  @confirm="handleImportConfirm"
                  @download-template="handleDownloadTemplate"
                  @close="handleImportClose" />
  </div>
</template>
<script setup>
  import { onMounted, ref } from "vue";
  import { onMounted, ref, reactive, toRefs, getCurrentInstance } from "vue";
  import NewProcess from "@/views/productionManagement/productionProcess/New.vue";
  import EditProcess from "@/views/productionManagement/productionProcess/Edit.vue";
  import { listPage, del } from "@/api/productionManagement/productionProcess.js";
  import ImportDialog from "@/components/Dialog/ImportDialog.vue";
  import {
    listPage,
    del,
    importData,
    downloadTemplate,
  } from "@/api/productionManagement/productionProcess.js";
  import { getToken } from "@/utils/auth";
  const data = reactive({
    searchForm: {
      name: "",
      type: undefined,
      no: "",
    },
  });
  const { searchForm } = toRefs(data);
  const tableColumn = ref([
    {
      label: "工序名称",
      label: "产品名称",
      prop: "name",
    },
    {
      label: "工序编号",
      label: "产品规格",
      prop: "productModel",
    },
    {
      label: "部件编号",
      prop: "no",
    },
    {
      label: "工资定额",
      label: "部件类型",
      prop: "typeText",
    },
    {
      label: "计划工时(小时)",
      prop: "salaryQuota",
    },
    {
      label: "计划人员",
      prop: "plannerName",
    },
    {
      label: "是否质检",
      prop: "isQuality",
      formatData: (params) => {
        return params ? "是" : "否";
      },
    },
    {
      label: "备注",
      prop: "remark",
    },
    {
      label: "更新时间",
      prop: "updateTime",
    },
    {
      dataType: "action",
@@ -108,12 +178,21 @@
  const isShowNewModal = ref(false);
  const isShowEditModal = ref(false);
  const record = ref({});
  const importDialogVisible = ref(false);
  const importLoading = ref(false);
  const importDialogRef = ref(null);
  const page = reactive({
    current: 1,
    size: 100,
    total: 0,
  });
  const { proxy } = getCurrentInstance();
  // 导入相关配置
  const importAction =
    import.meta.env.VITE_APP_BASE_API + "/productProcess/importData";
  const importHeaders = { Authorization: "Bearer " + getToken() };
  // 查询列表
  /** 搜索按钮操作 */
@@ -136,6 +215,7 @@
        tableLoading.value = false;
        tableData.value = res.data.records.map(item => ({
          ...item,
          typeText: item.type !== undefined && item.type !== null ? (item.type === 1 ? "加工" : item.type === 2 ? "刮板冷芯制作" : item.type === 3 ? "管路组对" : item.type === 4 ? "罐体连接及调试" : item.type === 5 ? "测试打压" : "其他") : "",
        }));
        page.total = res.data.total;
      })
@@ -165,7 +245,7 @@
    if (no.length > 2) {
      proxy.$modal
        .confirm(
          '是否确认删除工序编号为"' +
          '是否确认删除部件编号为"' +
            no[0] +
            "、" +
            no[1] +
@@ -183,7 +263,7 @@
        .catch(() => {});
    } else {
      proxy.$modal
        .confirm('是否确认删除工序编号为"' + no + '"的数据项?')
        .confirm('是否确认删除部件编号为"' + no + '"的数据项?')
        .then(function () {
          return del(ids);
        })
@@ -195,6 +275,71 @@
    }
  }
  // 导入
  const handleImport = () => {
    importDialogVisible.value = true;
  };
  // 确认导入
  const handleImportConfirm = () => {
    if (importDialogRef.value) {
      importDialogRef.value.submit();
    }
  };
  // 导入中
  const handleImportProgress = () => {
    importLoading.value = true;
  };
  // 导入成功
  const handleImportSuccess = response => {
    importLoading.value = false;
    if (response.code === 200) {
      proxy.$modal.msgSuccess("导入成功");
      importDialogVisible.value = false;
      if (importDialogRef.value) {
        importDialogRef.value.clearFiles();
      }
      getList();
    } else {
      proxy.$modal.msgError(response.msg || "导入失败");
    }
  };
  // 导入失败
  const handleImportError = error => {
    importLoading.value = false;
    proxy.$modal.msgError("导入失败:" + (error.message || "未知错误"));
  };
  // 关闭导入弹窗
  const handleImportClose = () => {
    importLoading.value = false;
    if (importDialogRef.value) {
      importDialogRef.value.clearFiles();
    }
  };
  // 下载模板
  const handleDownloadTemplate = async () => {
    try {
      const res = await downloadTemplate();
      const blob = new Blob([res], {
        type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
      });
      const url = window.URL.createObjectURL(blob);
      const link = document.createElement("a");
      link.href = url;
      link.download = "部件导入模板.xlsx";
      link.click();
      window.URL.revokeObjectURL(url);
      proxy.$modal.msgSuccess("模板下载成功");
    } catch (error) {
      proxy.$modal.msgError("模板下载失败");
    }
  };
  // 导出
  // const handleOut = () => {
  //    ElMessageBox.confirm("选中的内容将被导出,是否确认导出?", "导出", {
@@ -203,7 +348,7 @@
  //       type: "warning",
  //    })
  //       .then(() => {
  //          proxy.download("/salesLedger/scheduling/exportTwo", {}, "工序排产.xlsx");
  //          proxy.download("/salesLedger/scheduling/exportTwo", {}, "部件排产.xlsx");
  //       })
  //       .catch(() => {
  //          proxy.$modal.msg("已取消");