fix(04): no work name duplicate
This commit is contained in:
parent
0a861a7aaa
commit
e2b30f9c1c
5 changed files with 93 additions and 56 deletions
|
|
@ -125,7 +125,7 @@ defineEmits<{
|
|||
@click.stop="$emit('manageWorkName')"
|
||||
>
|
||||
<q-icon name="mdi-cog" size="xs" class="q-mr-sm" />
|
||||
{{ $t('manage') }}
|
||||
{{ $t('general.manage') }}
|
||||
</q-btn>
|
||||
</div>
|
||||
</q-item>
|
||||
|
|
|
|||
|
|
@ -13,10 +13,18 @@ const nameList = defineModel<{ id: string; name: string; isEdit: boolean }[]>(
|
|||
{ required: true },
|
||||
);
|
||||
|
||||
const refForm = ref();
|
||||
const cloneList = ref();
|
||||
const isAdd = ref(false);
|
||||
const inputName = ref<HTMLInputElement[]>([]);
|
||||
|
||||
function nameExist(name: string) {
|
||||
const listToCheck = cloneList.value.filter((clone) => !clone.isEdit);
|
||||
const alreadyExist = listToCheck.find((clone) => clone.name === name);
|
||||
|
||||
return alreadyExist ? true : false;
|
||||
}
|
||||
|
||||
function isWorkNameEdit() {
|
||||
return cloneList.value.some((i: { isEdit: boolean }) => i.isEdit === true);
|
||||
}
|
||||
|
|
@ -30,7 +38,7 @@ defineExpose({
|
|||
});
|
||||
|
||||
defineEmits<{
|
||||
(e: 'delete', id: string): void;
|
||||
(e: 'delete', id: string, noDialog?: boolean): void;
|
||||
(e: 'edit', id: string, data: { name: string }): void;
|
||||
(e: 'add', data: { name: string; productId: []; order: number }): void;
|
||||
}>();
|
||||
|
|
@ -61,55 +69,79 @@ watch(
|
|||
v-for="(item, index) in cloneList"
|
||||
:key="index"
|
||||
>
|
||||
<q-input
|
||||
lazy-rules="ondemand"
|
||||
ref="inputName"
|
||||
:for="`input-work-name-${index}`"
|
||||
dense
|
||||
class="col q-mr-md"
|
||||
v-model="item.name"
|
||||
placeholder="ชื่องาน"
|
||||
:borderless="!item.isEdit"
|
||||
:readonly="!item.isEdit"
|
||||
:outlined="item.isEdit"
|
||||
></q-input>
|
||||
<EditButton
|
||||
v-if="!item.isEdit"
|
||||
icon-only
|
||||
id="btn-edit-work-name"
|
||||
:disabled="isWorkNameEdit()"
|
||||
@click="item.isEdit = true"
|
||||
/>
|
||||
<SaveButton
|
||||
v-else
|
||||
icon-only
|
||||
id="btn-save-work-name"
|
||||
@click="
|
||||
<q-form
|
||||
ref="refForm"
|
||||
greedy
|
||||
@submit.prevent
|
||||
@validation-success="
|
||||
() => {
|
||||
$emit('edit', item.id, { name: item.name }),
|
||||
(item.isEdit = false);
|
||||
$emit('edit', item.id, { name: item.name });
|
||||
item.isEdit = false;
|
||||
}
|
||||
"
|
||||
/>
|
||||
<DeleteButton
|
||||
v-if="!item.isEdit"
|
||||
icon-only
|
||||
id="btn-delete-work-name"
|
||||
:disabled="isWorkNameEdit()"
|
||||
@click="$emit('delete', item.id)"
|
||||
/>
|
||||
<UndoButton
|
||||
v-else
|
||||
icon-only
|
||||
id="btn-undo-work-name"
|
||||
@click="assignClone"
|
||||
/>
|
||||
class="row full-width"
|
||||
>
|
||||
<q-input
|
||||
lazy-rules="ondemand"
|
||||
ref="inputName"
|
||||
:for="`input-work-name-${index}`"
|
||||
dense
|
||||
class="col q-mr-md"
|
||||
v-model="item.name"
|
||||
placeholder="ชื่องาน"
|
||||
:borderless="!item.isEdit"
|
||||
:readonly="!item.isEdit"
|
||||
:outlined="item.isEdit"
|
||||
:rules="[
|
||||
(val: string) => val.length > 2 || $t('form.error.required'),
|
||||
(val: string) =>
|
||||
(val.length > 0 && !nameExist(val)) ||
|
||||
$t('productService.service.workAlreadyExist'),
|
||||
]"
|
||||
hide-bottom-space
|
||||
></q-input>
|
||||
<EditButton
|
||||
v-if="!item.isEdit"
|
||||
icon-only
|
||||
id="btn-edit-work-name"
|
||||
:disabled="isWorkNameEdit()"
|
||||
@click="item.isEdit = true"
|
||||
/>
|
||||
<SaveButton
|
||||
v-else
|
||||
icon-only
|
||||
id="btn-save-work-name"
|
||||
type="submit"
|
||||
@click.stop
|
||||
/>
|
||||
<DeleteButton
|
||||
v-if="!item.isEdit"
|
||||
icon-only
|
||||
id="btn-delete-work-name"
|
||||
:disabled="isWorkNameEdit()"
|
||||
@click="$emit('delete', item.id)"
|
||||
/>
|
||||
<UndoButton
|
||||
v-else
|
||||
icon-only
|
||||
id="btn-undo-work-name"
|
||||
@click="
|
||||
() => {
|
||||
assignClone();
|
||||
if (nameList[nameList.length - 1].name === '') {
|
||||
$emit('delete', cloneList[cloneList.length - 1].id, true);
|
||||
cloneList = cloneList.filter((item) => item.name !== '');
|
||||
nameList = nameList.filter((item) => item.name !== '');
|
||||
}
|
||||
}
|
||||
"
|
||||
/>
|
||||
</q-form>
|
||||
</q-item>
|
||||
</q-list>
|
||||
<div v-else class="flex col justify-center items-center">
|
||||
<NoData />
|
||||
</div>
|
||||
|
||||
<div class="bordered-t full-width">
|
||||
<q-item
|
||||
clickable
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue