maven
8 天以前 4cc27f93a1901e12eb12a198029911c483dd991f
src/views/procureMent/index.vue
@@ -16,14 +16,16 @@
    </el-form>
    <el-card>
      <!-- 操作按钮区 -->
      <el-row :gutter="24" class="table-toolbar">
      <el-row :gutter="24" class="table-toolbar" justify="space-between">
        <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-button>
        <el-button type="primary" :icon="Plus" @click="handleAddPayable">
          添加应付款
        </el-button>
        <!-- <el-button type="danger" :icon="Delete" @click="handleDelete"
          >删除
        </el-button> -->
      </el-row>
      <!-- 表格组件 -->
      <data-table
@@ -36,7 +38,11 @@
        @delete="handleDeleteSuccess"
        :show-selection="true"
        :border="true"
        :maxHeight="440"
        style="width: 100%; height: calc(100vh - 26em)"
        @viewRow="handleView"
        :operations="['edit', 'viewRow']"
        :operationsWidth="200"
        :show-overflow-tooltip="false"
      />
      <pagination
        v-if="total > 0"
@@ -56,6 +62,14 @@
      @success="handleSuccess"
      ref="productionDialogs"
    />
    <PayableDialog
        v-model:dialogPayableFormVisible="dialogPayableFormVisible"
        v-model:form="formPayable"
        :title="title"
        @submit="handleSubmit"
        @success="payableHandleSuccess"
        ref="productionDialogs">
    </PayableDialog>>
  </div>
