张诺
3 天以前 dd159ea51a7a77bd8cc00c70c0e900f472fb3395
src/views/procureMent/index.vue
@@ -2,36 +2,16 @@
  <div class="app-container">
      <el-form :inline="true" :model="queryParams" class="search-form">
        <el-form-item label="搜索">
          <el-input
            v-model="queryParams.searchText"
            placeholder="请输入关键词"
            clearable
            :style="{ width: '100%' }"
          />
        <el-input v-model="queryParams.searchText" placeholder="请输入关键词" clearable :style="{ width: '100%' }" />
        </el-form-item>
        <el-form-item label="供应商名称">
          <el-input
            v-model="queryParams.supplierName"
            placeholder="请输入"
            clearable
            :style="{ width: '100%' }"
          />
        <el-input v-model="queryParams.supplierName" placeholder="请输入" clearable :style="{ width: '100%' }" />
        </el-form-item>
        <el-form-item label="统一人识别号">
          <el-input
            v-model="queryParams.identifyNumber"
            placeholder="请输入"
            clearable
            :style="{ width: '100%' }"
          />
        <el-input v-model="queryParams.identifyNumber" placeholder="请输入" clearable :style="{ width: '100%' }" />
        </el-form-item>
        <el-form-item label="经营地址">
          <el-input
            v-model="queryParams.address"
            placeholder="请输入"
            clearable
            :style="{ width: '100%' }"
          />
        <el-input v-model="queryParams.address" placeholder="请输入" clearable :style="{ width: '100%' }" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="handleQuery">查询</el-button>
@@ -41,38 +21,17 @@
    <el-card>
      <!-- 操作按钮区 -->
      <el-row :gutter="24" class="table-toolbar">
        <el-button type="primary" :icon="Plus" @click="handleAdd"
          >新建</el-button
        >
        <el-button type="primary" :icon="Plus" @click="handleAdd">新建</el-button>
        <el-button type="danger" :icon="Delete" @click="handleDelete">删除</el-button>
        <el-button type="info" :icon="Download" @click="handleExport">导出</el-button>
      </el-row> 
      <!-- 表格组件 -->
        <data-table
          :loading="loading"
          :table-data="tableData"
          :columns="columns"
          @selection-change="handleSelectionChange"
          @edit="handleEdit"
          @delete="handleDeleteSuccess"
          :show-selection="true"
          :border="true"
          :maxHeight="440"
        />      <pagination
        v-if="total>0"
        :page="pageNum"
        :limit="pageSize"
        :total="total"
        @pagination="handlePagination"
        :layout="'total, prev, pager, next, jumper'"
      />
    </el-card>    <ProductionDialog
        v-model:dialogFormVisible="dialogFormVisible"
        :form="form"
        :title="title"
        @submit="handleSubmit"
        @success="handleSuccess"
      />
      <data-table :loading="loading" :table-data="tableData" :columns="columns" @selection-change="handleSelectionChange"
        @edit="handleEdit" @delete="handleDeleteSuccess" :show-selection="true" :border="true" :maxHeight="440" />
      <pagination v-if="total>0" :page="pageNum" :limit="pageSize" :total="total" @pagination="handlePagination"
        :layout="'total, prev, pager, next, jumper'" />
    </el-card>    <ProductionDialog v-model:copyForm="copyForm" v-model:dialogFormVisible="dialogFormVisible" v-model:form="form" :title="title" @submit="handleSubmit"
      @success="handleSuccess" />
  </div>
