feat: เพิ่ม สินค้า

This commit is contained in:
Net 2024-06-20 15:05:44 +07:00
parent 48d2214f93
commit f49b3ecdc0
2 changed files with 107 additions and 35 deletions

View file

@ -3,32 +3,47 @@ import { ref } from 'vue';
import AppBox from 'components/app/AppBox.vue'; import AppBox from 'components/app/AppBox.vue';
const addedProduct = ref<boolean>(false); const addedProduct = ref<boolean>(false);
import { ProductList } from 'src/stores/product-service/types';
const baseUrl = ref<string>(import.meta.env.VITE_API_BASE_URL); const baseUrl = ref<string>(import.meta.env.VITE_API_BASE_URL);
defineProps<{
title?: string; withDefaults(
code?: string; defineProps<{
dense?: boolean; data: ProductList;
outlined?: boolean; title?: string;
readonly?: boolean;
separator?: boolean; dense?: boolean;
typeProduct?: string; outlined?: boolean;
price?: number; readonly?: boolean;
process?: number; separator?: boolean;
id?: string; typeProduct?: string;
status?: boolean; status?: boolean;
}>();
isAddProduct?: boolean;
isSelected?: boolean;
}>(),
{
isSelected: false,
},
);
</script> </script>
<template> <template>
<AppBox <AppBox
no-padding no-padding
bordered bordered
:class="{ 'is-add-product': isAddProduct }"
style="box-shadow: var(--shadow-3); width: 240px; height: 286px" style="box-shadow: var(--shadow-3); width: 240px; height: 286px"
@click="$emit('select', data)"
> >
<div class="q-pa-sm" :class="{ inactive: status }"> <div class="q-pa-sm" :class="{ inactive: status }">
<div class="row flex justify-between text-bold"> <div class="row flex justify-between text-bold">
<div class="col-9">{{ title ?? 'title' }}</div> <div class="col-9">{{ title ?? 'title' }}</div>
<div class="col-3 relative-position" style="left: 10px; bottom: 10px"> <div
v-if="isSelected === false"
class="col-3 relative-position"
style="left: 10px; bottom: 10px"
>
<q-btn <q-btn
flat flat
round round
@ -79,8 +94,17 @@ defineProps<{
</q-menu> </q-menu>
</q-btn> </q-btn>
</div> </div>
<q-avatar
v-if="isAddProduct"
:style="`background-color: var(${typeProduct === 'product' ? '--green-10' : '--orange-8'})`"
size="18px"
text-color="white"
>
1
</q-avatar>
</div> </div>
<div class="app-text-muted">{{ code ?? 'code' }}</div> <div class="app-text-muted">{{ data.code ?? 'code' }}</div>
<div class="flex justify-start text-bold"> <div class="flex justify-start text-bold">
<div <div
v-if="typeProduct === 'work'" v-if="typeProduct === 'work'"
@ -98,7 +122,7 @@ defineProps<{
class="flex justify-end text-bold" class="flex justify-end text-bold"
style="color: var(--green-10)" style="color: var(--green-10)"
> >
฿ {{ price }} ฿ {{ data.price }}
</div> </div>
<div <div
@ -106,7 +130,7 @@ defineProps<{
:style="`background-color: var(${typeProduct === 'product' ? '--green-0' : '--orange-0'})`" :style="`background-color: var(${typeProduct === 'product' ? '--green-0' : '--orange-0'})`"
> >
<q-img <q-img
:src="`${baseUrl}/product/${id}/image`" :src="`${baseUrl}/product/${data.id}/image`"
style="height: 86px; max-width: 100px" style="height: 86px; max-width: 100px"
> >
<template #error> <template #error>
@ -138,20 +162,11 @@ defineProps<{
class="surface-0 rounded q-pa-xs app-text-muted" class="surface-0 rounded q-pa-xs app-text-muted"
size="20px" size="20px"
/> />
{{ process }} {{ data.process }}
</div> </div>
<div> <div v-if="isSelected === false">
<q-btn <q-btn
v-if="addedProduct"
unelevated
class="q-mr-sm text-white"
label="เพิ่มสินค้าแล้ว (1)"
@click="addedProduct = false"
style="background-color: var(--green-10)"
/>
<q-btn
v-else
unelevated unelevated
dense dense
class="q-mr-sm app-text-info" class="q-mr-sm app-text-info"
@ -173,4 +188,8 @@ defineProps<{
.inactive { .inactive {
opacity: 0.4; opacity: 0.4;
} }
.is-add-product {
border-color: var(--green-10);
}
</style> </style>

View file

@ -155,6 +155,8 @@ const serviceTab = [
const currentServiceTab = ref('serviceInformation'); const currentServiceTab = ref('serviceInformation');
const propertiesDialog = ref<boolean>(false); const propertiesDialog = ref<boolean>(false);
const selectProduct = ref<ProductList[]>([]);
const currentId = ref<string>(''); const currentId = ref<string>('');
const currentIdType = ref<string>(''); const currentIdType = ref<string>('');
const currentIdService = ref<string>(''); const currentIdService = ref<string>('');
@ -418,8 +420,6 @@ async function assignFormDataProductService(id: string) {
} }
function assignFormDataProduct(data: ProductList) { function assignFormDataProduct(data: ProductList) {
console.log(data.detail);
statusToggle.value = data.status === 'INACTIVE' ? false : true; statusToggle.value = data.status === 'INACTIVE' ? false : true;
formDataProduct.value = { formDataProduct.value = {
@ -1032,12 +1032,9 @@ watch(currentStatus, async () => {
> >
<div v-for="i in product" :key="i.id"> <div v-for="i in product" :key="i.id">
<TotalProductCardComponent <TotalProductCardComponent
:data="i"
typeProduct="product" typeProduct="product"
:title="i.name" :title="i.name"
:code="i.code"
:price="i.price"
:process="i.process"
:id="i.id"
:status="i.status === 'INACTIVE' ? true : false" :status="i.status === 'INACTIVE' ? true : false"
@menuViewDetail=" @menuViewDetail="
() => { () => {
@ -1178,7 +1175,63 @@ watch(currentStatus, async () => {
</template> </template>
</q-input> </q-input>
</div> </div>
<TotalProductComponent />
<AppBox
class="row full-width"
no-padding
style="
width: 75vw;
display: grid;
background: none;
grid-template-columns: repeat(4, 1fr);
gap: var(--size-3);
"
>
<div v-for="i in product" :key="i.id">
<TotalProductCardComponent
:isAddProduct="!!selectProduct.find((v) => v.id === i.id)"
:isSelected="true"
:data="i"
typeProduct="product"
:title="i.name"
:status="i.status === 'INACTIVE' ? true : false"
@menuViewDetail="
() => {
currentIdProduct = i.id;
assignFormDataProduct(i);
dialogProductEdit = true;
}
"
@menuEdit="
() => {
currentIdProduct = i.id;
infoProductEdit = true;
assignFormDataProduct(i);
dialogProductEdit = true;
}
"
@viewDetail="
() => {
currentIdProduct = i.id;
infoProductEdit = false;
assignFormDataProduct(i);
dialogProductEdit = true;
}
"
@select="
(data) => {
const tempValue = selectProduct.find((v) => v.id === i.id);
if (tempValue) {
selectProduct = selectProduct.filter((v) => v.id !== i.id);
} else {
selectProduct.push(data);
}
}
"
/>
</div>
</AppBox>
</div> </div>
</FormDialog> </FormDialog>