</template>
@@ -66,12 +80,34 @@
import DataTable from "@/components/Table/ETable.vue";
import Pagination from "@/components/Pagination";
import ProductionDialog from "./components/ProductionDialog.vue";
import { purchaseRegistration } from "@/api/procureMent";
import PayableDialog from "../payable/components/PayableDialog.vue";
import {
  purchaseRegistration,
  getSupplyList,
  getCoalInfoList,
  delPR
} from "@/api/procureMent";
import { useDelete } from "@/hooks/useDelete";
const userStore = useUserStore();
const dictStore = useDictStore()
import useUserStore from "@/store/modules/user";
import useDictStore from "@/store/modules/dict"
let userList = ref([]);
userStore.getUserList().then((res) => {
  userList.value = res;
});
// 引入字典数据
const { proxy } = getCurrentInstance();
const dialogFormVisible = ref(false);
const form = ref({});
const dialogPayableFormVisible = ref(false);
const form = ref({
  taxRate: 13,
  freight: 20,
});
const title = ref("");
// 状态变量
const loading = ref(false);
@@ -80,6 +116,7 @@
const pageSize = ref(10);
const selectedRows = ref([]);
const copyForm = ref({});
const formPayable = ref({});
// 查询参数
const queryParams = reactive({
  searchAll: "",
@@ -96,10 +133,12 @@
// 方法定义
const handleQuery = () => {
  loading.value = true;
   current.value = 1;
   pageSize.value = 10;
  // 这里添加实际的查询逻辑
  getList();
};
const userStore = useUserStore();
// 获取用户信息
const userInfo = ref({});
onMounted(async () => {
@@ -117,17 +156,63 @@
// supplier 供应商数据
const columns = ref([
  { prop: "supplierName", label: "供应商名称", minWidth: 200 },
  { prop: "coal", label: "煤种类型", minWidth: 120 },
  { prop: "unit", label: "单位", minWidth: 150 },
  {
    prop: "supplierId",
    label: "供应商名称",
    minWidth: 200,
    formatter: (row) => {
      return MatchQuery(row.supplierId, "supplyRes") || "未知供应商";
    },
  },
  {
    prop: "type",
    label: "煤料类型",
    minWidth: 120,
    formatter: (row) => {
      return row.type === 1 ? "成品" : "原料";
    },
  },
  {
    prop: "coalId",
    label: "煤种类型",
    minWidth: 120,
    formatter: (row) => {
      return MatchQuery(row.coalId, "coalRes") || "未知煤种";
    },
  },
  { prop: "purchaseQuantity", label: "采购数量", minWidth: 100 },
  { prop: "priceIncludingTax", label: "单价(含税)", minWidth: 150 },
  { prop: "totalPriceIncludingTax", label: "总价(含税)", minWidth: 100 },
  { prop: "freight", label: "运费", minWidth: 100 },
  { prop: "taxRate", label: "税率", minWidth: 100 },
  { prop: "priceExcludingTax", label: "不含税单价", minWidth: 100 },
  { prop: "registrantId", label: "登记人", minWidth: 100 },
  { prop: "registrantId", label: "登记人", minWidth: 100,
    formatter: (row) => {
      // 匹配用户信息
      const user = userList.value.find((user) => user.userId === row.registrantId);
      return user ? user.nickName : "未知用户";
    },
  },
  { prop: "purchaseType", label: "类型", minWidth: 100 ,
    formatter: (row) => {
      if (row.purchaseType == null) {
        return ""
      }
      const dictItem = dictStore.getDictDataByTypeAndValue("purchase_type", row.purchaseType);
      return dictItem ? dictItem.label : "";    }
  },
  { prop: "registrationDate", label: "登记日期", minWidth: 100 },
]);
// 匹配查询字段
const MatchQuery = (data, name) => {
  const list = name === "supplyRes" ? supplyRes.value.data : coalRes.value.data;
  const item = list.find((items) => items.id == data);
  return item ? item.coal || item.supplierName : "";
};
// 获取供应商列表
const supplyRes = ref([]);
const coalRes = ref([]);
// 重置查询
const resetQuery = () => {
@@ -146,17 +231,39 @@
  addOrEdit.value = "add";
  handleAddEdit();
};
const handleAddPayable = () => {
  // 只有选择一行的时候进行操作
  if (selectedRows.value.length !== 1) {
    ElMessage.error("请选中一行进行填写")
    return
  }
  formPayable.value = {
    purchaseRegistrationId: selectedRows.value[0].id,
    registrantId: userInfo.value.userId,
    ticketNo:"",
    paymentAmount:"",
    payableType:"",
    attachUpload:"",
    registrationDate: new Date().toISOString().split("T")[0],
    fileList:[]
  }
  dialogPayableFormVisible.value = true
};
// 新增编辑
const productionDialogs = ref(null); // 添加ref声明
const handleAddEdit = () => {
  addOrEdit.value == "add" ? (title.value = "新增") : (title.value = "编辑");
  addOrEdit.value == "add" ? (title.value = "新增") : addOrEdit.value == "viewRow" ? (title.value = "查看") : (title.value = "编辑");
  title.value = title.value + "采购信息";
  openDialog();
};
// 打开弹窗
const openDialog = () => {
  if (addOrEdit.value === "edit") {
  if (addOrEdit.value === "edit" || addOrEdit.value === "viewRow") {
    // 确保复制一份数据,避免直接引用
    copyForm.value = JSON.parse(JSON.stringify(form.value));
    dialogFormVisible.value = true;
@@ -167,15 +274,17 @@
  form.value = {
    supplierName: "",
    coal: "",
    unit: "",
    unit: "吨",
    purchaseQuantity: "",
    priceExcludingTax: "",
    totalPriceExcludingTax: "",
    priceIncludingTax: "",
    totalPriceIncludingTax: "",
    taxRate: "",
    registrantId: userInfo.value.userName,
    taxRate: 13,
    freight:20,
    registrantId: userInfo.value.userId,
    registrationDate: new Date().toISOString().split("T")[0],
    purchaseType: ""
  };
  // 新建时也需要设置 copyForm 用于重置功能
  copyForm.value = JSON.parse(JSON.stringify(form.value));
@@ -202,41 +311,23 @@
  addOrEdit.value = "edit";
  handleAddEdit();
};
const handleDelete = () => {
  if (selectedRows.value.length === 0) {
    ElMessage.warning("请选择要删除的数据");
    return;
  }
  ElMessageBox.confirm(`确定删除选中的数据吗?`, "提示", {
    confirmButtonText: "确定",
    cancelButtonText: "取消",
    type: "warning",
  })
    .then(() => {
      // 模拟删除操作
      tableData.value = tableData.value.filter(
        (item) => !selectedRows.value.includes(item)
      );
      total.value = tableData.value.length;
      ElMessage.success("删除成功");
    })
    .catch(() => {
      ElMessage.info("已取消删除");
    });
const handleView = (row) => {
  form.value = JSON.parse(JSON.stringify(row));
  addOrEdit.value = "viewRow";
  handleAddEdit();
};
// 使用删除组合式函数 - 简化版本
const { handleDeleteBatch: handleDelete } = useDelete({
  deleteApi: delPR,
  selectedRows,
  tableData,
  total,
  confirmText: "确定删除选中的采购记录吗?",
  useLocalUpdate: true
});
const handleDeleteSuccess = (row) => {
  ElMessage.success("删除成功:" + row.supplierName);
};
// 导出
const handleExport = (row) => {
  proxy.download(
    "system/post/export",
    {
      ...queryParams.value,
    },
    `post_${new Date().getTime()}.xlsx`
  );
  ElMessage.success("导出数据:" + row.supplierName);
   handleQuery()
};
// 成功
const handleSuccess = (val) => {
@@ -245,9 +336,19 @@
  total.value = tableData.value.length;
  ElMessage.success("操作成功");
};
const payableHandleSuccess = (val) => {
  ElMessage.success("操作成功");
  dialogPayableFormVisible.value = false;
}
const getList = async () => {
  loading.value = true;
  try {
    [supplyRes.value, coalRes.value] = await Promise.all([
      getSupplyList(),
      getCoalInfoList(),
    ]);
    // 传递分页参数
    let res = await purchaseRegistration({
      current: current.value,
@@ -271,6 +372,7 @@
.app-container {
  box-sizing: border-box;
}
.search-form {
  background-color: #fff;
  padding: 20px 20px 0 20px;
@@ -278,6 +380,7 @@
  border-radius: 4px;
  box-shadow: var(--el-box-shadow-light);
}
.search-form :deep(.el-form-item) {
  margin-bottom: 16px;
  width: 100%;
@@ -289,11 +392,13 @@
    width: 50%;
  }
}
@media screen and (min-width: 1200px) {
  .search-form :deep(.el-form-item) {
    width: 18%;
  }
}
.table-toolbar {
  margin-bottom: 20px;
  display: flex;
@@ -306,15 +411,18 @@
  .table-toolbar {
    flex-direction: column;
  }
  .table-toolbar .el-button {
    width: 100%;
  }
}
/* 表格工具栏 */
.table-toolbar,
.table-toolbar > * {
  margin: 0 0 0 0 !important;
}
.table-toolbar {
  margin-bottom: 20px !important;
}