feat: 加料组补齐停用能力
This commit is contained in:
@@ -12,6 +12,7 @@ const props = defineProps<{
|
|||||||
|
|
||||||
const emit = defineEmits<{
|
const emit = defineEmits<{
|
||||||
bindProducts: [item: AddonGroupCardViewModel];
|
bindProducts: [item: AddonGroupCardViewModel];
|
||||||
|
disable: [item: AddonGroupCardViewModel];
|
||||||
edit: [item: AddonGroupCardViewModel];
|
edit: [item: AddonGroupCardViewModel];
|
||||||
enable: [item: AddonGroupCardViewModel];
|
enable: [item: AddonGroupCardViewModel];
|
||||||
removeGroup: [item: AddonGroupCardViewModel];
|
removeGroup: [item: AddonGroupCardViewModel];
|
||||||
@@ -112,6 +113,14 @@ function getStockClass(stock: number) {
|
|||||||
<button type="button" class="g-action" @click="emit('edit', item)">
|
<button type="button" class="g-action" @click="emit('edit', item)">
|
||||||
编辑
|
编辑
|
||||||
</button>
|
</button>
|
||||||
|
<button
|
||||||
|
v-if="item.status === 'enabled'"
|
||||||
|
type="button"
|
||||||
|
class="g-action"
|
||||||
|
@click="emit('bindProducts', item)"
|
||||||
|
>
|
||||||
|
关联商品
|
||||||
|
</button>
|
||||||
<button
|
<button
|
||||||
v-if="item.status === 'disabled'"
|
v-if="item.status === 'disabled'"
|
||||||
type="button"
|
type="button"
|
||||||
@@ -124,9 +133,9 @@ function getStockClass(stock: number) {
|
|||||||
v-else
|
v-else
|
||||||
type="button"
|
type="button"
|
||||||
class="g-action"
|
class="g-action"
|
||||||
@click="emit('bindProducts', item)"
|
@click="emit('disable', item)"
|
||||||
>
|
>
|
||||||
关联商品
|
停用
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
|
|||||||
@@ -27,6 +27,26 @@ interface CreateGroupActionsOptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function createGroupActions(options: CreateGroupActionsOptions) {
|
export function createGroupActions(options: CreateGroupActionsOptions) {
|
||||||
|
async function changeGroupStatus(
|
||||||
|
item: AddonGroupCardViewModel,
|
||||||
|
status: 'disabled' | 'enabled',
|
||||||
|
successMessage: string,
|
||||||
|
) {
|
||||||
|
if (!options.selectedStoreId.value) return;
|
||||||
|
try {
|
||||||
|
await changeProductAddonGroupStatusApi({
|
||||||
|
storeId: options.selectedStoreId.value,
|
||||||
|
groupId: item.id,
|
||||||
|
status,
|
||||||
|
});
|
||||||
|
message.success(successMessage);
|
||||||
|
await options.loadAddonGroups();
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
message.error('加料组状态更新失败');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function removeGroup(item: AddonGroupCardViewModel) {
|
function removeGroup(item: AddonGroupCardViewModel) {
|
||||||
if (!options.selectedStoreId.value) return;
|
if (!options.selectedStoreId.value) return;
|
||||||
Modal.confirm({
|
Modal.confirm({
|
||||||
@@ -45,18 +65,19 @@ export function createGroupActions(options: CreateGroupActionsOptions) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function enableGroup(item: AddonGroupCardViewModel) {
|
async function enableGroup(item: AddonGroupCardViewModel) {
|
||||||
if (!options.selectedStoreId.value) return;
|
await changeGroupStatus(item, 'enabled', '加料组已启用');
|
||||||
try {
|
|
||||||
await changeProductAddonGroupStatusApi({
|
|
||||||
storeId: options.selectedStoreId.value,
|
|
||||||
groupId: item.id,
|
|
||||||
status: 'enabled',
|
|
||||||
});
|
|
||||||
message.success('加料组已启用');
|
|
||||||
await options.loadAddonGroups();
|
|
||||||
} catch (error) {
|
|
||||||
console.error(error);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function disableGroup(item: AddonGroupCardViewModel) {
|
||||||
|
if (!options.selectedStoreId.value) return;
|
||||||
|
Modal.confirm({
|
||||||
|
title: `确认停用加料组「${item.name}」吗?`,
|
||||||
|
okText: '确认停用',
|
||||||
|
cancelText: '取消',
|
||||||
|
async onOk() {
|
||||||
|
await changeGroupStatus(item, 'disabled', '加料组已停用');
|
||||||
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function saveGroupInline(
|
async function saveGroupInline(
|
||||||
@@ -167,6 +188,7 @@ export function createGroupActions(options: CreateGroupActionsOptions) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
disableGroup,
|
||||||
enableGroup,
|
enableGroup,
|
||||||
removeCardItem,
|
removeCardItem,
|
||||||
removeGroup,
|
removeGroup,
|
||||||
|
|||||||
@@ -131,7 +131,7 @@ export function useProductAddonsPage() {
|
|||||||
selectedStoreId,
|
selectedStoreId,
|
||||||
});
|
});
|
||||||
|
|
||||||
const { enableGroup, removeCardItem, removeGroup, renameItem } =
|
const { disableGroup, enableGroup, removeCardItem, removeGroup, renameItem } =
|
||||||
createGroupActions({
|
createGroupActions({
|
||||||
selectedStoreId,
|
selectedStoreId,
|
||||||
loadAddonGroups,
|
loadAddonGroups,
|
||||||
@@ -166,6 +166,7 @@ export function useProductAddonsPage() {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
addItem,
|
addItem,
|
||||||
|
disableGroup,
|
||||||
drawerSubmitText,
|
drawerSubmitText,
|
||||||
drawerTitle,
|
drawerTitle,
|
||||||
enableGroup,
|
enableGroup,
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import { useProductAddonsPage } from './composables/useProductAddonsPage';
|
|||||||
|
|
||||||
const {
|
const {
|
||||||
addItem,
|
addItem,
|
||||||
|
disableGroup,
|
||||||
drawerSubmitText,
|
drawerSubmitText,
|
||||||
drawerTitle,
|
drawerTitle,
|
||||||
enableGroup,
|
enableGroup,
|
||||||
@@ -112,6 +113,7 @@ const {
|
|||||||
@bind-products="openBindProducts"
|
@bind-products="openBindProducts"
|
||||||
@remove-group="removeGroup"
|
@remove-group="removeGroup"
|
||||||
@enable="enableGroup"
|
@enable="enableGroup"
|
||||||
|
@disable="disableGroup"
|
||||||
@rename-item="renameItem"
|
@rename-item="renameItem"
|
||||||
@remove-item="removeCardItem"
|
@remove-item="removeCardItem"
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in New Issue
Block a user