refactor: product create

This commit is contained in:
puriphatt 2024-08-09 10:56:27 +00:00
parent 676c2c5ebf
commit 5e4cfb747d
8 changed files with 325 additions and 217 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 535 KiB

View file

@ -23,7 +23,6 @@ defineProps<{
dense?: boolean; dense?: boolean;
outlined?: boolean; outlined?: boolean;
readonly?: boolean; readonly?: boolean;
separator?: boolean;
isType?: boolean; isType?: boolean;
}>(); }>();
@ -51,162 +50,176 @@ const branchFilter = selectFilterOptionRefMod(
</script> </script>
<template> <template>
<div class="col-3 app-text-muted"> <div class="row col-12">
{{ $t(`formDialogTitleInformation`) }} <div class="col-12 q-pb-sm text-weight-bold text-body1 row items-center">
</div> <q-icon
flat
size="xs"
class="q-pa-sm rounded q-mr-sm"
color="info"
name="mdi-office-building-outline"
style="background-color: var(--surface-3)"
/>
{{ $t(`formDialogTitleInformation`) }}
</div>
<div class="col-9 row q-col-gutter-md"> <div class="col-12 row q-col-gutter-sm">
<q-select <q-select
outlined outlined
clearable clearable
use-input use-input
fill-input fill-input
emit-value emit-value
map-options map-options
hide-selected hide-selected
hide-bottom-space hide-bottom-space
input-debounce="0" input-debounce="0"
class="col-3" class="col-3"
v-model="code" v-model="code"
id="select-br-id" id="select-br-id"
option-label="label" option-label="label"
option-value="value" option-value="value"
lazy-rules="ondemand" lazy-rules="ondemand"
:dense="dense" :dense="dense"
:readonly="readonly" :readonly="readonly"
:options="codeOptions" :options="codeOptions"
:label="$t('productCode')" :label="$t('productCode')"
:hide-dropdown-icon="readonly" :hide-dropdown-icon="readonly"
:rules="[(val: string) => !!val]" :rules="[(val: string) => !!val]"
@filter="codeFilter" @filter="codeFilter"
> >
<template v-slot:no-option> <template v-slot:no-option>
<q-item> <q-item>
<q-item-section class="text-grey"> <q-item-section class="text-grey">
{{ $t('noResults') }} {{ $t('noResults') }}
</q-item-section> </q-item-section>
</q-item> </q-item>
</template> </template>
</q-select> </q-select>
<q-select <q-select
outlined outlined
clearable clearable
use-input use-input
fill-input fill-input
emit-value emit-value
map-options map-options
hide-selected hide-selected
hide-bottom-space hide-bottom-space
input-debounce="0" input-debounce="0"
class="col-3" class="col-3"
option-value="id" option-value="id"
option-label="name" option-label="name"
lazy-rules="ondemand" lazy-rules="ondemand"
id="input-source-nationality" id="input-source-nationality"
v-model="registeredBranchId" v-model="registeredBranchId"
:dense="dense" :dense="dense"
:readonly="readonly" :readonly="readonly"
:options="branchOptions" :options="branchOptions"
:hide-dropdown-icon="readonly" :hide-dropdown-icon="readonly"
:label="$t('registeredBranch')" :label="$t('registeredBranch')"
:rules="[ :rules="[
(val) => { (val) => {
const roles = getRole() || []; const roles = getRole() || [];
const isSpecialRole = ['admin', 'system', 'head_of_admin'].some( const isSpecialRole = ['admin', 'system', 'head_of_admin'].some(
(role) => roles.includes(role), (role) => roles.includes(role),
); );
return isSpecialRole || !!val || 'กรุณากรอกข้อมูล'; return isSpecialRole || !!val || 'กรุณากรอกข้อมูล';
}, },
]" ]"
@filter="branchFilter" @filter="branchFilter"
> >
<template v-slot:no-option> <template v-slot:no-option>
<q-item> <q-item>
<q-item-section class="text-grey"> <q-item-section class="text-grey">
{{ $t('noResults') }} {{ $t('noResults') }}
</q-item-section> </q-item-section>
</q-item> </q-item>
</template> </template>
</q-select> </q-select>
<q-input <q-input
lazy-rules="ondemand" lazy-rules="ondemand"
for="input-name" for="input-name"
:dense="dense" :dense="dense"
outlined
:readonly="readonly"
:borderless="readonly"
hide-bottom-space
class="col-6"
:label="$t('productName')"
v-model="name"
/>
<q-input
lazy-rules="ondemand"
for="input-detail"
:dense="dense"
outlined
:readonly="readonly"
:borderless="readonly"
hide-bottom-space
type="textarea"
class="col-12"
:label="$t('serviceDetail')"
v-model="detail"
autogrow
/>
<div class="col-12">
<q-field
class="full-width"
outlined outlined
:readonly="readonly" :readonly="readonly"
:borderless="readonly" :borderless="readonly"
:label="$t('detail')" hide-bottom-space
stack-label class="col-6"
dense :label="$t('productName')"
> v-model="name"
<q-editor />
dense <q-input
v-model="remark" lazy-rules="ondemand"
min-height="5rem" for="input-process"
class="full-width q-mt-sm q-mb-xs" :dense="dense"
:flat="!readonly" outlined
:readonly="readonly"
:borderless="readonly"
hide-bottom-space
class="col-3"
:label="$t('productProcessingTime')"
v-model="process"
type="number"
/>
<q-input
lazy-rules="ondemand"
for="input-detail"
:dense="dense"
outlined
:readonly="readonly"
:borderless="readonly"
hide-bottom-space
type="textarea"
class="col-12"
:label="$t('serviceDetail')"
v-model="detail"
/>
<div class="col-12">
<q-field
class="full-width"
outlined
:readonly="readonly" :readonly="readonly"
:toolbar-color=" :borderless="readonly"
readonly ? 'disabled' : $q.dark.isActive ? 'white' : '' :label="$t('detail')"
" stack-label
:toolbar-toggle-color="readonly ? 'disabled' : 'primary'" dense
style=" >
cursor: auto; <q-editor
color: var(--foreground); dense
border-color: var(--surface-3); v-model="remark"
" min-height="5rem"
/> class="full-width q-mt-sm q-mb-xs"
</q-field> :flat="!readonly"
:readonly="readonly"
:toolbar-color="
readonly ? 'disabled' : $q.dark.isActive ? 'white' : ''
"
:toolbar-toggle-color="readonly ? 'disabled' : 'primary'"
style="
cursor: auto;
color: var(--foreground);
border-color: var(--surface-3);
"
/>
</q-field>
</div>
<!-- <q-input
lazy-rules="ondemand"
for="input-detail"
:dense="dense"
outlined
:readonly="readonly"
:borderless="readonly"
hide-bottom-space
type="textarea"
class="col-12"
:label="$t('formDialogInputRemark')"
v-model="detail"
/> -->
</div> </div>
<q-input
lazy-rules="ondemand"
for="input-process"
:dense="dense"
outlined
:readonly="readonly"
:borderless="readonly"
hide-bottom-space
class="col-4"
:label="$t('productProcessingTime')"
v-model="process"
type="number"
/>
</div> </div>
<q-separator
v-if="separator"
class="col-12 q-mb-md"
style="padding-block: 0.5px; margin-top: 32px"
/>
</template> </template>
<style scoped> <style scoped>

View file

@ -13,46 +13,58 @@ defineProps<{
</script> </script>
<template> <template>
<div class="col-3 app-text-muted"> {{ $t('priceInformation') }}</div> <div class="row col-12">
<div class="col-9 row q-col-gutter-md"> <div class="col-12 q-pb-sm text-weight-bold text-body1 row items-center">
<q-input <q-icon
lazy-rules="ondemand" flat
:dense="dense" size="xs"
outlined class="q-pa-sm rounded q-mr-sm"
:readonly="readonly" color="info"
:borderless="readonly" name="mdi-cash"
hide-bottom-space style="background-color: var(--surface-3)"
class="col-4" />
type="number" {{ $t('priceInformation') }}
:label="$t('salePrice')" </div>
v-model="price" <div class="col-12 row q-col-gutter-sm">
/> <q-input
lazy-rules="ondemand"
:dense="dense"
outlined
:readonly="readonly"
:borderless="readonly"
hide-bottom-space
class="col-4"
type="number"
:label="$t('salePrice')"
v-model="price"
/>
<q-input <q-input
lazy-rules="ondemand" lazy-rules="ondemand"
:dense="dense" :dense="dense"
outlined outlined
:readonly="readonly" :readonly="readonly"
:borderless="readonly" :borderless="readonly"
hide-bottom-space hide-bottom-space
class="col-4" class="col-4"
type="number" type="number"
:label="$t('agentPrice')" :label="$t('agentPrice')"
v-model="agentPrice" v-model="agentPrice"
/> />
<q-input <q-input
lazy-rules="ondemand" lazy-rules="ondemand"
:dense="dense" :dense="dense"
outlined outlined
:readonly="readonly" :readonly="readonly"
:borderless="readonly" :borderless="readonly"
hide-bottom-space hide-bottom-space
class="col-4" class="col-4"
type="number" type="number"
:label="$t('processingPrice')" :label="$t('processingPrice')"
v-model="serviceCharge" v-model="serviceCharge"
/> />
</div>
</div> </div>
</template> </template>

View file

@ -1,5 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref } from 'vue'; import { ref } from 'vue';
import ToggleButton from './button/ToggleButton.vue';
defineProps<{ defineProps<{
icon?: string; icon?: string;
@ -12,6 +13,8 @@ defineProps<{
toggleTitle?: string; toggleTitle?: string;
hideFade?: boolean; hideFade?: boolean;
hideActive?: boolean;
noImageAction?: boolean;
active?: boolean; active?: boolean;
readonly?: boolean; readonly?: boolean;
useToggle?: boolean; useToggle?: boolean;
@ -73,11 +76,12 @@ const showOverlay = ref(false);
<q-avatar <q-avatar
size="6rem" size="6rem"
font-size="3rem" font-size="3rem"
class="cursor-pointer relative-position" class="relative-position"
style="z-index: 1" style="z-index: 1"
:style="{ :style="{
background: `${bgColor || 'var(--brand-1)'}`, background: `${bgColor || 'var(--brand-1)'}`,
color: `${color || 'white'}`, color: `${color || 'white'}`,
cursor: `${noImageAction ? 'default' : 'pointer'}`,
}" }"
@mouseover="showOverlay = true" @mouseover="showOverlay = true"
@mouseleave="showOverlay = false" @mouseleave="showOverlay = false"
@ -98,6 +102,7 @@ const showOverlay = ref(false);
</q-img> </q-img>
<q-icon id="profile-view" v-else :name="icon || 'mdi-account'" /> <q-icon id="profile-view" v-else :name="icon || 'mdi-account'" />
<q-badge <q-badge
v-if="!hideActive"
class="absolute-bottom-right" class="absolute-bottom-right"
style=" style="
border-radius: 10px; border-radius: 10px;

View file

@ -196,4 +196,7 @@ export default {
passportExpire: 'Passport Expiration Date', passportExpire: 'Passport Expiration Date',
pleaseInformation: 'Please enter information', pleaseInformation: 'Please enter information',
// product
formDialogTitleUseStatus: 'Status',
}; };

View file

@ -196,4 +196,7 @@ export default {
passportExpire: 'วันหมดอายุของเอกสาร(visa ,passport)', passportExpire: 'วันหมดอายุของเอกสาร(visa ,passport)',
pleaseInformation: 'โปรดกรอกข้อมูล', pleaseInformation: 'โปรดกรอกข้อมูล',
// product
formDialogTitleUseStatus: 'สถานะการใช้งาน',
}; };

View file

@ -217,6 +217,7 @@ const dialogProductServiceType = ref(false);
const dialogTotalProduct = ref(false); const dialogTotalProduct = ref(false);
const productMode = ref<'group' | 'type' | 'service' | 'product'>('group'); const productMode = ref<'group' | 'type' | 'service' | 'product'>('group');
const productTab = ref(1);
const productGroup = ref<ProductGroup[]>(); const productGroup = ref<ProductGroup[]>();
const productType = ref<ProductGroup[]>(); const productType = ref<ProductGroup[]>();
const product = ref<(ProductList & { type: 'product' })[]>(); const product = ref<(ProductList & { type: 'product' })[]>();
@ -1414,6 +1415,7 @@ watch(
icon="mdi-folder-multiple-plus" icon="mdi-folder-multiple-plus"
@click=" @click="
async () => { async () => {
productTab = 1;
clearFormProduct(); clearFormProduct();
await fetchListOfOptionBranch(); await fetchListOfOptionBranch();
dialogProduct = true; dialogProduct = true;
@ -2089,6 +2091,13 @@ watch(
<template v-slot:body="props"> <template v-slot:body="props">
<q-tr <q-tr
:style="
props.rowIndex % 2 !== 0
? $q.dark.isActive
? 'background: hsl(var(--gray-11-hsl)/0.2)'
: `background: #f9fafc`
: ''
"
:id="`enter-${props.row.name}`" :id="`enter-${props.row.name}`"
class="cursor-pointer" class="cursor-pointer"
:class="{ :class="{
@ -2342,6 +2351,7 @@ watch(
<q-item-section class="q-py-sm"> <q-item-section class="q-py-sm">
<div class="q-pa-sm surface-2 rounded"> <div class="q-pa-sm surface-2 rounded">
<q-toggle <q-toggle
color="positive"
:id="`view-detail-btn-${props.row.name}-status`" :id="`view-detail-btn-${props.row.name}-status`"
dense dense
size="sm" size="sm"
@ -3162,6 +3172,7 @@ watch(
<q-item-section class="q-py-sm"> <q-item-section class="q-py-sm">
<div class="q-pa-sm surface-2 rounded"> <div class="q-pa-sm surface-2 rounded">
<q-toggle <q-toggle
color="positive"
:id="`view-detail-btn-${props.row.name}-status`" :id="`view-detail-btn-${props.row.name}-status`"
dense dense
size="sm" size="sm"
@ -3334,9 +3345,13 @@ watch(
> >
<div class="q-mx-lg q-mt-lg"> <div class="q-mx-lg q-mt-lg">
<ProfileBanner <ProfileBanner
readonly
noImageAction
active active
hideFade hideFade
hideActive
useToggle useToggle
:toggleTitle="$t('formDialogTitleUseStatus')"
:icon="productMode === 'group' ? 'mdi-folder' : 'mdi-folder-table'" :icon="productMode === 'group' ? 'mdi-folder' : 'mdi-folder-table'"
:title="formDataGroup.name" :title="formDataGroup.name"
:caption="formDataGroup.code" :caption="formDataGroup.code"
@ -3363,7 +3378,6 @@ watch(
: '--violet-11' : '--violet-11'
}-hsl)/0.1)`" }-hsl)/0.1)`"
v-model:toggle-status="currentStatusGroupType" v-model:toggle-status="currentStatusGroupType"
@view="imageDialog = true"
@update:toggle-status=" @update:toggle-status="
() => { () => {
currentStatusGroupType = currentStatusGroupType =
@ -3466,6 +3480,7 @@ watch(
<InfoForm> <InfoForm>
<div class="q-mx-lg q-mt-lg"> <div class="q-mx-lg q-mt-lg">
<ProfileBanner <ProfileBanner
noImageAction
:active="currentStatusGroupType !== 'INACTIVE'" :active="currentStatusGroupType !== 'INACTIVE'"
hideFade hideFade
useToggle useToggle
@ -3497,7 +3512,6 @@ watch(
bgColor: 'var(--surface-1)', bgColor: 'var(--surface-1)',
}, },
]" ]"
@view="imageDialog = true"
@update:toggle-status=" @update:toggle-status="
async (v) => { async (v) => {
await triggerChangeStatus(currentIdGroupType, v, productMode); await triggerChangeStatus(currentIdGroupType, v, productMode);
@ -3693,9 +3707,8 @@ watch(
</FormDialog> </FormDialog>
<!-- Add Product --> <!-- Add Product -->
<FormDialog <DialogForm
v-model:modal="dialogProduct" v-model:modal="dialogProduct"
noAddress
:title="$t('buttonAddProduct')" :title="$t('buttonAddProduct')"
:submit=" :submit="
() => { () => {
@ -3709,8 +3722,7 @@ watch(
} }
" "
> >
<template #prepend> <!-- <ProfileUpload
<ProfileUpload
prefix-id="form-dialog-product" prefix-id="form-dialog-product"
isProduct isProduct
v-model:url-profile="profileUrl" v-model:url-profile="profileUrl"
@ -3718,31 +3730,84 @@ watch(
v-model:profile-submit="profileSubmit" v-model:profile-submit="profileSubmit"
@input-file="inputFile.click()" @input-file="inputFile.click()"
@cancel-file="inputFile.value = ''" @cancel-file="inputFile.value = ''"
/> -->
<div class="q-mx-lg q-mt-lg">
<ProfileBanner
hideFade
useToggle
hideActive
:toggleTitle="$t('formDialogTitleUseStatus')"
img="/images/product-avatar.png"
fallbackCover="/images/product-banner.png"
bgColor="#ebf1ee"
:menu="[
{
icon: 'mdi-office-building-outline',
color: 'hsl(var(--info-bg))',
bgColor: 'var(--surface-1)',
},
]"
/> />
</template> </div>
<template #information> <div
<BasicInfoProduct class="col surface-1 q-ma-lg rounded bordered scroll row relative-position"
v-model:options-branch="branchOption" id="group-form"
v-model:registered-branch-id="formDataProduct.registeredBranchId" >
v-model:detail="formDataProduct.detail" <div
v-model:remark="formDataProduct.remark" class="col"
v-model:name="formDataProduct.name" style="height: 100%; max-height: 100; overflow-y: auto"
v-model:code="formDataProduct.code" v-if="$q.screen.gt.sm"
v-model:process="formDataProduct.process" >
dense <div class="q-py-md q-pl-md q-pr-sm">
separator <q-item
/> v-for="v in 2"
</template> :key="v"
<template #person> dense
<PriceDataComponent clickable
v-model:price="formDataProduct.price" class="no-padding items-center rounded full-width"
v-model:agent-price="formDataProduct.agentPrice" :class="{ 'q-mt-xs': v > 1 }"
v-model:service-charge="formDataProduct.serviceCharge" active-class="product-form-active"
dense :active="productTab === v"
/> @click="productTab = v"
</template> >
</FormDialog> <span class="full-width q-py-sm" style="padding-inline: 20px">
{{
v === 0
? $t('formDialogTitleInformation')
: $t('priceInformation')
}}
</span>
</q-item>
</div>
</div>
<div
class="col-12 col-md-10 q-py-md q-pr-md q-pl-sm"
id="customer-form-content"
style="height: 100%; max-height: 100%; overflow-y: auto"
>
<BasicInfoProduct
v-if="productTab === 1"
v-model:options-branch="branchOption"
v-model:registered-branch-id="formDataProduct.registeredBranchId"
v-model:detail="formDataProduct.detail"
v-model:remark="formDataProduct.remark"
v-model:name="formDataProduct.name"
v-model:code="formDataProduct.code"
v-model:process="formDataProduct.process"
dense
separator
/>
<PriceDataComponent
v-if="productTab === 2"
v-model:price="formDataProduct.price"
v-model:agent-price="formDataProduct.agentPrice"
v-model:service-charge="formDataProduct.serviceCharge"
dense
/>
</div>
</div>
</DialogForm>
<!-- edit product --> <!-- edit product -->
<FormDialog <FormDialog
@ -4184,6 +4249,7 @@ watch(
<q-item clickable v-ripple> <q-item clickable v-ripple>
<q-item-section avatar> <q-item-section avatar>
<q-toggle <q-toggle
color="positive"
dense dense
:id="`view-detail-btn-${currentNode.name}-status`" :id="`view-detail-btn-${currentNode.name}-status`"
size="sm" size="sm"
@ -4354,4 +4420,10 @@ watch(
* :deep(.q-icon.mdi-play) { * :deep(.q-icon.mdi-play) {
display: none; display: none;
} }
.product-form-active {
background-color: hsla(var(--info-bg) / 0.2);
color: hsl(var(--info-bg));
font-weight: 600;
}
</style> </style>