2025-08-22 11:48:41 +08:00
|
|
|
|
<script lang="tsx">
|
2025-09-15 17:02:48 +08:00
|
|
|
|
import { provide, ref } from 'vue';
|
2025-08-23 16:14:05 +08:00
|
|
|
|
import { TABS_LIST, RawMaterialType, INITIAL_QUERY, TABLE_COLUMNS } from './constants';
|
2025-09-15 17:02:48 +08:00
|
|
|
|
|
|
|
|
|
|
import { Tabs, TabPane, Button, Pagination } from 'ant-design-vue';
|
2025-08-23 16:14:05 +08:00
|
|
|
|
import FilterBlock from './components/filter-block/index.vue';
|
|
|
|
|
|
import RawMaterialTable from './components/table/index.vue';
|
|
|
|
|
|
import DeleteRawMaterialModal from './components/table/delete-file-modal.vue';
|
2025-09-15 17:02:48 +08:00
|
|
|
|
import TagsManageModal from './components/tags-manage-modal';
|
2025-09-16 17:03:06 +08:00
|
|
|
|
import AddRawMaterialDrawer from './components/add-raw-material-drawer';
|
2025-09-17 17:08:58 +08:00
|
|
|
|
import EditRawMaterialDrawer from './components/edit-raw-material-modal';
|
2025-09-25 15:26:42 +08:00
|
|
|
|
import SvgIcon from '@/components/svg-icon/index.vue';
|
2025-08-23 16:14:05 +08:00
|
|
|
|
|
|
|
|
|
|
import { useTableSelectionWithPagination } from '@/hooks/useTableSelectionWithPagination';
|
|
|
|
|
|
import { getRawMaterialsPage } from '@/api/all/generationWorkshop';
|
|
|
|
|
|
|
2025-09-15 17:02:48 +08:00
|
|
|
|
import icon3 from '@/assets/img/media-account/icon-tag.png';
|
|
|
|
|
|
|
2025-08-22 11:48:41 +08:00
|
|
|
|
export default defineComponent({
|
|
|
|
|
|
setup(_, { attrs, slots, expose }) {
|
2025-08-23 16:14:05 +08:00
|
|
|
|
const {
|
|
|
|
|
|
dataSource,
|
|
|
|
|
|
pageInfo,
|
|
|
|
|
|
onPageChange,
|
|
|
|
|
|
selectedRowKeys,
|
|
|
|
|
|
selectedRows,
|
|
|
|
|
|
handleSelect,
|
|
|
|
|
|
handleSelectAll,
|
|
|
|
|
|
resetPageInfo,
|
|
|
|
|
|
} = useTableSelectionWithPagination({
|
|
|
|
|
|
onPageChange: () => {
|
|
|
|
|
|
getData();
|
|
|
|
|
|
},
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
const deleteRawMaterialModalRef = ref(null);
|
2025-09-15 17:02:48 +08:00
|
|
|
|
const tagsManageModalRef = ref(null);
|
2025-09-16 17:03:06 +08:00
|
|
|
|
const addRawMaterialDrawerRef = ref(null);
|
2025-09-17 17:08:58 +08:00
|
|
|
|
const editRawMaterialDrawerRef = ref(null);
|
2025-09-15 17:02:48 +08:00
|
|
|
|
|
2025-08-23 16:14:05 +08:00
|
|
|
|
const query = ref(cloneDeep(INITIAL_QUERY));
|
|
|
|
|
|
const handleSearch = () => {
|
|
|
|
|
|
getData();
|
|
|
|
|
|
};
|
|
|
|
|
|
const getData = async () => {
|
|
|
|
|
|
const { page, page_size } = pageInfo.value;
|
|
|
|
|
|
const { code, data } = await getRawMaterialsPage({
|
|
|
|
|
|
...query.value,
|
|
|
|
|
|
page,
|
|
|
|
|
|
page_size,
|
|
|
|
|
|
});
|
|
|
|
|
|
if (code === 200) {
|
|
|
|
|
|
dataSource.value = data?.data ?? [];
|
|
|
|
|
|
pageInfo.value.total = data.total;
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
const reload = () => {
|
|
|
|
|
|
pageInfo.value.page = 1;
|
|
|
|
|
|
getData();
|
|
|
|
|
|
};
|
|
|
|
|
|
const handleReset = () => {
|
|
|
|
|
|
resetPageInfo();
|
|
|
|
|
|
query.value = cloneDeep(INITIAL_QUERY);
|
|
|
|
|
|
reload();
|
|
|
|
|
|
};
|
|
|
|
|
|
const handleSorterChange = (column, order) => {
|
|
|
|
|
|
query.value.sort_column = column;
|
|
|
|
|
|
query.value.sort_order = order;
|
|
|
|
|
|
reload();
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const handleBatchDelete = () => {
|
|
|
|
|
|
const ids = selectedRows.value.map((item) => item.id);
|
|
|
|
|
|
const names = selectedRows.value.map((item) => `"${item.name || '-'}` + '"').join(',');
|
|
|
|
|
|
|
|
|
|
|
|
deleteRawMaterialModalRef.value?.open({ id: ids, name: names });
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const handleDelete = (item) => {
|
|
|
|
|
|
const { id, name } = item;
|
|
|
|
|
|
deleteRawMaterialModalRef.value?.open({ id, name: `“${name}”` });
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-09-17 17:08:58 +08:00
|
|
|
|
const handleEdit = (item) => {
|
|
|
|
|
|
editRawMaterialDrawerRef.value?.open(item.id);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-08-23 16:14:05 +08:00
|
|
|
|
const handleTabClick = (key) => {
|
|
|
|
|
|
query.value.type = key;
|
|
|
|
|
|
reload();
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const onBatchSuccess = () => {
|
|
|
|
|
|
selectedRows.value = [];
|
|
|
|
|
|
selectedRowKeys.value = [];
|
|
|
|
|
|
getData();
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-09-15 17:02:48 +08:00
|
|
|
|
const handleOpenTagsModal = () => {
|
|
|
|
|
|
tagsManageModalRef.value?.open();
|
|
|
|
|
|
};
|
|
|
|
|
|
const handleAddMaterial = () => {
|
2025-09-16 17:03:06 +08:00
|
|
|
|
addRawMaterialDrawerRef.value?.open();
|
2025-09-15 17:02:48 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
2025-08-23 16:14:05 +08:00
|
|
|
|
onMounted(() => {
|
|
|
|
|
|
getData();
|
|
|
|
|
|
});
|
2025-08-22 11:48:41 +08:00
|
|
|
|
|
|
|
|
|
|
return () => (
|
|
|
|
|
|
<div class="raw-material-wrap h-full flex flex-col">
|
2025-08-23 16:14:05 +08:00
|
|
|
|
<div class="bg-white rounded-t-8px">
|
2025-09-15 17:02:48 +08:00
|
|
|
|
<Tabs
|
|
|
|
|
|
v-model:activeKey={query.value.type}
|
|
|
|
|
|
onTabClick={handleTabClick}
|
|
|
|
|
|
v-slots={{
|
|
|
|
|
|
rightExtra: () => (
|
|
|
|
|
|
<div class="flex items-center">
|
|
|
|
|
|
<Button
|
|
|
|
|
|
type="primary"
|
|
|
|
|
|
ghost
|
|
|
|
|
|
size="medium"
|
|
|
|
|
|
onClick={handleOpenTagsModal}
|
|
|
|
|
|
v-slots={{
|
|
|
|
|
|
icon: () => <img src={icon3} width="16" height="16" class="mr-8px" />,
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
|
|
|
|
|
标签管理
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
<Button
|
|
|
|
|
|
type="primary"
|
|
|
|
|
|
size="medium"
|
|
|
|
|
|
class="ml-12px"
|
|
|
|
|
|
onClick={handleAddMaterial}
|
|
|
|
|
|
v-slots={{
|
2025-09-25 15:26:42 +08:00
|
|
|
|
icon: () => <SvgIcon name="xt-plus" size="16" class="mr-8px" />,
|
2025-09-15 17:02:48 +08:00
|
|
|
|
default: () => '上传原料',
|
|
|
|
|
|
}}
|
|
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
),
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
2025-08-23 16:14:05 +08:00
|
|
|
|
{TABS_LIST.map((item) => (
|
|
|
|
|
|
<TabPane key={item.value} tab={item.label}>
|
|
|
|
|
|
{item.label}
|
|
|
|
|
|
</TabPane>
|
|
|
|
|
|
))}
|
|
|
|
|
|
</Tabs>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="filter-wrap bg-#fff rounded-b-8px mb-16px">
|
|
|
|
|
|
<FilterBlock v-model:query={query.value} onSearch={handleSearch} onReset={handleReset} />
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="table-wrap bg-#fff rounded-8px px-24px py-24px flex flex-col">
|
|
|
|
|
|
<div class="flex justify-end mb-12px">
|
2025-09-03 12:04:15 +08:00
|
|
|
|
<Button
|
|
|
|
|
|
type="primary"
|
|
|
|
|
|
ghost
|
|
|
|
|
|
class="w-fit"
|
|
|
|
|
|
size="medium"
|
|
|
|
|
|
onClick={handleBatchDelete}
|
|
|
|
|
|
disabled={!selectedRows.value.length}
|
|
|
|
|
|
>
|
2025-08-23 16:14:05 +08:00
|
|
|
|
批量删除
|
2025-09-03 11:15:37 +08:00
|
|
|
|
</Button>
|
2025-08-23 16:14:05 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<RawMaterialTable
|
|
|
|
|
|
tableColumns={TABLE_COLUMNS}
|
|
|
|
|
|
selectedRowKeys={selectedRowKeys.value}
|
|
|
|
|
|
dataSource={dataSource.value}
|
|
|
|
|
|
onSorterChange={handleSorterChange}
|
|
|
|
|
|
onDelete={handleDelete}
|
|
|
|
|
|
onSelect={handleSelect}
|
|
|
|
|
|
onSelectAll={handleSelectAll}
|
2025-09-17 17:08:58 +08:00
|
|
|
|
onEdit={handleEdit}
|
2025-08-23 16:14:05 +08:00
|
|
|
|
/>
|
|
|
|
|
|
{pageInfo.value.total > 0 && (
|
|
|
|
|
|
<div class="pagination-row">
|
2025-09-04 23:30:41 +08:00
|
|
|
|
<Pagination
|
2025-08-23 16:14:05 +08:00
|
|
|
|
total={pageInfo.value.total}
|
2025-09-04 23:30:41 +08:00
|
|
|
|
size="small"
|
|
|
|
|
|
showTotal={(total: number) => `共 ${total} 条记录`}
|
|
|
|
|
|
showSizeChanger
|
|
|
|
|
|
showQuickJumper
|
2025-08-23 16:14:05 +08:00
|
|
|
|
current={pageInfo.value.page}
|
|
|
|
|
|
pageSize={pageInfo.value.page_size}
|
|
|
|
|
|
onChange={onPageChange}
|
|
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</div>
|
2025-09-15 17:02:48 +08:00
|
|
|
|
|
|
|
|
|
|
<TagsManageModal ref={tagsManageModalRef} />
|
2025-09-17 15:57:19 +08:00
|
|
|
|
<AddRawMaterialDrawer ref={addRawMaterialDrawerRef} onUpdate={getData} />
|
2025-09-17 17:08:58 +08:00
|
|
|
|
<EditRawMaterialDrawer ref={editRawMaterialDrawerRef} onUpdate={getData} />
|
2025-08-23 16:14:05 +08:00
|
|
|
|
<DeleteRawMaterialModal ref={deleteRawMaterialModalRef} onBatchUpdate={onBatchSuccess} onUpdate={getData} />
|
2025-08-22 11:48:41 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
);
|
|
|
|
|
|
},
|
|
|
|
|
|
});
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style scoped lang="scss">
|
|
|
|
|
|
@import './style.scss';
|
|
|
|
|
|
</style>
|