2131e99ec4
- 新增路由 /business/contract-manage/detail,详情页共享合同管理组件 - 列表、表单、详情三分支用 isFormPage 和 isDetailPage 控制 - openDetail 方法改为跳转详情路由,initDetailPage 获取详情数据 - 新增 resetDetailState 和 closeDetailPage 方法,复用关闭逻辑 - 详情页去除弹窗高度限制,样式改为页面自滚动 - 详情页底栏使用固定位置关闭按钮,保持页面布局一致 - watch 和 created 中添加对 isDetailPage 的初始化调用和监听
859 lines
27 KiB
Vue
859 lines
27 KiB
Vue
<template>
|
||
<basic-container class="temporary-credit-limit-page">
|
||
<avue-crud
|
||
ref="crud"
|
||
v-model="form"
|
||
v-model:page="page"
|
||
:data="data"
|
||
:option="tableOption"
|
||
:permission="permissionList"
|
||
:table-loading="loading"
|
||
:before-open="beforeOpen"
|
||
@row-save="rowSave"
|
||
@row-update="rowUpdate"
|
||
@row-del="rowDel"
|
||
@search-change="searchChange"
|
||
@search-reset="searchReset"
|
||
@selection-change="selectionChange"
|
||
@current-change="currentChange"
|
||
@size-change="sizeChange"
|
||
@refresh-change="refreshChange"
|
||
@on-load="onLoad"
|
||
>
|
||
<template #menu-left>
|
||
<el-button v-if="canCreate" type="primary" icon="el-icon-plus" @click="$refs.crud.rowAdd()">
|
||
新增
|
||
</el-button>
|
||
<el-button
|
||
v-if="config.exportUrl && hasPermission(`${config.permission}_export`)"
|
||
type="primary"
|
||
icon="el-icon-download"
|
||
plain
|
||
@click="handleExport"
|
||
>
|
||
批量导出
|
||
</el-button>
|
||
<el-button
|
||
v-if="hasPermission(`${config.permission}_delete`)"
|
||
type="danger"
|
||
icon="el-icon-delete"
|
||
plain
|
||
@click="handleDelete"
|
||
>
|
||
批量删除
|
||
</el-button>
|
||
</template>
|
||
|
||
<template #approvalStatus="{ row }">
|
||
<el-tag :type="statusTagType(row.approvalStatus)" class="status-text">
|
||
{{ displayStatus(row, 'approvalStatus') }}
|
||
</el-tag>
|
||
</template>
|
||
|
||
<template #projectName-label>项目额度信息</template>
|
||
|
||
<template #projectName-form>
|
||
<el-select
|
||
v-model="selectedProjectId"
|
||
class="temporary-credit-limit-page__field"
|
||
placeholder="请选择"
|
||
filterable
|
||
clearable
|
||
:loading="projectLoading"
|
||
:disabled="dialogReadonly"
|
||
@visible-change="visible => visible && loadProjectOptions()"
|
||
@change="handleProjectChange"
|
||
>
|
||
<el-option
|
||
v-for="item in projectOptions"
|
||
:key="item.id"
|
||
:label="item.projectName"
|
||
:value="item.id"
|
||
/>
|
||
</el-select>
|
||
</template>
|
||
|
||
<template #applyLimit-form>
|
||
<el-input
|
||
v-model="form.applyLimit"
|
||
class="temporary-credit-limit-page__field"
|
||
placeholder="请输入"
|
||
:disabled="dialogReadonly"
|
||
@input="handleAmountInput"
|
||
/>
|
||
</template>
|
||
|
||
<template #attachmentsJson-form>
|
||
<div class="temporary-credit-limit-page__attachment">
|
||
<div class="temporary-credit-limit-page__attachment-head">
|
||
<el-button type="primary" :disabled="!attachmentRows.length" @click="batchDownload">
|
||
批量下载
|
||
</el-button>
|
||
</div>
|
||
<el-table :data="attachmentRows" border @selection-change="selectedAttachments = $event">
|
||
<el-table-column type="selection" width="55" align="center" />
|
||
<el-table-column type="index" label="序号" width="70" align="center" />
|
||
<el-table-column label="文件名" min-width="240" show-overflow-tooltip>
|
||
<template #default="{ row }">
|
||
<el-link type="primary" @click="previewAttachment(row)">
|
||
{{ attachmentName(row) }}
|
||
</el-link>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="文件大小" width="120" align="center">
|
||
<template #default="{ row }">{{ formatFileSize(row.size) }}</template>
|
||
</el-table-column>
|
||
<el-table-column prop="uploadUserName" label="上传人" width="140" align="center" />
|
||
<el-table-column prop="uploadTime" label="上传时间" width="180" align="center" />
|
||
<el-table-column label="操作" width="100" align="center" fixed="right">
|
||
<template #default="{ row, $index }">
|
||
<el-link v-if="!dialogReadonly" type="danger" @click="removeAttachment($index)">
|
||
删除
|
||
</el-link>
|
||
<el-link v-else type="primary" @click="downloadAttachment(row)">下载</el-link>
|
||
</template>
|
||
</el-table-column>
|
||
</el-table>
|
||
<div class="temporary-credit-limit-page__attachment-upload">
|
||
<vehicle-attachment-upload
|
||
v-model="attachmentRows"
|
||
:readonly="dialogReadonly"
|
||
:file-types="attachmentFileTypes"
|
||
:max-size="50"
|
||
:show-file-list="false"
|
||
button-text="上传附件"
|
||
tip="支持pdf、bmp、jpeg、png、jpg、doc、docx、ppt、pptx、xlsx、xls、eml、msg、zip的文件格式,单个文件不超过50M"
|
||
@change="handleAttachmentChange"
|
||
/>
|
||
</div>
|
||
</div>
|
||
</template>
|
||
|
||
<template #menu-form-before>
|
||
<el-button
|
||
v-if="!dialogReadonly"
|
||
type="primary"
|
||
plain
|
||
:loading="draftLoading"
|
||
@click="saveDraft"
|
||
>
|
||
保存
|
||
</el-button>
|
||
</template>
|
||
|
||
<template #menu="{ row }">
|
||
<el-link
|
||
v-if="hasPermission(`${config.permission}_view`)"
|
||
type="primary"
|
||
@click="$refs.crud.rowView(row)"
|
||
>
|
||
查看
|
||
</el-link>
|
||
<el-link v-if="canEdit(row)" type="primary" @click="$refs.crud.rowEdit(row)">
|
||
编辑
|
||
</el-link>
|
||
<el-link
|
||
v-for="operation in customOperations(row)"
|
||
:key="operation.action"
|
||
:type="operation.type || 'primary'"
|
||
@click="handleOperation(operation, row)"
|
||
>
|
||
{{ operation.label }}
|
||
</el-link>
|
||
<el-link v-if="canDelete(row)" type="danger" @click="rowDel(row)">删除</el-link>
|
||
</template>
|
||
</avue-crud>
|
||
|
||
<empty-pagination
|
||
:page="page"
|
||
@size-change="sizeChange"
|
||
@current-change="currentChange"
|
||
@load="onLoad(page, query)"
|
||
/>
|
||
|
||
<el-dialog
|
||
v-model="attachmentDocumentPreviewVisible"
|
||
:title="attachmentPreviewFile.name || '附件预览'"
|
||
append-to-body
|
||
destroy-on-close
|
||
width="90%"
|
||
top="4vh"
|
||
class="temporary-credit-limit-page__attachment-viewer-dialog"
|
||
>
|
||
<open-file-viewer
|
||
v-if="attachmentDocumentPreviewVisible && attachmentPreviewFile.url"
|
||
:file="attachmentPreviewFile.url"
|
||
:file-name="attachmentPreviewFile.name"
|
||
:mime-type="attachmentPreviewFile.mimeType"
|
||
width="100%"
|
||
height="72vh"
|
||
fit="contain"
|
||
theme="auto"
|
||
locale="zh-CN"
|
||
:toolbar="attachmentViewerToolbar"
|
||
:plugins="attachmentViewerPlugins"
|
||
@unsupported="handleAttachmentPreviewUnsupported"
|
||
@error="handleAttachmentPreviewError"
|
||
/>
|
||
</el-dialog>
|
||
<el-image-viewer
|
||
v-if="attachmentImagePreviewVisible"
|
||
:url-list="attachmentImagePreviewUrls"
|
||
:initial-index="attachmentImagePreviewIndex"
|
||
@close="attachmentImagePreviewVisible = false"
|
||
/>
|
||
|
||
<flow-design-step
|
||
v-if="website.design.designMode"
|
||
v-model:is-display="flowBox"
|
||
:process-instance-id="processInstanceId"
|
||
/>
|
||
<el-dialog v-else v-model="flowBox" title="流程图" append-to-body fullscreen>
|
||
<iframe class="temporary-credit-limit-page__flow" :src="flowUrl" />
|
||
<template #footer><el-button @click="flowBox = false">关闭</el-button></template>
|
||
</el-dialog>
|
||
</basic-container>
|
||
</template>
|
||
|
||
<script>
|
||
import { exportBlob } from '@/api/common';
|
||
import * as api from '@/api/business/temporary-credit-limit';
|
||
import {
|
||
getDetail as getProjectDetail,
|
||
getList as getProjectList,
|
||
} from '@/api/business/project-apply';
|
||
import { config, option } from '@/option/business/temporary-credit-limit';
|
||
import { getToken } from '@/utils/auth';
|
||
import { downloadFileByUrl, downloadXls } from '@/utils/util';
|
||
import { ElImageViewer } from 'element-plus';
|
||
import { OpenFileViewer } from '@open-file-viewer/vue';
|
||
import {
|
||
fallbackPlugin,
|
||
imagePlugin,
|
||
officePlugin,
|
||
pdfPlugin,
|
||
textPlugin,
|
||
} from '@open-file-viewer/core';
|
||
import '@open-file-viewer/core/style.css';
|
||
import pdfWorkerSrc from 'pdfjs-dist/build/pdf.worker.mjs?url';
|
||
import { mapGetters } from 'vuex';
|
||
import NProgress from 'nprogress';
|
||
import 'nprogress/nprogress.css';
|
||
|
||
const attachmentFileTypes = [
|
||
'pdf',
|
||
'bmp',
|
||
'jpeg',
|
||
'png',
|
||
'jpg',
|
||
'doc',
|
||
'docx',
|
||
'ppt',
|
||
'pptx',
|
||
'xlsx',
|
||
'xls',
|
||
'eml',
|
||
'msg',
|
||
'zip',
|
||
];
|
||
|
||
const attachmentViewerPlugins = [
|
||
imagePlugin(),
|
||
pdfPlugin({ workerSrc: pdfWorkerSrc, useFetchData: true }),
|
||
officePlugin({ pdf: { workerSrc: pdfWorkerSrc, useFetchData: true } }),
|
||
textPlugin(),
|
||
fallbackPlugin(),
|
||
];
|
||
|
||
const extractRecords = res => {
|
||
const data = res?.data?.data || res?.data || {};
|
||
return Array.isArray(data) ? data : data.records || [];
|
||
};
|
||
|
||
export default {
|
||
name: 'TemporaryCreditLimit',
|
||
components: {
|
||
ElImageViewer,
|
||
OpenFileViewer,
|
||
},
|
||
data() {
|
||
return {
|
||
api,
|
||
config,
|
||
form: {},
|
||
data: [],
|
||
query: {},
|
||
loading: true,
|
||
draftLoading: false,
|
||
dialogReadonly: false,
|
||
tableOption: this.buildTableOption(),
|
||
page: {
|
||
currentPage: 1,
|
||
pageSize: 10,
|
||
pageSizes: [10, 20, 50, 100],
|
||
total: 0,
|
||
},
|
||
selectionList: [],
|
||
selectedProjectId: '',
|
||
projectOptions: [],
|
||
projectLoading: false,
|
||
attachmentRows: [],
|
||
selectedAttachments: [],
|
||
attachmentImagePreviewVisible: false,
|
||
attachmentImagePreviewUrls: [],
|
||
attachmentImagePreviewIndex: 0,
|
||
attachmentDocumentPreviewVisible: false,
|
||
attachmentPreviewFile: {},
|
||
attachmentViewerPlugins,
|
||
attachmentViewerToolbar: {
|
||
download: true,
|
||
fullscreen: true,
|
||
print: true,
|
||
rotate: true,
|
||
zoom: true,
|
||
},
|
||
attachmentFileTypes,
|
||
flowBox: false,
|
||
flowUrl: '',
|
||
processInstanceId: '',
|
||
};
|
||
},
|
||
computed: {
|
||
...mapGetters(['permission', 'userInfo']),
|
||
permissionList() {
|
||
return { addBtn: this.canCreate };
|
||
},
|
||
isAdmin() {
|
||
const authority = this.userInfo?.authority;
|
||
return Array.isArray(authority)
|
||
? authority.includes('admin')
|
||
: String(authority || '').includes('admin');
|
||
},
|
||
canCreate() {
|
||
return this.hasPermission(`${this.config.permission}_add`);
|
||
},
|
||
ids() {
|
||
return this.selectionList.map(item => item.id).join(',');
|
||
},
|
||
},
|
||
created() {
|
||
this.loadProjectOptions();
|
||
},
|
||
methods: {
|
||
buildTableOption() {
|
||
return {
|
||
...option,
|
||
addBtn: false,
|
||
viewBtn: false,
|
||
editBtn: false,
|
||
delBtn: false,
|
||
menuWidth: 320,
|
||
column: (option.column || []).map(column => ({ ...column })),
|
||
};
|
||
},
|
||
hasPermission(code) {
|
||
return this.isAdmin || this.validData(this.permission?.[code], false);
|
||
},
|
||
statusValue(row) {
|
||
return row[this.config.statusProp || 'status'];
|
||
},
|
||
statusTagType(status) {
|
||
if (['approved', 'change_approved'].includes(status)) return 'success';
|
||
if (['draft', 'withdrawn'].includes(status)) return 'info';
|
||
if (['rejected', 'change_rejected'].includes(status)) return 'danger';
|
||
return 'warning';
|
||
},
|
||
displayStatus(row, prop) {
|
||
const textProp = prop === this.config.statusProp ? this.config.statusTextProp : '';
|
||
if (textProp && row[textProp]) return row[textProp];
|
||
const column = this.findColumn(this.tableOption.column, prop);
|
||
const item = column?.dicData?.find(dic => String(dic.value) === String(row[prop]));
|
||
return item?.label || row[prop] || '未知';
|
||
},
|
||
canEdit(row) {
|
||
return (
|
||
this.hasPermission(`${this.config.permission}_edit`) &&
|
||
!row.readonly &&
|
||
(this.config.editStatus || []).includes(this.statusValue(row))
|
||
);
|
||
},
|
||
canDelete(row) {
|
||
return (
|
||
this.hasPermission(`${this.config.permission}_delete`) &&
|
||
!row.readonly &&
|
||
(this.config.deleteStatus || []).includes(this.statusValue(row))
|
||
);
|
||
},
|
||
customOperations(row) {
|
||
return (this.config.operations || []).filter(operation => {
|
||
const permission = operation.permission || `${this.config.permission}_${operation.action}`;
|
||
const statusProp = operation.statusProp || this.config.statusProp || 'status';
|
||
return (
|
||
this.hasPermission(permission) &&
|
||
!row.readonly &&
|
||
(!operation.status?.length || operation.status.includes(row[statusProp]))
|
||
);
|
||
});
|
||
},
|
||
onLoad(page, params = {}) {
|
||
this.loading = true;
|
||
this.api
|
||
.getList(page.currentPage, page.pageSize, { ...params, ...this.query })
|
||
.then(res => {
|
||
const result = res.data?.data || {};
|
||
this.page.total = result.total || 0;
|
||
this.data = result.records || [];
|
||
this.selectionClear();
|
||
})
|
||
.finally(() => {
|
||
this.loading = false;
|
||
});
|
||
},
|
||
searchChange(params, done) {
|
||
this.query = { ...params };
|
||
this.page.currentPage = 1;
|
||
this.onLoad(this.page);
|
||
done();
|
||
},
|
||
searchReset() {
|
||
this.query = {};
|
||
this.page.currentPage = 1;
|
||
this.onLoad(this.page);
|
||
},
|
||
selectionChange(list) {
|
||
this.selectionList = list;
|
||
},
|
||
selectionClear() {
|
||
this.selectionList = [];
|
||
this.$refs.crud?.toggleSelection();
|
||
},
|
||
currentChange(currentPage) {
|
||
this.page.currentPage = currentPage;
|
||
},
|
||
sizeChange(pageSize) {
|
||
this.page.pageSize = pageSize;
|
||
},
|
||
refreshChange() {
|
||
this.onLoad(this.page, this.query);
|
||
},
|
||
beforeOpen(done, type) {
|
||
this.dialogReadonly = type === 'view';
|
||
if (type === 'add') {
|
||
this.form = { ...(this.config.defaultForm || {}) };
|
||
this.selectedProjectId = '';
|
||
this.attachmentRows = [];
|
||
this.selectedAttachments = [];
|
||
done();
|
||
return;
|
||
}
|
||
this.api
|
||
.getDetail(this.form.id)
|
||
.then(res => this.applyDetail(res.data?.data || {}))
|
||
.finally(done);
|
||
},
|
||
applyDetail(detail) {
|
||
this.form = { ...detail };
|
||
this.selectedProjectId = detail.projectId || '';
|
||
this.attachmentRows = this.parseJsonArray(detail.attachmentsJson);
|
||
this.selectedAttachments = [];
|
||
this.syncCurrentProjectOption();
|
||
},
|
||
normalizeForm(row = this.form) {
|
||
return {
|
||
...row,
|
||
applyLimit: row.applyLimit === '' ? '' : Number(row.applyLimit),
|
||
attachmentsJson: JSON.stringify(this.attachmentRows),
|
||
};
|
||
},
|
||
rowSave(row, done, loading) {
|
||
this.api
|
||
.submit(this.normalizeForm(row))
|
||
.then(() => {
|
||
this.$message.success('新增成功');
|
||
done();
|
||
this.onLoad(this.page, this.query);
|
||
})
|
||
.catch(() => loading());
|
||
},
|
||
rowUpdate(row, index, done, loading) {
|
||
this.api
|
||
.submit(this.normalizeForm(row))
|
||
.then(() => {
|
||
this.$message.success('修改成功');
|
||
done();
|
||
this.onLoad(this.page, this.query);
|
||
})
|
||
.catch(() => loading());
|
||
},
|
||
saveDraft() {
|
||
if (this.draftLoading) return;
|
||
this.draftLoading = true;
|
||
this.api
|
||
.saveDraft(this.normalizeForm())
|
||
.then(() => {
|
||
this.$message.success('保存成功');
|
||
this.$refs.crud?.closeDialog();
|
||
this.onLoad(this.page, this.query);
|
||
})
|
||
.finally(() => {
|
||
this.draftLoading = false;
|
||
});
|
||
},
|
||
rowDel(row) {
|
||
this.removeRows([row]);
|
||
},
|
||
handleDelete() {
|
||
if (!this.selectionList.length) {
|
||
this.$message.warning('请选择至少一条数据');
|
||
return;
|
||
}
|
||
const rows = this.selectionList.filter(this.canDelete);
|
||
if (!rows.length) {
|
||
this.$message.warning('所选数据当前状态不可删除');
|
||
return;
|
||
}
|
||
this.removeRows(rows);
|
||
},
|
||
removeRows(rows) {
|
||
this.$confirm('确定将选择数据删除?', '提示', {
|
||
confirmButtonText: '确定',
|
||
cancelButtonText: '取消',
|
||
type: 'warning',
|
||
})
|
||
.then(() => this.api.remove(rows.map(row => row.id).join(',')))
|
||
.then(() => {
|
||
this.$message.success('删除成功');
|
||
this.onLoad(this.page, this.query);
|
||
});
|
||
},
|
||
handleOperation(operation, row) {
|
||
if (operation.action === 'flow') {
|
||
this.openFlow(row);
|
||
return;
|
||
}
|
||
this.$confirm(`确定${operation.label}该${this.config.title}?`, '提示', {
|
||
confirmButtonText: '确定',
|
||
cancelButtonText: '取消',
|
||
type: 'warning',
|
||
})
|
||
.then(() => this.api[operation.action](row.id))
|
||
.then(() => {
|
||
this.$message.success(`${operation.label}成功`);
|
||
this.onLoad(this.page, this.query);
|
||
});
|
||
},
|
||
openFlow(row, loaded = false) {
|
||
const processInstanceId = row.processInstanceId || row.processInstanceID || row.procInstId;
|
||
if (!processInstanceId && !loaded && row.id) {
|
||
this.api.getDetail(row.id).then(res => this.openFlow(res.data?.data || {}, true));
|
||
return;
|
||
}
|
||
if (!processInstanceId) {
|
||
this.$message.warning('流程实例为空,无法查看流程');
|
||
return;
|
||
}
|
||
if (this.website.design.designMode) this.processInstanceId = processInstanceId;
|
||
else
|
||
this.flowUrl = `/api/blade-flow/process/diagram-view?processInstanceId=${processInstanceId}`;
|
||
this.flowBox = true;
|
||
},
|
||
loadProjectOptions() {
|
||
if (this.projectLoading) return;
|
||
this.projectLoading = true;
|
||
getProjectList(1, 9999, this.config.projectQueryParams || {})
|
||
.then(res => {
|
||
this.projectOptions = extractRecords(res);
|
||
this.syncCurrentProjectOption();
|
||
})
|
||
.finally(() => {
|
||
this.projectLoading = false;
|
||
});
|
||
},
|
||
syncCurrentProjectOption() {
|
||
if (!this.form.projectId || !this.form.projectName) return;
|
||
if (this.projectOptions.some(item => String(item.id) === String(this.form.projectId))) return;
|
||
this.projectOptions.unshift({
|
||
id: this.form.projectId,
|
||
projectName: this.form.projectName,
|
||
projectCode: this.form.projectCode,
|
||
undertakeDeptName: this.form.undertakeDeptName,
|
||
fundLimit: this.form.projectFundLimit,
|
||
});
|
||
},
|
||
handleProjectChange(projectId) {
|
||
const project = this.projectOptions.find(item => String(item.id) === String(projectId));
|
||
if (!project) {
|
||
Object.assign(this.form, {
|
||
projectId: '',
|
||
projectName: '',
|
||
projectCode: '',
|
||
undertakeDeptName: '',
|
||
projectFundLimit: '',
|
||
usedFundLimit: 0,
|
||
remainingFundLimit: 0,
|
||
});
|
||
return;
|
||
}
|
||
Object.assign(this.form, {
|
||
projectId: project.id,
|
||
projectName: project.projectName || '',
|
||
projectCode: project.projectCode || '',
|
||
undertakeDeptName: project.undertakeDeptName || '',
|
||
projectFundLimit: project.fundLimit || project.projectFundLimit || 0,
|
||
usedFundLimit: project.usedFundLimit || 0,
|
||
});
|
||
this.form.remainingFundLimit = this.calculateRemainingFundLimit();
|
||
getProjectDetail(project.id).then(res => {
|
||
const detail = res.data?.data || {};
|
||
Object.assign(this.form, {
|
||
projectCode: detail.projectCode || this.form.projectCode,
|
||
undertakeDeptName: detail.undertakeDeptName || this.form.undertakeDeptName,
|
||
projectFundLimit:
|
||
detail.fundLimit ?? detail.projectFundLimit ?? this.form.projectFundLimit,
|
||
usedFundLimit: detail.usedFundLimit ?? this.form.usedFundLimit,
|
||
});
|
||
this.form.remainingFundLimit = this.calculateRemainingFundLimit();
|
||
});
|
||
},
|
||
calculateRemainingFundLimit() {
|
||
const total = Number(this.form.projectFundLimit);
|
||
const used = Number(this.form.usedFundLimit);
|
||
if (!Number.isFinite(total) || !Number.isFinite(used)) return '';
|
||
return Math.round((total - used + Number.EPSILON) * 100) / 100;
|
||
},
|
||
handleAmountInput(value) {
|
||
const text = String(value || '').replace(/[^\d.]/g, '');
|
||
const parts = text.split('.');
|
||
this.form.applyLimit =
|
||
parts.length > 1 ? `${parts[0]}.${parts.slice(1).join('').slice(0, 2)}` : parts[0];
|
||
},
|
||
handleAttachmentChange(list) {
|
||
const uploadUserName = this.userInfo?.realName || this.userInfo?.userName || '';
|
||
const uploadTime = this.$dayjs().format('YYYY-MM-DD HH:mm:ss');
|
||
this.attachmentRows = (list || []).map(item => ({
|
||
...item,
|
||
uploadUserName: item.uploadUserName || uploadUserName,
|
||
uploadTime: item.uploadTime || uploadTime,
|
||
}));
|
||
this.form.attachmentsJson = JSON.stringify(this.attachmentRows);
|
||
},
|
||
removeAttachment(index) {
|
||
this.attachmentRows.splice(index, 1);
|
||
this.form.attachmentsJson = JSON.stringify(this.attachmentRows);
|
||
},
|
||
parseJsonArray(value) {
|
||
if (Array.isArray(value)) return value;
|
||
if (!value) return [];
|
||
try {
|
||
const data = JSON.parse(value);
|
||
return Array.isArray(data) ? data : [];
|
||
} catch (error) {
|
||
return [];
|
||
}
|
||
},
|
||
attachmentName(row = {}) {
|
||
return row.originalName || row.name || row.fileName || '附件';
|
||
},
|
||
attachmentUrl(row = {}) {
|
||
return row.url || row.link || row.fileUrl || row.downloadUrl || row.domain || '';
|
||
},
|
||
attachmentExtension(row = {}) {
|
||
const source = String(this.attachmentName(row) || this.attachmentUrl(row)).split('?')[0];
|
||
const index = source.lastIndexOf('.');
|
||
return index > -1 ? source.slice(index + 1).toLowerCase() : '';
|
||
},
|
||
isAttachmentImage(row) {
|
||
return ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp'].includes(
|
||
this.attachmentExtension(row)
|
||
);
|
||
},
|
||
previewAttachment(row) {
|
||
const url = this.attachmentUrl(row);
|
||
if (!url) {
|
||
this.$message.warning('附件地址为空,无法预览');
|
||
return;
|
||
}
|
||
if (this.isAttachmentImage(row)) {
|
||
this.attachmentImagePreviewUrls = this.attachmentRows
|
||
.filter(item => this.isAttachmentImage(item) && this.attachmentUrl(item))
|
||
.map(item => this.attachmentUrl(item));
|
||
this.attachmentImagePreviewIndex = Math.max(
|
||
this.attachmentImagePreviewUrls.indexOf(url),
|
||
0
|
||
);
|
||
this.attachmentImagePreviewVisible = true;
|
||
return;
|
||
}
|
||
this.attachmentPreviewFile = {
|
||
name: this.attachmentName(row),
|
||
url,
|
||
mimeType: row.mimeType || row.contentType || '',
|
||
};
|
||
this.attachmentDocumentPreviewVisible = true;
|
||
},
|
||
handleAttachmentPreviewUnsupported() {
|
||
this.$message.warning('当前文件暂不支持在线预览');
|
||
},
|
||
handleAttachmentPreviewError() {
|
||
this.$message.error('附件预览失败');
|
||
},
|
||
downloadAttachment(row) {
|
||
const url = this.attachmentUrl(row);
|
||
if (!url) {
|
||
this.$message.warning('附件地址为空,无法下载');
|
||
return;
|
||
}
|
||
downloadFileByUrl(url, this.attachmentName(row));
|
||
},
|
||
batchDownload() {
|
||
const rows = this.selectedAttachments.length ? this.selectedAttachments : this.attachmentRows;
|
||
const downloadableRows = rows.filter(row => this.attachmentUrl(row));
|
||
if (!downloadableRows.length) {
|
||
this.$message.warning(
|
||
this.selectedAttachments.length ? '所选附件暂无可下载地址' : '暂无可下载附件'
|
||
);
|
||
return;
|
||
}
|
||
downloadableRows.forEach((row, index) => {
|
||
window.setTimeout(() => this.downloadAttachment(row), index * 300);
|
||
});
|
||
},
|
||
formatFileSize(size) {
|
||
const value = Number(size);
|
||
if (!value) return '';
|
||
if (value < 1024) return `${value}B`;
|
||
if (value < 1024 * 1024) return `${(value / 1024).toFixed(1)}KB`;
|
||
return `${(value / 1024 / 1024).toFixed(1)}MB`;
|
||
},
|
||
handleExport() {
|
||
this.$confirm(`是否导出${this.config.exportName || this.config.title}?`, '提示', {
|
||
confirmButtonText: '确定',
|
||
cancelButtonText: '取消',
|
||
type: 'warning',
|
||
}).then(() => {
|
||
NProgress.start();
|
||
exportBlob(
|
||
this.config.exportUrl,
|
||
{ ...this.query, ids: this.ids, [this.website.tokenHeader]: getToken() },
|
||
{ feedback: true }
|
||
)
|
||
.then(res => {
|
||
downloadXls(
|
||
res.data,
|
||
`${this.config.exportName || this.config.title}${this.$dayjs().format(
|
||
'YYYY-MM-DD HH:mm:ss'
|
||
)}.xlsx`
|
||
);
|
||
})
|
||
.finally(() => NProgress.done());
|
||
});
|
||
},
|
||
},
|
||
};
|
||
</script>
|
||
|
||
<style lang="scss" scoped>
|
||
.temporary-credit-limit-page {
|
||
&__field {
|
||
width: 100%;
|
||
}
|
||
|
||
&__attachment-head {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: flex-end;
|
||
margin-bottom: 12px;
|
||
margin-top: 12px;
|
||
}
|
||
|
||
&__attachment-upload {
|
||
display: flex;
|
||
justify-content: flex-start;
|
||
margin-top: 12px;
|
||
|
||
:deep(.vehicle-attachment-upload) {
|
||
display: flex;
|
||
align-items: center;
|
||
width: auto;
|
||
}
|
||
|
||
:deep(.el-upload) {
|
||
display: inline-flex;
|
||
}
|
||
|
||
:deep(.el-upload__tip) {
|
||
display: inline-block;
|
||
margin: 0 0 0 30px;
|
||
color: #909399;
|
||
font-size: 13px;
|
||
line-height: 1.4;
|
||
text-align: left;
|
||
}
|
||
}
|
||
|
||
&__flow {
|
||
width: 100%;
|
||
height: calc(100vh - 150px);
|
||
border: 0;
|
||
}
|
||
|
||
:deep(.avue-crud__header) {
|
||
margin-top: 12px;
|
||
}
|
||
|
||
:deep(.avue-crud__menu) {
|
||
display: flex;
|
||
flex-wrap: wrap;
|
||
gap: 8px;
|
||
}
|
||
}
|
||
</style>
|
||
|
||
<style lang="scss">
|
||
// 弹窗字段 label 允许多行(列宽不足时换行)
|
||
.temporary-credit-limit-dialog .el-form-item__label {
|
||
white-space: normal;
|
||
line-height: 18px;
|
||
}
|
||
|
||
// 多行 label 时,必填星号与第一行首字严格对齐(不被 form-item align-items:center 拉到中间)
|
||
.temporary-credit-limit-dialog {
|
||
.el-form-item {
|
||
align-items: flex-start; // 改:取消上下居中,星号不再被拉到 label 块中央
|
||
}
|
||
|
||
.el-form-item__label {
|
||
height: auto !important;
|
||
line-height: 18px;
|
||
//padding-top: 7px; // 视觉补偿:让单行 label 仍接近 input 中线
|
||
}
|
||
|
||
// 强制必填星号垂直居中于行盒,与第一行汉字字符中心同基线(关键)
|
||
.el-form-item.is-required .el-form-item__label::before {
|
||
display: inline-block;
|
||
line-height: 18px;
|
||
height: 18px;
|
||
vertical-align: middle; // 关键:相对 baseline 上移,与汉字字符中心对齐
|
||
margin-right: 4px;
|
||
}
|
||
}
|
||
|
||
.temporary-credit-limit-dialog .business-crud-page__detail-content .el-descriptions__label {
|
||
width: 180px !important;
|
||
}
|
||
|
||
// 仅查看(detail)态加宽 label 列:长字段名(如「剩余项目资金使用额度(万元)」)收敛为最多两行,
|
||
// 避免撑坏详情表格。新增 / 编辑弹窗的 avue-form 无 .avue--detail 类,不受影响
|
||
.temporary-credit-limit-dialog .avue--detail .el-form-item__label {
|
||
width: 148px !important;
|
||
flex: 0 0 148px !important;
|
||
}
|
||
.el-form-item--default .el-form-item__label {
|
||
height: auto !important;
|
||
}
|
||
.el-dialog .avue-form{
|
||
padding: 16px 16px 4px !important;
|
||
}
|
||
|
||
</style>
|