maven
8 天以前 4cc27f93a1901e12eb12a198029911c483dd991f
src/views/procureMent/index.vue
@@ -16,13 +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 type="primary" :icon="Plus" @click="handleAddPayable">
          添加应付款
        </el-button>
        <!-- <el-button type="danger" :icon="Delete" @click="handleDelete"
          >删除
        </el-button> -->
      </el-row>
      <!-- 表格组件 -->
      <data-table
@@ -35,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"
@@ -55,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>
@@ -65,17 +80,34 @@
import DataTable from "@/components/Table/ETable.vue";
import Pagination from "@/components/Pagination";
import ProductionDialog from "./components/ProductionDialog.vue";
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);
@@ -84,6 +116,7 @@
const pageSize = ref(10);
const selectedRows = ref([]);
const copyForm = ref({});
const formPayable = ref({});
// 查询参数
const queryParams = reactive({
  searchAll: "",
@@ -100,10 +133,12 @@
// 方法定义
const handleQuery = () => {
  loading.value = true;
   current.value = 1;
   pageSize.value = 10;
  // 这里添加实际的查询逻辑
  getList();
};
const userStore = useUserStore();
// 获取用户信息
const userInfo = ref({});
onMounted(async () => {
@@ -130,6 +165,14 @@
    },
  },
  {
    prop: "type",
    label: "煤料类型",
    minWidth: 120,
    formatter: (row) => {
      return row.type === 1 ? "成品" : "原料";
    },
  },
  {
    prop: "coalId",
    label: "煤种类型",
    minWidth: 120,
@@ -140,9 +183,24 @@
  { 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 },
]);
@@ -150,7 +208,7 @@
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  : "";
  return item ? item.coal || item.supplierName : "";
};
// 获取供应商列表
const supplyRes = ref([]);
@@ -173,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;
@@ -200,9 +280,11 @@
    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));
@@ -229,30 +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);
   handleQuery()
};
// 成功
const handleSuccess = (val) => {
@@ -261,6 +336,12 @@
  total.value = tableData.value.length;
  ElMessage.success("操作成功");
};
const payableHandleSuccess = (val) => {
  ElMessage.success("操作成功");
  dialogPayableFormVisible.value = false;
}
const getList = async () => {
  loading.value = true;
  try {