</template>
@@ -84,6 +43,8 @@
import Pagination from "@/components/Pagination";
import ProductionDialog from './components/ProductionDialog.vue';
import { purchaseRegistration } from "@/api/procureMent";
import useUserStore from '@/store/modules/user'
const { proxy } = getCurrentInstance()
const dialogFormVisible = ref(false);
const form = ref({});
@@ -94,6 +55,7 @@
const pageNum = ref(1)
const pageSize = ref(10);
const selectedRows = ref([]);
const copyForm = ref({});
// 查询参数
const queryParams = reactive({
  searchText: "",
@@ -113,10 +75,13 @@
  // 这里添加实际的查询逻辑
  getList();
};
const userStore = useUserStore();
onMounted(async() => {
  let res = await userStore.getInfo()
  form.value.registrantId = res.user.userName; // 设置登记人ID
});
// 分页处理
const handlePagination = (val) => {
  console.log("分页参数:", val);
  pageNum.value = val.page;
  pageSize.value = val.limit;
  queryParams.pageNum = val.page;
@@ -127,8 +92,8 @@
// supplier 供应商数据
const columns = ref([
  { prop: "supplierName", label: "供应商名称", minWidth: 200 },
  { prop: "unit", label: "单位", minWidth: 150 },
  { prop: "coal", label: "煤种类型", minWidth: 120 },
  { prop: "unit", label: "单位", minWidth: 150 },
  { prop: "purchaseQuantity", label: "采购数量", minWidth: 100 },
  { prop: "priceIncludingTax", label: "单价(含税)", minWidth: 150 },
  { prop: "totalPriceIncludingTax", label: "总价(含税)", minWidth: 100 },
@@ -145,11 +110,9 @@
      queryParams[key] = "";
    }
  });
  handleQuery();
};
// 新增
const handleAdd = () => {
  console.log("点击新增按钮");
  addOrEdit.value = "add";
  handleAddEdit();
};
@@ -163,28 +126,36 @@
const openDialog = () => {
  if (addOrEdit.value === "edit") {
    // 确保复制一份数据,避免直接引用
    form.value = JSON.parse(JSON.stringify(form.value));
    copyForm.value = JSON.parse(JSON.stringify(form.value));
    dialogFormVisible.value = true;
    return;
  }
  // 新建时初始化表单
  form.value = {
    supplierName: "",
    category: "",
    coal: "",
    unit: "",
    purchaseAmount: "",
    priceBeforeTax: "",
    totalBeforeTax: "",
    calorificValue: "",
    registrant: "",
    purchaseQuantity: "",
    priceExcludingTax: "",
    totalPriceExcludingTax: "",
    priceIncludingTax: "",
    totalPriceIncludingTax: "",
    taxRate: "",
    registrantId: "",
    registrationDate: new Date().toISOString().split('T')[0]
  };  dialogFormVisible.value = true;
  console.log("openDialog 设置 dialogFormVisible =", dialogFormVisible.value);
  };
  // 新建时也需要设置 copyForm 用于重置功能
  copyForm.value = JSON.parse(JSON.stringify(form.value));
  dialogFormVisible.value = true;
};
// 提交表单
const handleSubmit = () => {
  // 拿到提交数据
const handleSubmit = (val) => {
  if (val.result.code !== 200) {
    ElMessage.error("操作失败:" + val.result.msg);
    return;
  }
  ElMessage.success(val.title + val.result.msg);
  dialogFormVisible.value = false;
  getList();
};
@@ -204,7 +175,7 @@
    return;
  }
  ElMessageBox.confirm(
    `确认删除选中的 ${selectedRows.value.length} 条数据吗?`,
    `确定删除选中的数据吗?`,
    "提示",
    {
      confirmButtonText: "确定",
@@ -236,7 +207,6 @@
};
// 成功
const handleSuccess = (val) => {
  console.log(val);
  tableData.value.push(val);
  // getList();
  total.value = tableData.value.length;
@@ -251,13 +221,11 @@
      pageSize: pageSize.value,
      ...queryParams
    });
    console.log("API返回数据:", res);
    if (res && res.data) {
      tableData.value = res.data.records || [];
      total.value = res.data.total || 0;
    }
  } catch (error) {
    console.error("获取数据失败:", error);
    ElMessage.error("获取数据失败");
  } finally {
    loading.value = false;
@@ -310,7 +278,8 @@
  }
}
/* 表格工具栏 */
.table-toolbar, .table-toolbar > * {
.table-toolbar,
.table-toolbar>* {
  margin: 0 0 0 0 !important;
}
.table-toolbar{