|
@@ -2,79 +2,188 @@
|
|
<BasicTable @register="registerTable">
|
|
<BasicTable @register="registerTable">
|
|
<template #toolbar>
|
|
<template #toolbar>
|
|
<a-button type="primary" @click="handleCreate"> 新增商品分类</a-button>
|
|
<a-button type="primary" @click="handleCreate"> 新增商品分类</a-button>
|
|
- <a-button type="warning" @click="expandAll">展开全部</a-button>
|
|
|
|
- <a-button type="error" @click="collapseAll">折叠全部</a-button>
|
|
|
|
</template>
|
|
</template>
|
|
- <template #action="{ record }">
|
|
|
|
- <TableAction
|
|
|
|
- :actions="[
|
|
|
|
- {
|
|
|
|
- icon: 'clarity:note-edit-line',
|
|
|
|
- onClick: handleEdit.bind(null, record),
|
|
|
|
- },
|
|
|
|
- {
|
|
|
|
- icon: 'ant-design:delete-outlined',
|
|
|
|
- color: 'error',
|
|
|
|
- popConfirm: {
|
|
|
|
- title: '是否确认删除',
|
|
|
|
- confirm: handleDelete.bind(null, record),
|
|
|
|
- },
|
|
|
|
- },
|
|
|
|
- ]"
|
|
|
|
- />
|
|
|
|
|
|
+ <template #action="{ record, column }">
|
|
|
|
+ <TableAction :actions="createActions(record, column)" />
|
|
</template>
|
|
</template>
|
|
</BasicTable>
|
|
</BasicTable>
|
|
|
|
+ <addModal @register="registerModal" @ok="handleSaveAdd" />
|
|
</template>
|
|
</template>
|
|
|
|
|
|
<script lang="ts">
|
|
<script lang="ts">
|
|
- import { defineComponent } from 'vue'; // h
|
|
|
|
- import { BasicTable, useTable, BasicColumn, TableAction } from '/@/components/Table';
|
|
|
|
- import { categoryApi } from '/@/api/product/category';
|
|
|
|
|
|
+ import { defineComponent, ref } from 'vue'; // h
|
|
|
|
+ import {
|
|
|
|
+ BasicTable,
|
|
|
|
+ useTable,
|
|
|
|
+ BasicColumn,
|
|
|
|
+ TableAction,
|
|
|
|
+ EditRecordRow,
|
|
|
|
+ ActionItem,
|
|
|
|
+ } from '/@/components/Table';
|
|
|
|
+ import { attributeListApi, attributeDleteApi, updateItemApi } from '/@/api/product/category';
|
|
|
|
+ import { cloneDeep } from 'lodash-es';
|
|
// import { Tag } from 'ant-design-vue';
|
|
// import { Tag } from 'ant-design-vue';
|
|
-
|
|
|
|
import { useI18n } from '/@/hooks/web/useI18n';
|
|
import { useI18n } from '/@/hooks/web/useI18n';
|
|
|
|
+ import { useModal } from '/@/components/Modal';
|
|
|
|
+ import addModal from './addModal.vue';
|
|
import { useMessage } from '/@/hooks/web/useMessage';
|
|
import { useMessage } from '/@/hooks/web/useMessage';
|
|
|
|
|
|
export default defineComponent({
|
|
export default defineComponent({
|
|
- components: { BasicTable, TableAction },
|
|
|
|
|
|
+ components: { BasicTable, TableAction, addModal },
|
|
setup() {
|
|
setup() {
|
|
- const { createMessage } = useMessage();
|
|
|
|
-
|
|
|
|
|
|
+ const { createConfirm, createMessage: msg } = useMessage();
|
|
|
|
+ const [registerModal, { openModal }] = useModal();
|
|
|
|
+ const currentEditKeyRef = ref('');
|
|
const { t } = useI18n();
|
|
const { t } = useI18n();
|
|
-
|
|
|
|
|
|
+ console.log('registerModal', registerModal);
|
|
const columns: BasicColumn[] = [
|
|
const columns: BasicColumn[] = [
|
|
{
|
|
{
|
|
title: '商品属性',
|
|
title: '商品属性',
|
|
- dataIndex: 'id',
|
|
|
|
|
|
+ editRow: true,
|
|
|
|
+ dataIndex: 'name',
|
|
fixed: 'left',
|
|
fixed: 'left',
|
|
width: 100,
|
|
width: 100,
|
|
},
|
|
},
|
|
{
|
|
{
|
|
title: '排序',
|
|
title: '排序',
|
|
- dataIndex: 'orderNo',
|
|
|
|
|
|
+ dataIndex: 'sortOrder',
|
|
|
|
+ editComponent: 'InputNumber',
|
|
|
|
+ editRow: true,
|
|
width: 50,
|
|
width: 50,
|
|
},
|
|
},
|
|
];
|
|
];
|
|
|
|
|
|
- const [registerTable, { expandAll, collapseAll }] = useTable({
|
|
|
|
|
|
+ const [registerTable, { expandAll, reload, collapseAll }] = useTable({
|
|
title: '商品分类',
|
|
title: '商品分类',
|
|
- api: categoryApi,
|
|
|
|
|
|
+ api: attributeListApi,
|
|
columns: columns,
|
|
columns: columns,
|
|
useSearchForm: true,
|
|
useSearchForm: true,
|
|
- showTableSetting: true,
|
|
|
|
- tableSetting: { fullScreen: true },
|
|
|
|
showIndexColumn: false,
|
|
showIndexColumn: false,
|
|
- isTreeTable: true,
|
|
|
|
|
|
+ // rowSelection: { type: 'checkbox' },
|
|
rowKey: 'id',
|
|
rowKey: 'id',
|
|
bordered: true,
|
|
bordered: true,
|
|
|
|
+ fetchSetting: {
|
|
|
|
+ pageField: 'page',
|
|
|
|
+ sizeField: 'limit',
|
|
|
|
+ listField: 'list',
|
|
|
|
+ totalField: 'totalCount',
|
|
|
|
+ },
|
|
|
|
+ formConfig: {
|
|
|
|
+ labelWidth: 66,
|
|
|
|
+ schemas: [
|
|
|
|
+ {
|
|
|
|
+ field: `name`,
|
|
|
|
+ label: `商品属性`,
|
|
|
|
+ component: 'Input',
|
|
|
|
+ colProps: {
|
|
|
|
+ xl: 6,
|
|
|
|
+ xxl: 6,
|
|
|
|
+ },
|
|
|
|
+ },
|
|
|
|
+ ],
|
|
|
|
+ },
|
|
|
|
+ actionColumn: {
|
|
|
|
+ width: 160,
|
|
|
|
+ title: 'Action',
|
|
|
|
+ dataIndex: 'action',
|
|
|
|
+ slots: { customRender: 'action' },
|
|
|
|
+ },
|
|
});
|
|
});
|
|
- function handleCreate() {}
|
|
|
|
- function handleEdit() {}
|
|
|
|
- function handleDelete() {}
|
|
|
|
|
|
+ async function handleCreate() {
|
|
|
|
+ openModal(true);
|
|
|
|
+ }
|
|
|
|
+ function handleEdit(record: EditRecordRow) {
|
|
|
|
+ currentEditKeyRef.value = record.key;
|
|
|
|
+ record.onEdit?.(true);
|
|
|
|
+ }
|
|
|
|
+ function handleDelete(record) {
|
|
|
|
+ createConfirm({
|
|
|
|
+ iconType: 'warning',
|
|
|
|
+ title: '警告',
|
|
|
|
+ content: `此操作将对${record.name}进行删除, 是否继续?`,
|
|
|
|
+ onOk: async () => {
|
|
|
|
+ let res = await attributeDleteApi(record.id);
|
|
|
|
+ console.log('res', res);
|
|
|
|
+ reload();
|
|
|
|
+ },
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ function handleCancel(record: EditRecordRow) {
|
|
|
|
+ currentEditKeyRef.value = '';
|
|
|
|
+ record.onEdit?.(false, false);
|
|
|
|
+ }
|
|
|
|
+ async function handleSaveAdd() {
|
|
|
|
+ console.log('handleSaveAdd');
|
|
|
|
+ reload();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ async function handleSave(record: EditRecordRow) {
|
|
|
|
+ // 校验
|
|
|
|
+ msg.loading({ content: '正在保存...', duration: 0, key: 'saving' });
|
|
|
|
+ const valid = await record.onValid?.();
|
|
|
|
+ if (valid) {
|
|
|
|
+ try {
|
|
|
|
+ const data = cloneDeep(record.editValueRefs);
|
|
|
|
+ console.log(data);
|
|
|
|
+ //TODO 此处将数据提交给服务器保存
|
|
|
|
+ // ...
|
|
|
|
+ updateItemApi({
|
|
|
|
+ id: record.id,
|
|
|
|
+ ...data,
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ // 保存之后提交编辑状态
|
|
|
|
+ const pass = await record.onEdit?.(false, true);
|
|
|
|
+ if (pass) {
|
|
|
|
+ currentEditKeyRef.value = '';
|
|
|
|
+ }
|
|
|
|
+ msg.success({ content: '数据已保存', key: 'saving' });
|
|
|
|
+ } catch (error) {
|
|
|
|
+ msg.error({ content: '保存失败', key: 'saving' });
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ msg.error({ content: '请填写正确的数据', key: 'saving' });
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ function createActions(record: EditRecordRow, column: BasicColumn): ActionItem[] {
|
|
|
|
+ console.log('editable', record);
|
|
|
|
+ if (!record.editable) {
|
|
|
|
+ return [
|
|
|
|
+ {
|
|
|
|
+ label: '编辑',
|
|
|
|
+ icon: 'mdi:information-outline',
|
|
|
|
+ disabled: currentEditKeyRef.value ? currentEditKeyRef.value !== record.key : false,
|
|
|
|
+ onClick: handleEdit.bind(null, record),
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ label: '删除',
|
|
|
|
+ color: 'error',
|
|
|
|
+ icon: 'ant-design:delete-outlined',
|
|
|
|
+ disabled: currentEditKeyRef.value ? currentEditKeyRef.value !== record.key : false,
|
|
|
|
+ onClick: handleDelete.bind(null, record),
|
|
|
|
+ },
|
|
|
|
+ ];
|
|
|
|
+ }
|
|
|
|
+ return [
|
|
|
|
+ {
|
|
|
|
+ label: '保存',
|
|
|
|
+ onClick: handleSave.bind(null, record, column),
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ label: '取消',
|
|
|
|
+ popConfirm: {
|
|
|
|
+ title: '是否取消编辑',
|
|
|
|
+ confirm: handleCancel.bind(null, record, column),
|
|
|
|
+ },
|
|
|
|
+ },
|
|
|
|
+ ];
|
|
|
|
+ }
|
|
return {
|
|
return {
|
|
registerTable,
|
|
registerTable,
|
|
- createMessage,
|
|
|
|
|
|
+ createActions,
|
|
t,
|
|
t,
|
|
|
|
+ registerModal,
|
|
|
|
+ handleSaveAdd,
|
|
handleCreate,
|
|
handleCreate,
|
|
handleEdit,
|
|
handleEdit,
|
|
handleDelete,
|
|
handleDelete,
|