<script setup lang="tsx">
import { NButton, NPopconfirm, NTag } from "naive-ui";
import {
fetchGetChangeLedgerList,fetchBatchDeleteChange,fetchDeleteChange,getDeptOptions,clearDeptCache
} from "@/service/api";
import { $t } from "@/locales";
import { useAppStore } from "@/store/modules/app";
import { useTable, useTableOperate } from "@/hooks/common/table";
import { useAuth } from "@/hooks/business/auth";
import LedgerOperateDrawer from "./modules/ledger-operate-drawer.vue";
import LedgerSearch from "./modules/ledger-search.vue";
import LedgerUploadDrawer from "./modules/ledger-upload-drawer.vue";
import { useBoolean } from "@sa/hooks";
import { canUpgradeRecord } from "@/constants/business";
import { ref, onMounted } from "vue";
import {useDepartment} from "@/hooks/common/useDepartment"
import { exportXlsx, SheetData } from "@/utils/export-excel";
// 使用封装的部门功能
const {
deptLoading,
deptOptions,
} = useDepartment();
const appStore = useAppStore();
const {
columns,
columnChecks,
data,
getData,
loading,
mobilePagination,
searchParams,
resetSearchParams,
} = useTable({
apiFn: fetchGetChangeLedgerList,
showTotal: true,
apiParams: {
current: 1,
size: 10,
// if you want to use the searchParams in Form, you need to define the following properties, and the value is null
// the value can not be undefined, otherwise the property in Form will not be reactive
source: null,
pecoName: null,
peco: null,
softwareChange: null,
projectno: null,
dept: null,
canUpgrade: null,
softResponsiblePerson: null,
elecResponsiblePerson: null,
changeResponsiblePerson: null,
customerDemandTime: null,
softCompletionTime:null,
hardCompletionTime: null,
fmtCustomerDemandTime:null,
fmtSoftCompletionTime:null,
fmtHardCompletionTime: null,
},
columns: () => [
{
type: "selection",
align: "center",
width: 48,
},
{
key: "index",
title: $t("common.index"),
align: "center",
width: 64,
},
{
key: "hwswcoId",
title: $t("page.change.ledger.hwswcoId"),
align: "center",
minWidth: 50,
},
{
key: "source",
title: $t("page.change.ledger.source"),
align: "center",
width: 50,
},
{
key: "pecoName",
title: $t("page.change.ledger.pecoName"),
align: "center",
minWidth: 50,
},
{
key: "peco",
title: $t("page.change.ledger.peco"),
align: "center",
minWidth: 50,
},
{
key: "softwareChange",
title: $t("page.change.ledger.softwareChange"),
align: "center",
minWidth: 150,
},
{
key: "projectno",
title: $t("page.change.ledger.projectno"),
align: "center",
minWidth: 50,
},
{
key: "dept",
title: $t("page.change.ledger.dept"),
align: "center",
width: 130,
render: (row) => {
// 使用部门选项映射部门名称
if (row.dept && deptOptions.value.length > 0) {
const dept = deptOptions.value.find(option => option.value === row.dept);
if (dept) {
return <NTag type="info">{dept.label}</NTag>;
}
}
return null;
},
},
{
key: "softResponsiblePersonName",
title: $t("page.change.ledger.softResponsiblePersonName"),
align: "center",
minWidth: 50,
},
{
key: "elecResponsiblePersonName",
title: $t("page.change.ledger.elecResponsiblePersonName"),
align: "center",
minWidth: 50,
},
// {
// key: "changeResponsiblePerson",
// title: $t("page.change.ledger.changeResponsiblePerson"),
// align: "center",
// minWidth: 50,
// },
{
key: "canUpgrade",
title: $t("page.change.ledger.canUpgrade"),
align: "center",
minWidth: 50,
render: (row) => {
if (row.canUpgrade) {
console.log( row.canUpgrade, canUpgradeRecord[
row.canUpgrade as Api.Change.canUpgrade
])
const label = $t(
canUpgradeRecord[
row.canUpgrade as Api.Change.canUpgrade
]
);
return <NTag type="default">{label}</NTag>;
}
return null;
},
},
{
key: "fmtCustomerDemandTime",
title: $t("page.change.ledger.customerDemandTime"),
align: "center",
minWidth: 50,
},
{
key: "fmtSoftCompletionTime",
title: $t("page.change.ledger.softCompletionTime"),
align: "center",
minWidth: 50,
},
{
key: "fmtHardCompletionTime",
title: $t("page.change.ledger.hardCompletionTime"),
align: "center",
minWidth: 50,
},
// {
// key: "fmtPlanCompletionTime",
// title: $t("page.change.ledger.planCompletionTime"),
// align: "center",
// minWidth: 50,
// },
{
key: "operate",
title: $t("common.operate"),
align: "center",
width: 130,
render: (row) => (
<div class="flex-center gap-8px">
{hasAuth("B_ChangeLedger_Upgrade") ? (
<NButton
type="primary"
ghost
size="small"
onClick={() => window.open (`http://192.168.100.63/pro/hwswco-upgrade-${row.hwswcoId}.html`,"_blank")}
>
{$t("common.upgrade")}
</NButton>
) : null}
{hasAuth("B_ChangeLedger_Assign") ? (
<NButton
type="primary"
ghost
size="small"
onClick={() => window.open(`http://192.168.100.63/pro/hwswco-view-${row.hwswcoId}.html`,"_blank")}
>
{$t("common.assign")}
</NButton>
) : null}
</div>
),
},
],
});
const {
drawerVisible,
operateType,
editingData,
handleAdd,
handleEdit,
handleClone,
checkedRowKeys,
onBatchDeleted,
onDeleted,
// closeDrawer
} = useTableOperate(data, getData);
const { hasAuth } = useAuth();
const { bool: uploadVisible, setTrue: openModal } = useBoolean();
async function handleBatchDelete() {
// request
const { error } = await fetchBatchDeleteChange({
ids: checkedRowKeys.value,
});
if (!error) {
onBatchDeleted();
}
}
async function handleDelete(id: number) {
// request
const { error } = await fetchDeleteChange({ id });
if (!error) {
onDeleted();
}
}
function edit(id: number) {
handleEdit(id);
}
function clone(id: number) {
handleClone(id);
}
async function handleDownload() {
// 请求cosnt {data, error } = await fetchGetProblemList({size:xxx,current:1})
const { data, error } = await fetchGetChangeLedgerList({
size: checkedRowKeys.value.length,
current: 1,
ids: checkedRowKeys.value,
});
if (error) {
console.error("获取数据时出错:", error);
alert("获取数据时发生错误,请稍后再试。");
return;
}
// 翻译表头
const titleMap = {
hwswcoId: $t("page.change.ledger.hwswcoId"),
source: $t("page.change.ledger.source"),
pecoName: $t("page.change.ledger.pecoName"),
peco: $t("page.change.ledger.peco"),
softwareChange:$t("page.change.ledger.softwareChange"),
projectno: $t("page.change.ledger.projectno"),
dept: $t("page.change.ledger.dept"),
softResponsiblePersonName: $t("page.change.ledger.softResponsiblePersonName"),
elecResponsiblePersonName: $t("page.change.ledger.elecResponsiblePersonName"),
canUpgrade: $t("page.change.ledger.canUpgrade"),
customerDemandTime: $t("page.change.ledger.customerDemandTime"),
softCompletionTime: $t("page.change.ledger.softCompletionTime"),
hardCompletionTime: $t("page.change.ledger.hardCompletionTime"),
};
const headers = Object.keys(titleMap).map((key) => titleMap[key]);
const sd = [headers];
data.records.forEach((e) => {
const tmp = [];
Object.keys(titleMap).forEach((key) => {
tmp.push(e[key]);
});
sd.push(tmp);
});
const sheetName = $t("page.change.ledger.title");
const sheets: SheetData[] = [
{
sheetName: sheetName,
data: sd,
},
];
exportXlsx(sheets, `${sheetName}`);
}
// 在页面加载时获取最新数据
getData();
</script>
<template>
<div
class="min-h-500px flex-col-stretch gap-16px overflow-hidden lt-sm:overflow-auto"
>
<LedgerSearch
v-model:model="searchParams"
@reset="resetSearchParams"
@search="getData"
/>
<NCard
:title="$t('page.change.ledger.title')"
:bordered="false"
size="small"
class="sm:flex-1-hidden card-wrapper"
>
<template #header-extra>
<TableHeaderOperation
v-model:columns="columnChecks"
:disabled-delete="checkedRowKeys.length === 0"
:loading="loading"
table-id="api"
@add="handleAdd"
@delete="handleBatchDelete"
@refresh="getData"
>
<template #default>
<NButton size="small" @click="handleDownload" type="primary" ghost>
<template #icon>
<icon-mdi-tray-download
class="text-icon"
:class="{ 'animate-spin': loading }"
/>
</template>
{{ $t("common.download") }}
</NButton>
</template>
</TableHeaderOperation>
</template>
<NDataTable
v-model:checked-row-keys="checkedRowKeys"
:columns="columns"
:data="data"
size="small"
:flex-height="!appStore.isMobile"
:scroll-x="962"
:loading="loading"
remote
:row-key="(row) => row.id"
:pagination="mobilePagination"
class="sm:h-full"
/>
</NCard>
</div>
</template>
<style scoped></style>
下载数据时 ,如何时下载得到的dept列的值是前端展示的值,而不是后台数据库存储的值
最新发布