|
@@ -0,0 +1,132 @@
|
|
|
+<template>
|
|
|
+ <!--定义表格-->
|
|
|
+ <BasicTable @register="registerTable" :rowSelection="rowSelection">
|
|
|
+ <template #tableTitle>
|
|
|
+ <a-button type="primary" preIcon="ant-design:plus-outlined" @click="handleCreate"> 新增</a-button>
|
|
|
+ <div style="margin-left: 10px;margin-top: 5px">当前登录租户: <span class="tenant-name">{{loginTenantName}}</span> </div>
|
|
|
+ </template>
|
|
|
+ <!--操作栏-->
|
|
|
+ <template #action="{ record }">
|
|
|
+ <TableAction :actions="getTableAction(record)" />
|
|
|
+ </template>
|
|
|
+ </BasicTable>
|
|
|
+ <productCassificationModel @register="registerModal" @success="handleSuccess" />
|
|
|
+</template>
|
|
|
+
|
|
|
+<script lang="ts" name="basic-table-demo" setup>
|
|
|
+ import { onMounted, ref } from 'vue';
|
|
|
+ import { useModal } from '/@/components/Modal';
|
|
|
+ import { ActionItem, BasicColumn, BasicTable, TableAction,FormSchema } from '/@/components/Table';
|
|
|
+ import productCassificationModel from './components/productCassificationModel.vue';
|
|
|
+ import { useListPage } from '/@/hooks/system/useListPage';
|
|
|
+ import { list,deleteDict } from './api/productCassification.api';
|
|
|
+ const showFooter = ref(true);
|
|
|
+ const [registerModal, { openModal }] = useModal();
|
|
|
+ //定义表格列字段
|
|
|
+ const columns: BasicColumn[] = [
|
|
|
+ {
|
|
|
+ title: '编码(code)',
|
|
|
+ dataIndex: 'code',
|
|
|
+ key: 'code',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '名称(name)',
|
|
|
+ dataIndex: 'name',
|
|
|
+ key: 'name',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '上级分类(parent)',
|
|
|
+ dataIndex: 'parentId',
|
|
|
+ key: 'parentId',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '毛利率(gross margin)',
|
|
|
+ dataIndex: 'grossMargin',
|
|
|
+ key: 'grossMargin',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '税率(tax rate)',
|
|
|
+ dataIndex: 'taxRate',
|
|
|
+ key: 'taxRate',
|
|
|
+ },
|
|
|
+ ];
|
|
|
+ //表单搜索字段
|
|
|
+ const searchFormSchema: FormSchema[] = [
|
|
|
+ {
|
|
|
+ label: '编码(code)', //显示label
|
|
|
+ field: 'code', //查询字段
|
|
|
+ component: 'JInput', //渲染的组件
|
|
|
+ defaultValue: '', //设置默认值
|
|
|
+ },
|
|
|
+ {
|
|
|
+ label: '名称(name)', //显示label
|
|
|
+ field: 'name', //查询字段
|
|
|
+ component: 'JInput', //渲染的组件
|
|
|
+ defaultValue: '', //设置默认值
|
|
|
+ },
|
|
|
+ ];
|
|
|
+ /** useListPage 是整个框架的核心用于表格渲染,里边封装了很多公共方法;
|
|
|
+ * 平台通过此封装,简化了代码,支持自定义扩展*/
|
|
|
+ // 通过hook useListPage渲染表格(设置dataSource、columns、actionColumn等参数)
|
|
|
+ const { tableContext } = useListPage({
|
|
|
+ designScope: 'basic-table-demo',
|
|
|
+ tableProps: {
|
|
|
+ title: '',
|
|
|
+ api: list,
|
|
|
+ columns: columns,
|
|
|
+ size: 'small',
|
|
|
+ rowkey:"id",
|
|
|
+ actionColumn: {
|
|
|
+ width: 120,
|
|
|
+ },
|
|
|
+ formConfig: {
|
|
|
+ schemas: searchFormSchema,
|
|
|
+ }
|
|
|
+ },
|
|
|
+ });
|
|
|
+ const [registerTable, { reload ,updateTableDataRecord}, { rowSelection, selectedRows, selectedRowKeys }] = tableContext;
|
|
|
+ /**
|
|
|
+ * 操作栏
|
|
|
+ */
|
|
|
+ function getTableAction(record): ActionItem[] {
|
|
|
+ return [
|
|
|
+ {
|
|
|
+ label: '编辑',
|
|
|
+ onClick: handleEdit.bind(null, record),
|
|
|
+ },
|
|
|
+ {
|
|
|
+ label: '删除',
|
|
|
+ popConfirm: {
|
|
|
+ title: '确定删除吗?',
|
|
|
+ confirm: handleDelete.bind(null, record),
|
|
|
+ },
|
|
|
+ },
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ function handleEdit(record) {
|
|
|
+ openModal(true, {
|
|
|
+ record,
|
|
|
+ isUpdate: true,
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ async function handleDelete(record) {
|
|
|
+ await deleteDict({ id: record.id }, reload);
|
|
|
+ }
|
|
|
+ function handleCreate() {
|
|
|
+ openModal(true, {
|
|
|
+ isUpdate: false,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 成功回调
|
|
|
+ */
|
|
|
+ function handleSuccess({ isUpdate, values }) {
|
|
|
+ if (isUpdate) {
|
|
|
+ updateTableDataRecord(values.id, values);
|
|
|
+ } else {
|
|
|
+ reload();
|
|
|
+ }
|
|
|
+ }
|
|
|
+</script>
|