fix: change status dialog

This commit is contained in:
puriphatt 2024-07-25 10:49:43 +00:00
parent 305d1f2e2b
commit f9eeb7f529
4 changed files with 152 additions and 84 deletions

View file

@ -695,6 +695,46 @@ async function toggleStatusGroup(id: string, status: Status) {
flowStore.rotate();
}
async function triggerChangeStatus(
id: string,
status: string,
type?: 'type' | 'group' | 'service' | 'product',
) {
return await new Promise((resolve, reject) => {
dialog({
color: status !== 'INACTIVE' ? 'warning' : 'info',
icon: status !== 'INACTIVE' ? 'mdi-alert' : 'mdi-comment-alert',
title: t('confirmChangeStatusTitle'),
actionText:
status !== 'INACTIVE' ? t('switchOffLabel') : t('switchOnLabel'),
message:
status !== 'INACTIVE'
? t('confirmChangeStatusOffMessage')
: t('confirmChangeStatusOnMessage'),
action: async () => {
if (type === 'group' || productMode.value === 'group') {
await toggleStatusGroup(id, status as Status)
.then(resolve)
.catch(reject);
} else if (type === 'type' || productMode.value === 'type') {
await toggleStatusType(id, status as Status)
.then(resolve)
.catch(reject);
} else if (type === 'service' || productMode.value === 'service') {
await toggleStatusService(id, status as Status)
.then(resolve)
.catch(reject);
} else if (type === 'product' || productMode.value === 'product') {
await toggleStatusProduct(id, status as Status)
.then(resolve)
.catch(reject);
}
},
cancel: () => {},
});
});
}
async function deleteServiceById(serviceId?: string) {
dialog({
color: 'negative',
@ -1712,15 +1752,17 @@ watch(
@click.stop="
async () => {
if (node.type === 'type') {
toggleStatusType(
triggerChangeStatus(
node.id,
node.status,
node.type,
);
}
if (node.type === 'group') {
toggleStatusGroup(
triggerChangeStatus(
node.id,
node.status,
node.type,
);
}
}
@ -2175,18 +2217,10 @@ watch(
"
@click="
async () => {
if (productMode === 'type') {
toggleStatusType(
props.row.id,
props.row.status,
);
}
if (productMode === 'group') {
toggleStatusGroup(
props.row.id,
props.row.status,
);
}
triggerChangeStatus(
props.row.id,
props.row.status,
);
}
"
:model-value="
@ -2225,12 +2259,7 @@ watch(
}[productMode] || 'var(--pink-6-hsl)'
"
@toggleStatus="
if (productMode === 'type') {
toggleStatusType(props.row.id, props.row.status);
}
if (productMode === 'group') {
toggleStatusGroup(props.row.id, props.row.status);
}
triggerChangeStatus(props.row.id, props.row.status)
"
@viewCard="
() => {
@ -3000,18 +3029,11 @@ watch(
"
@click="
() => {
if (props.row.type === 'product') {
toggleStatusProduct(
props.row.id,
props.row.status,
);
}
if (props.row.type === 'service') {
toggleStatusService(
props.row.id,
props.row.status,
);
}
triggerChangeStatus(
props.row.id,
props.row.status,
props.row.type,
);
}
"
:model-value="
@ -3038,12 +3060,7 @@ watch(
:isDisabled="row.status === 'INACTIVE' ? true : false"
@toggleStatus="
() => {
if (row.type === 'product') {
toggleStatusProduct(row.id, row.status);
}
if (row.type === 'service') {
toggleStatusService(row.id, row.status);
}
triggerChangeStatus(row.id, row.status, row.type);
}
"
@menuViewDetail="
@ -3890,13 +3907,21 @@ watch(
async () => {
if (!currentNode) return;
if (currentNode.type === 'type') {
toggleStatusType(currentNode.id, currentNode.status);
triggerChangeStatus(
currentNode.id,
currentNode.status,
currentNode.type,
);
currentNode.status === 'ACTIVE'
? (currentNode.status = 'INACTIVE')
: (currentNode.status = 'ACTIVE');
}
if (currentNode.type === 'group') {
toggleStatusGroup(currentNode.id, currentNode.status);
triggerChangeStatus(
currentNode.id,
currentNode.status,
currentNode.type,
);
currentNode.status === 'ACTIVE'
? (currentNode.status = 'INACTIVE')
: (currentNode.status = 'ACTIVE');