feat: CRUD work
This commit is contained in:
parent
12e52e4a79
commit
2fb345e78f
3 changed files with 115 additions and 55 deletions
|
|
@ -118,14 +118,14 @@ defineEmits<{
|
||||||
</div>
|
</div>
|
||||||
</q-item>
|
</q-item>
|
||||||
<q-item
|
<q-item
|
||||||
@click="workName = item"
|
@click="workName = item.name"
|
||||||
clickable
|
clickable
|
||||||
v-for="item in workNameItems"
|
v-for="(item, index) in workNameItems"
|
||||||
:key="item"
|
:key="index"
|
||||||
>
|
>
|
||||||
<div class="full-width flex items-center">
|
<div class="full-width flex items-center">
|
||||||
<q-icon
|
<q-icon
|
||||||
v-if="workName === item"
|
v-if="workName === item.name"
|
||||||
name="mdi-checkbox-marked"
|
name="mdi-checkbox-marked"
|
||||||
size="xs"
|
size="xs"
|
||||||
color="primary"
|
color="primary"
|
||||||
|
|
@ -138,7 +138,7 @@ defineEmits<{
|
||||||
style="color: hsl(var(--text-mute))"
|
style="color: hsl(var(--text-mute))"
|
||||||
class="q-mr-sm"
|
class="q-mr-sm"
|
||||||
/>
|
/>
|
||||||
{{ item }}
|
{{ item.name }}
|
||||||
</div>
|
</div>
|
||||||
</q-item>
|
</q-item>
|
||||||
</q-menu>
|
</q-menu>
|
||||||
|
|
|
||||||
|
|
@ -1,77 +1,89 @@
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { ref } from 'vue';
|
import { onMounted, ref, watch } from 'vue';
|
||||||
import { deleteItem, dialog } from 'src/stores/utils';
|
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
|
import { storeToRefs } from 'pinia';
|
||||||
|
|
||||||
const { t } = useI18n();
|
import { deleteItem, dialog } from 'src/stores/utils';
|
||||||
|
import useProductServiceStore from 'src/stores/product-service';
|
||||||
|
|
||||||
const inputWorkName = ref<HTMLInputElement[]>([]);
|
import NoData from '../NoData.vue';
|
||||||
const newNameIndex = ref();
|
|
||||||
|
|
||||||
const testName = ref([
|
const nameList = defineModel<{ id: string; name: string; isEdit: boolean }[]>(
|
||||||
{ name: 'ทดสอบการขาย 1', isEdit: false },
|
'nameList',
|
||||||
{ name: 'ทดสอบการขาย 2', isEdit: false },
|
{ required: true },
|
||||||
{ name: 'ทดสอบการขาย 3', isEdit: false },
|
);
|
||||||
{ name: 'ทดสอบการขาย 4', isEdit: false },
|
|
||||||
{ name: 'ทดสอบการขาย 5', isEdit: false },
|
|
||||||
]);
|
|
||||||
|
|
||||||
function addWorkName() {
|
const cloneList = ref();
|
||||||
testName.value.push({
|
const isAdd = ref(false);
|
||||||
name: '',
|
const inputName = ref<HTMLInputElement[]>([]);
|
||||||
isEdit: true,
|
|
||||||
});
|
function isWorkNameEdit() {
|
||||||
setTimeout(() => {
|
return cloneList.value.some((i: { isEdit: boolean }) => i.isEdit === true);
|
||||||
inputWorkName.value[testName.value.length - 1].focus();
|
|
||||||
}, 100);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function confirmDelete(items: unknown[], index: number) {
|
async function assignClone() {
|
||||||
dialog({
|
cloneList.value = await JSON.parse(JSON.stringify(nameList.value));
|
||||||
color: 'negative',
|
|
||||||
icon: 'mdi-alert',
|
|
||||||
title: t('deleteConfirmTitle'),
|
|
||||||
actionText: t('delete'),
|
|
||||||
message: t('deleteConfirmMessage'),
|
|
||||||
action: async () => {
|
|
||||||
deleteItem(items, index);
|
|
||||||
},
|
|
||||||
cancel: () => {},
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
defineExpose({
|
||||||
|
isWorkNameEdit,
|
||||||
|
});
|
||||||
|
|
||||||
|
defineEmits<{
|
||||||
|
(e: 'delete', id: string): void;
|
||||||
|
(e: 'edit', id: string, data: { name: string }): void;
|
||||||
|
(e: 'add', data: { name: string; productId: []; order: number }): void;
|
||||||
|
}>();
|
||||||
|
|
||||||
|
onMounted(async () => {
|
||||||
|
await assignClone();
|
||||||
|
});
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => nameList.value.length,
|
||||||
|
async () => {
|
||||||
|
await assignClone();
|
||||||
|
if (!isAdd.value) return;
|
||||||
|
cloneList.value[cloneList.value.length - 1].isEdit = true;
|
||||||
|
setTimeout(() => {
|
||||||
|
inputName.value[cloneList.value.length - 1].focus();
|
||||||
|
isAdd.value = false;
|
||||||
|
}, 150);
|
||||||
|
},
|
||||||
|
);
|
||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
<div class="full-width column no-wrap full-height">
|
<div v-if="cloneList" class="full-width column no-wrap full-height">
|
||||||
<div
|
<div
|
||||||
v-if="true"
|
v-if="cloneList.length > 0"
|
||||||
class="bordered rounded surface-1 flex col column justify-between"
|
class="bordered rounded surface-1 flex col column justify-between"
|
||||||
>
|
>
|
||||||
<q-list class="full-width col scroll">
|
<q-list class="full-width col scroll">
|
||||||
<q-item
|
<q-item
|
||||||
class="items-center row q-px-lg"
|
class="items-center row q-px-lg"
|
||||||
v-for="(i, index) in testName"
|
v-for="(item, index) in cloneList"
|
||||||
:key="index"
|
:key="index"
|
||||||
>
|
>
|
||||||
<!-- outlined -->
|
|
||||||
<q-input
|
<q-input
|
||||||
ref="inputWorkName"
|
ref="inputName"
|
||||||
dense
|
dense
|
||||||
:borderless="!i.isEdit"
|
|
||||||
:readonly="!i.isEdit"
|
|
||||||
:outlined="i.isEdit"
|
|
||||||
class="col q-mr-md"
|
class="col q-mr-md"
|
||||||
v-model="i.name"
|
v-model="item.name"
|
||||||
placeholder="ชื่องาน"
|
placeholder="ชื่องาน"
|
||||||
|
:borderless="!item.isEdit"
|
||||||
|
:readonly="!item.isEdit"
|
||||||
|
:outlined="item.isEdit"
|
||||||
></q-input>
|
></q-input>
|
||||||
<q-btn
|
<q-btn
|
||||||
v-if="!i.isEdit"
|
v-if="!item.isEdit"
|
||||||
id="btn-edit-work-name"
|
id="btn-edit-work-name"
|
||||||
icon="mdi-pencil-outline"
|
icon="mdi-pencil-outline"
|
||||||
|
:disable="isWorkNameEdit()"
|
||||||
dense
|
dense
|
||||||
flat
|
flat
|
||||||
round
|
round
|
||||||
color="primary"
|
color="primary"
|
||||||
@click="i.isEdit = true"
|
@click="item.isEdit = true"
|
||||||
>
|
>
|
||||||
<q-tooltip>Edit</q-tooltip>
|
<q-tooltip>Edit</q-tooltip>
|
||||||
</q-btn>
|
</q-btn>
|
||||||
|
|
@ -83,20 +95,26 @@ function confirmDelete(items: unknown[], index: number) {
|
||||||
flat
|
flat
|
||||||
round
|
round
|
||||||
color="primary"
|
color="primary"
|
||||||
@click="i.isEdit = false"
|
@click="
|
||||||
|
() => {
|
||||||
|
$emit('edit', item.id, { name: item.name }),
|
||||||
|
(item.isEdit = false);
|
||||||
|
}
|
||||||
|
"
|
||||||
>
|
>
|
||||||
<q-tooltip>Save</q-tooltip>
|
<q-tooltip>Save</q-tooltip>
|
||||||
</q-btn>
|
</q-btn>
|
||||||
<q-btn
|
<q-btn
|
||||||
v-if="!i.isEdit"
|
v-if="!item.isEdit"
|
||||||
id="btn-delete-work-name"
|
id="btn-delete-work-name"
|
||||||
|
:disable="isWorkNameEdit()"
|
||||||
icon="mdi-trash-can-outline"
|
icon="mdi-trash-can-outline"
|
||||||
dense
|
dense
|
||||||
flat
|
flat
|
||||||
round
|
round
|
||||||
class="q-ml-md"
|
class="q-ml-md"
|
||||||
color="negative"
|
color="negative"
|
||||||
@click="confirmDelete(testName, index)"
|
@click="$emit('delete', item.id)"
|
||||||
>
|
>
|
||||||
<q-tooltip>Delete</q-tooltip>
|
<q-tooltip>Delete</q-tooltip>
|
||||||
</q-btn>
|
</q-btn>
|
||||||
|
|
@ -109,7 +127,7 @@ function confirmDelete(items: unknown[], index: number) {
|
||||||
round
|
round
|
||||||
class="q-ml-md"
|
class="q-ml-md"
|
||||||
color="negative"
|
color="negative"
|
||||||
@click="i.isEdit = false"
|
@click="assignClone"
|
||||||
>
|
>
|
||||||
<q-tooltip>Cancel</q-tooltip>
|
<q-tooltip>Cancel</q-tooltip>
|
||||||
</q-btn>
|
</q-btn>
|
||||||
|
|
@ -117,7 +135,16 @@ function confirmDelete(items: unknown[], index: number) {
|
||||||
</q-list>
|
</q-list>
|
||||||
|
|
||||||
<div class="bordered-t full-width">
|
<div class="bordered-t full-width">
|
||||||
<q-item clickable @click="addWorkName">
|
<q-item
|
||||||
|
clickable
|
||||||
|
:disable="isWorkNameEdit()"
|
||||||
|
@click="
|
||||||
|
() => {
|
||||||
|
$emit('add', { name: '', productId: [], order: 1 }),
|
||||||
|
(isAdd = true);
|
||||||
|
}
|
||||||
|
"
|
||||||
|
>
|
||||||
<span class="q-px-lg flex items-center app-text-muted-2">
|
<span class="q-px-lg flex items-center app-text-muted-2">
|
||||||
<q-icon name="mdi-plus" class="q-mr-md" />
|
<q-icon name="mdi-plus" class="q-mr-md" />
|
||||||
เพิ่มงานใหม่
|
เพิ่มงานใหม่
|
||||||
|
|
|
||||||
|
|
@ -180,6 +180,7 @@ const serviceTab = [
|
||||||
];
|
];
|
||||||
|
|
||||||
const workItems = ref<WorkItems[]>([]);
|
const workItems = ref<WorkItems[]>([]);
|
||||||
|
const workNameRef = ref();
|
||||||
|
|
||||||
const currentServiceTab = ref('serviceInformation');
|
const currentServiceTab = ref('serviceInformation');
|
||||||
const propertiesDialog = ref<boolean>(false);
|
const propertiesDialog = ref<boolean>(false);
|
||||||
|
|
@ -605,6 +606,32 @@ async function submitGroup() {
|
||||||
clearFormGroup();
|
clearFormGroup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function confirmDeleteWork(id: string) {
|
||||||
|
dialog({
|
||||||
|
color: 'negative',
|
||||||
|
icon: 'mdi-alert',
|
||||||
|
title: t('deleteConfirmTitle'),
|
||||||
|
actionText: t('delete'),
|
||||||
|
message: t('deleteConfirmMessage'),
|
||||||
|
action: async () => {
|
||||||
|
deleteWork(id);
|
||||||
|
},
|
||||||
|
cancel: () => {},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function confirmCloseWork() {
|
||||||
|
dialog({
|
||||||
|
color: 'negative',
|
||||||
|
icon: 'mdi-alert',
|
||||||
|
title: t('deleteConfirmTitle'),
|
||||||
|
actionText: t('delete'),
|
||||||
|
message: t('deleteConfirmMessage'),
|
||||||
|
action: async () => {},
|
||||||
|
cancel: () => {},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const tempValueProperties = ref<Attributes>({
|
const tempValueProperties = ref<Attributes>({
|
||||||
additional: [],
|
additional: [],
|
||||||
});
|
});
|
||||||
|
|
@ -1584,7 +1611,6 @@ watch(currentStatus, async () => {
|
||||||
<ServiceProperties
|
<ServiceProperties
|
||||||
v-model:properties-option="propertiesOption"
|
v-model:properties-option="propertiesOption"
|
||||||
v-model:form-service-properties="tempValueProperties"
|
v-model:form-service-properties="tempValueProperties"
|
||||||
@add-properties="console.log('')"
|
|
||||||
/>
|
/>
|
||||||
</FormDialog>
|
</FormDialog>
|
||||||
|
|
||||||
|
|
@ -1592,11 +1618,18 @@ watch(currentStatus, async () => {
|
||||||
<FormDialog
|
<FormDialog
|
||||||
no-address
|
no-address
|
||||||
no-app-box
|
no-app-box
|
||||||
|
no-footer
|
||||||
width="65%"
|
width="65%"
|
||||||
title="จัดการ"
|
title="จัดการ"
|
||||||
v-model:modal="manageWorkNameDialog"
|
v-model:modal="manageWorkNameDialog"
|
||||||
>
|
>
|
||||||
<WorkNameManagement />
|
<WorkNameManagement
|
||||||
|
ref="workNameRef"
|
||||||
|
v-model:nameList="workNameItems"
|
||||||
|
@delete="confirmDeleteWork"
|
||||||
|
@edit="editWork"
|
||||||
|
@add="createWork"
|
||||||
|
/>
|
||||||
</FormDialog>
|
</FormDialog>
|
||||||
|
|
||||||
<!-- edit service -->
|
<!-- edit service -->
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue