<template>
|
<div class="contract-page art-full-height">
|
<ArtSearchBar
|
v-model="searchForm"
|
:items="searchItems"
|
:showExpand="true"
|
@search="handleSearch"
|
@reset="handleReset"
|
/>
|
|
<ElCard class="art-table-card">
|
<ArtTableHeader v-model:columns="columnChecks" :loading="loading" @refresh="refreshData">
|
<template #left>
|
<ElSpace wrap>
|
<ElButton v-auth="'add'" @click="showDialog('add')" v-ripple>新增合同信息</ElButton>
|
<ElButton
|
v-auth="'delete'"
|
type="danger"
|
:disabled="selectedRows.length === 0"
|
@click="handleBatchDelete"
|
v-ripple
|
>
|
批量删除
|
</ElButton>
|
<ListExportPrint
|
class="inline-flex"
|
:preview-visible="previewVisible"
|
@update:previewVisible="handlePreviewVisibleChange"
|
:report-title="reportTitle"
|
:selected-rows="selectedRows"
|
:query-params="reportQueryParams"
|
:columns="columns"
|
:preview-rows="previewRows"
|
:preview-meta="resolvedPreviewMeta"
|
:total="pagination.total"
|
:disabled="loading"
|
@export="handleExport"
|
@print="handlePrint"
|
/>
|
</ElSpace>
|
</template>
|
</ArtTableHeader>
|
|
<ArtTable
|
:loading="loading"
|
:data="data"
|
:columns="columns"
|
:pagination="pagination"
|
@selection-change="handleSelectionChange"
|
@pagination:size-change="handleSizeChange"
|
@pagination:current-change="handleCurrentChange"
|
/>
|
|
<ContractDialog
|
v-model:visible="dialogVisible"
|
:dialog-type="dialogType"
|
:contract-data="currentContractData"
|
@submit="handleDialogSubmit"
|
/>
|
|
<ContractDetailDrawer
|
v-model:visible="detailDrawerVisible"
|
:loading="detailLoading"
|
:detail="detailData"
|
/>
|
</ElCard>
|
</div>
|
</template>
|
|
<script setup>
|
import { computed, ref } from 'vue'
|
import { ElMessage } from 'element-plus'
|
import { useUserStore } from '@/store/modules/user'
|
import { useAuth } from '@/hooks/core/useAuth'
|
import { useTable } from '@/hooks/core/useTable'
|
import { useCrudPage } from '@/views/system/common/useCrudPage'
|
import { usePrintExportPage } from '@/views/system/common/usePrintExportPage'
|
import ListExportPrint from '@/components/biz/list-export-print/index.vue'
|
import { defaultResponseAdapter } from '@/utils/table/tableUtils'
|
import { guardRequestWithMessage } from '@/utils/sys/requestGuard'
|
import {
|
fetchContractPage,
|
fetchDeleteContract,
|
fetchExportContractReport,
|
fetchGetContractDetail,
|
fetchGetContractMany,
|
fetchSaveContract,
|
fetchUpdateContract
|
} from '@/api/contract'
|
import ContractDialog from './modules/contract-dialog.vue'
|
import ContractDetailDrawer from './modules/contract-detail-drawer.vue'
|
import { createContractTableColumns } from './contractTable.columns'
|
import {
|
buildContractDialogModel,
|
buildContractPageQueryParams,
|
buildContractPrintRows,
|
buildContractReportMeta,
|
buildContractSavePayload,
|
buildContractSearchParams,
|
createContractFormState,
|
createContractSearchState,
|
CONTRACT_REPORT_STYLE,
|
CONTRACT_REPORT_TITLE,
|
getContractPaginationKey,
|
normalizeContractDetailRecord,
|
normalizeContractListRow
|
} from './contractPage.helpers'
|
|
defineOptions({ name: 'Contract' })
|
|
const { hasAuth } = useAuth()
|
const userStore = useUserStore()
|
|
const searchForm = ref(createContractSearchState())
|
const detailDrawerVisible = ref(false)
|
const detailLoading = ref(false)
|
const detailData = ref({})
|
let handleDeleteAction = null
|
|
const reportTitle = CONTRACT_REPORT_TITLE
|
const reportQueryParams = computed(() => buildContractSearchParams(searchForm.value))
|
|
const searchItems = computed(() => [
|
{
|
label: '关键字',
|
key: 'condition',
|
type: 'input',
|
props: {
|
clearable: true,
|
placeholder: '请输入合同编码/名称/项目名称/备注'
|
}
|
},
|
{
|
label: '合同编码',
|
key: 'code',
|
type: 'input',
|
props: {
|
clearable: true,
|
placeholder: '请输入合同编码'
|
}
|
},
|
{
|
label: '合同名称',
|
key: 'name',
|
type: 'input',
|
props: {
|
clearable: true,
|
placeholder: '请输入合同名称'
|
}
|
},
|
{
|
label: '项目名称',
|
key: 'projectName',
|
type: 'input',
|
props: {
|
clearable: true,
|
placeholder: '请输入项目名称'
|
}
|
},
|
{
|
label: '状态',
|
key: 'status',
|
type: 'select',
|
props: {
|
clearable: true,
|
options: [
|
{ label: '正常', value: 1 },
|
{ label: '冻结', value: 0 }
|
]
|
}
|
},
|
{
|
label: '备注',
|
key: 'memo',
|
type: 'input',
|
props: {
|
clearable: true,
|
placeholder: '请输入备注'
|
}
|
}
|
])
|
|
async function openDetail(row) {
|
detailDrawerVisible.value = true
|
detailLoading.value = true
|
try {
|
const detail = await guardRequestWithMessage(fetchGetContractDetail(row.id), {}, {
|
timeoutMessage: '合同信息详情加载超时,已停止等待'
|
})
|
detailData.value = normalizeContractDetailRecord(detail)
|
} catch (error) {
|
detailDrawerVisible.value = false
|
detailData.value = {}
|
ElMessage.error(error?.message || '获取合同信息详情失败')
|
} finally {
|
detailLoading.value = false
|
}
|
}
|
|
async function openEditDialog(row) {
|
try {
|
const detail = await guardRequestWithMessage(fetchGetContractDetail(row.id), {}, {
|
timeoutMessage: '合同信息详情加载超时,已停止等待'
|
})
|
showDialog('edit', detail)
|
} catch (error) {
|
ElMessage.error(error?.message || '获取合同信息详情失败')
|
}
|
}
|
|
const { columns, columnChecks, data, loading, pagination, getData, replaceSearchParams, resetSearchParams, handleSizeChange, handleCurrentChange, refreshData, refreshCreate, refreshUpdate, refreshRemove } =
|
useTable({
|
core: {
|
apiFn: fetchContractPage,
|
apiParams: buildContractPageQueryParams(searchForm.value),
|
paginationKey: getContractPaginationKey(),
|
columnsFactory: () =>
|
createContractTableColumns({
|
handleView: openDetail,
|
handleEdit: hasAuth('update') ? openEditDialog : null,
|
handleDelete: hasAuth('delete') ? (row) => handleDeleteAction?.(row) : null,
|
canEdit: hasAuth('update'),
|
canDelete: hasAuth('delete')
|
})
|
},
|
transform: {
|
dataTransformer: (records) => {
|
if (!Array.isArray(records)) {
|
return []
|
}
|
return records.map((item) => normalizeContractListRow(item))
|
}
|
}
|
})
|
|
const {
|
dialogVisible,
|
dialogType,
|
currentRecord: currentContractData,
|
selectedRows,
|
handleSelectionChange,
|
showDialog,
|
handleDialogSubmit,
|
handleDelete,
|
handleBatchDelete
|
} = useCrudPage({
|
createEmptyModel: () => buildContractDialogModel(createContractFormState()),
|
buildEditModel: (record) => buildContractDialogModel(record),
|
buildSavePayload: (formData) => buildContractSavePayload(formData),
|
saveRequest: fetchSaveContract,
|
updateRequest: fetchUpdateContract,
|
deleteRequest: fetchDeleteContract,
|
entityName: '合同信息',
|
resolveRecordLabel: (record) => record?.code || record?.name || record?.id,
|
refreshCreate,
|
refreshUpdate,
|
refreshRemove
|
})
|
handleDeleteAction = handleDelete
|
|
const buildPreviewMeta = (rows) => {
|
const now = new Date()
|
return {
|
reportDate: now.toLocaleDateString('zh-CN'),
|
printedAt: now.toLocaleString('zh-CN', { hour12: false }),
|
operator: userStore.getUserInfo?.name || userStore.getUserInfo?.username || '',
|
count: rows.length,
|
reportStyle: { ...CONTRACT_REPORT_STYLE }
|
}
|
}
|
|
const resolvePrintRecords = async (payload) => {
|
if (Array.isArray(payload?.ids) && payload.ids.length > 0) {
|
return defaultResponseAdapter(await fetchGetContractMany(payload.ids)).records
|
}
|
return defaultResponseAdapter(
|
await fetchContractPage({
|
...reportQueryParams.value,
|
current: 1,
|
pageSize: Number(pagination.total) > 0 ? Number(pagination.total) : Number(payload?.pageSize) || 20
|
})
|
).records
|
}
|
|
const { previewVisible, previewRows, previewMeta, handlePreviewVisibleChange, handleExport, handlePrint } =
|
usePrintExportPage({
|
downloadFileName: 'contract.xlsx',
|
requestExport: (payload) =>
|
fetchExportContractReport(payload, {
|
headers: {
|
Authorization: userStore.accessToken || ''
|
}
|
}),
|
resolvePrintRecords,
|
buildPreviewRows: (records) => buildContractPrintRows(records),
|
buildPreviewMeta
|
})
|
|
const resolvedPreviewMeta = computed(() =>
|
buildContractReportMeta({
|
previewMeta: previewMeta.value,
|
count: previewRows.value.length,
|
orientation: previewMeta.value?.reportStyle?.orientation || CONTRACT_REPORT_STYLE.orientation
|
})
|
)
|
|
function handleSearch(params) {
|
replaceSearchParams(buildContractSearchParams(params))
|
getData()
|
}
|
|
function handleReset() {
|
Object.assign(searchForm.value, createContractSearchState())
|
resetSearchParams()
|
}
|
</script>
|