<script setup lang="ts">
|
import type { Recordable } from '@vben/types';
|
|
import { onMounted } from 'vue';
|
|
import { Page, useVbenDrawer, type VbenFormProps } from '@vben/common-ui';
|
import { $t } from '@vben/locales';
|
import { getVxePopupContainer } from '@vben/utils';
|
|
import { Modal, Popconfirm, Space } from 'ant-design-vue';
|
|
import { useVbenVxeGrid, vxeCheckboxChecked, type VxeGridProps, vxeSortEvent } from '#/adapter/vxe-table';
|
import { listEqu } from '#/api/eims/equ';
|
import { delEquTrial, equTrialExport, listEquTrial } from '#/api/eims/equ-trial';
|
import { commonDownloadExcel } from '#/utils/file/download';
|
|
import { columns, querySchema } from './data';
|
import equTrialDrawer from './equ-trial-drawer.vue';
|
import trialPreviewDrawer from './trial-preview-drawer.vue';
|
|
// 从设备明细打开页面 1.不需要设备筛选 2.只查询当前设备数据
|
interface Props {
|
equDetailFlag?: boolean;
|
equId?: string;
|
}
|
|
const props = withDefaults(defineProps<Props>(), { equDetailFlag: false, equId: undefined });
|
|
const formOptions: VbenFormProps = {
|
commonConfig: {
|
labelWidth: 80,
|
componentProps: {
|
allowClear: true
|
}
|
},
|
schema: querySchema(),
|
wrapperClass: 'grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4',
|
// 日期选择格式化
|
fieldMappingTime: [['trialDate', ['params[beginTime]', 'params[endTime]'], ['YYYY-MM-DD', 'YYYY-MM-DD']]]
|
};
|
|
const gridOptions: VxeGridProps = {
|
checkboxConfig: {
|
// 高亮
|
highlight: true,
|
// 翻页时保留选中状态
|
reserve: true
|
// 点击行选中
|
// trigger: 'row'
|
},
|
columns,
|
height: 'auto',
|
keepSource: true,
|
pagerConfig: {},
|
toolbarConfig: {
|
enabled: !props.equDetailFlag
|
},
|
proxyConfig: {
|
ajax: {
|
query: async ({ page }, formValues = {}) => {
|
// 如果传入了equId则只查询当前id数据
|
if (props.equDetailFlag && props.equId) {
|
const queryEqu = { equId: props.equId };
|
Object.assign(formValues, queryEqu);
|
}
|
|
return await listEquTrial({
|
pageNum: page.currentPage,
|
pageSize: page.pageSize,
|
...formValues
|
});
|
}
|
}
|
},
|
rowConfig: {
|
isHover: true,
|
keyField: 'trialId'
|
},
|
sortConfig: {
|
// 远程排序
|
remote: true,
|
// 支持多字段排序 默认关闭
|
multiple: true
|
},
|
id: 'eims-equ-trial-index'
|
};
|
|
const [BasicTable, tableApi] = useVbenVxeGrid({
|
formOptions,
|
gridOptions,
|
gridEvents: {
|
sortChange: (sortParams) => vxeSortEvent(tableApi, sortParams)
|
}
|
});
|
|
const [EquTrialDrawer, equTrialDrawerApi] = useVbenDrawer({
|
connectedComponent: equTrialDrawer
|
});
|
|
const [TrialPreviewDrawer, trialPreviewDrawerApi] = useVbenDrawer({
|
connectedComponent: trialPreviewDrawer
|
});
|
|
/**
|
* 预览
|
* @param record
|
*/
|
function handlePreview(record: Recordable<any>) {
|
trialPreviewDrawerApi.setData({ record });
|
trialPreviewDrawerApi.open();
|
}
|
|
onMounted(async () => {
|
await setupEquSelect();
|
});
|
|
async function setupEquSelect() {
|
// status-0 只查询试用设备
|
const params = { status: '0' };
|
const equPageResult = await listEqu({
|
pageNum: 1,
|
pageSize: 1000,
|
...params
|
});
|
if (!equPageResult || equPageResult.rows.length < 0) {
|
return false;
|
}
|
// 使用map来跟踪已经遇到的equId,使用filter来过滤掉重复的元素。
|
const uniqueItems = equPageResult.rows.filter((item, index, self) => index === self.findIndex((tm) => tm.equId === item.equId));
|
|
const options = uniqueItems.map((item) => ({
|
label: item.equName || item.equName,
|
value: item.equId
|
}));
|
// 筛选
|
const filterOption = (input: string, option: any) => {
|
return option.label.toLowerCase().includes(input.toLowerCase());
|
};
|
|
const placeholder = options.length > 0 ? '请选择' : '暂无设备记录';
|
// 更新selectOptions
|
tableApi.formApi.updateSchema([
|
{
|
componentProps: {
|
options,
|
placeholder,
|
filterOption
|
},
|
dependencies: {
|
show: () => !props.equDetailFlag,
|
triggerFields: ['']
|
},
|
fieldName: 'equId'
|
}
|
]);
|
}
|
|
function handleAdd() {
|
// 设备详情页打开时 只能新增指定设备id数据
|
if (props.equDetailFlag && props.equId) {
|
equTrialDrawerApi.setData({ equId: props.equId });
|
} else {
|
equTrialDrawerApi.setData({});
|
}
|
|
equTrialDrawerApi.open();
|
}
|
|
async function handleEdit(record: Recordable<any>) {
|
equTrialDrawerApi.setData({ id: record.trialId });
|
equTrialDrawerApi.open();
|
}
|
|
async function handleDelete(row: Recordable<any>) {
|
await delEquTrial(row.trialId);
|
await tableApi.query();
|
}
|
|
function handleMultiDelete() {
|
const rows = tableApi.grid.getCheckboxRecords();
|
const ids = rows.map((row: any) => row.trialId);
|
Modal.confirm({
|
title: '提示',
|
okType: 'danger',
|
content: `确认删除选中的${ids.length}条记录吗?`,
|
onOk: async () => {
|
await delEquTrial(ids);
|
await tableApi.query();
|
}
|
});
|
}
|
|
function handleDownloadExcel() {
|
commonDownloadExcel(equTrialExport, '试产记录', tableApi.formApi.form.values, {
|
fieldMappingTime: formOptions.fieldMappingTime
|
});
|
}
|
</script>
|
|
<template>
|
<Page :auto-content-height="true">
|
<div class="flex h-full gap-[8px]">
|
<BasicTable class="flex-1 overflow-hidden" table-title="试产列表">
|
<template #toolbar-tools>
|
<Space>
|
<a-button v-access:code="['eims:equTrial:export']" @click="handleDownloadExcel">
|
{{ $t('pages.common.export') }}
|
</a-button>
|
<a-button
|
:disabled="!vxeCheckboxChecked(tableApi)"
|
danger
|
type="primary"
|
v-access:code="['eims:equTrial:remove']"
|
@click="handleMultiDelete"
|
>
|
{{ $t('pages.common.delete') }}
|
</a-button>
|
<a-button type="primary" v-access:code="['eims:equTrial:add']" @click="handleAdd">
|
{{ $t('pages.common.add') }}
|
</a-button>
|
</Space>
|
</template>
|
|
<template #equName="{ row }">
|
<Space>
|
<span>{{ row.equName }}</span>
|
</Space>
|
</template>
|
|
<template #action="{ row }">
|
<Space>
|
<ghost-button v-access:code="['eims:equTrial:edit']" @click.stop="handleEdit(row)">
|
{{ $t('pages.common.edit') }}
|
</ghost-button>
|
<ghost-button class="btn-success" v-access:code="['eims:equTrial:list']" @click.stop="handlePreview(row)">
|
{{ $t('pages.common.preview') }}
|
</ghost-button>
|
<Popconfirm :get-popup-container="getVxePopupContainer" placement="left" title="确认删除?" @confirm="handleDelete(row)">
|
<ghost-button danger v-access:code="['eims:equTrial:remove']" @click.stop="">
|
{{ $t('pages.common.delete') }}
|
</ghost-button>
|
</Popconfirm>
|
</Space>
|
</template>
|
</BasicTable>
|
</div>
|
<EquTrialDrawer @reload="tableApi.query()" />
|
<TrialPreviewDrawer />
|
</Page>
|
</template>
|