jws-frontend/src/pages/13_receipt/MainPage.vue
Aif 2320883cb6
Some checks failed
Spell Check / Spell Check with Typos (push) Failing after 5s
feat: i18n register name en
2025-10-14 14:50:18 +07:00

458 lines
15 KiB
Vue

<script lang="ts" setup>
// NOTE: Library
import { computed, onMounted, reactive, ref, watch } from 'vue';
import { storeToRefs } from 'pinia';
// NOTE: Components
import StatCardComponent from 'src/components/StatCardComponent.vue';
import NoData from 'src/components/NoData.vue';
import PaginationComponent from 'src/components/PaginationComponent.vue';
import PaginationPageSize from 'src/components/PaginationPageSize.vue';
import TableReceipt from './TableReceipt.vue';
import QuotationCard from 'src/components/05_quotation/QuotationCard.vue';
// NOTE: Stores & Type
import { useNavigator } from 'src/stores/navigator';
import { columns, hslaColors } from './constants';
import useFlowStore from 'src/stores/flow';
import { usePayment, useReceipt } from 'src/stores/payment';
import { PaymentDataStatus } from 'src/stores/payment/types';
import { useQuasar } from 'quasar';
import AdvanceSearch from 'src/components/shared/AdvanceSearch.vue';
const $q = useQuasar();
const navigatorStore = useNavigator();
const flowStore = useFlowStore();
const receiptStore = useReceipt();
const { data, page, pageMax, pageSize } = storeToRefs(receiptStore);
// NOTE: Variable
const pageState = reactive({
hideStat: false,
statusFilter: 'None' as 'None' | PaymentDataStatus,
inputSearch: '',
fieldSelected: [...columns.map((v) => v.name)],
gridView: false,
total: 0,
searchDate: [],
});
const fieldSelectedOption = computed(() => {
return columns.map((v) => ({
label: v.label,
value: v.name,
}));
});
async function fetchList(opts?: { rotateFlowId?: boolean }) {
const ret = await receiptStore.getReceiptList({
page: page.value,
pageSize: pageSize.value,
query: pageState.inputSearch,
startDate: pageState.searchDate[0],
endDate: pageState.searchDate[1],
});
if (ret) {
data.value = $q.screen.xs ? [...data.value, ...ret.result] : ret.result;
pageState.total = ret.total;
pageMax.value = Math.ceil(ret.total / pageSize.value);
}
if (opts?.rotateFlowId) flowStore.rotate();
}
function triggerView(opts: { quotationId: string }) {
const url = new URL('/quotation/view?tab=receipt', window.location.origin);
localStorage.setItem(
'new-quotation',
JSON.stringify({
quotationId: opts.quotationId,
statusDialog: 'info',
}),
);
window.open(url.toString(), '_blank');
}
const paymentStore = usePayment();
async function viewDocExample(id: string) {
const url = await paymentStore.getFlowAccount(id);
if (url) {
window.open(url.data.link, '_blank');
}
}
onMounted(async () => {
pageState.gridView = $q.screen.lt.md ? true : false;
navigatorStore.current.title = 'receipt.title';
navigatorStore.current.path = [{ text: 'receipt.caption', i18n: true }];
await fetchList({ rotateFlowId: true });
});
watch(
[
() => pageState.inputSearch,
() => pageState.statusFilter,
() => pageSize.value,
() => pageState.searchDate,
],
() => {
page.value = 1;
data.value = [];
fetchList({ rotateFlowId: true });
},
);
</script>
<template>
<div class="column full-height no-wrap">
<!-- SEC: stat -->
<section class="text-body-2 q-mb-xs flex items-center">
{{ $t('receipt.dataSum') }}
<q-badge
rounded
class="q-ml-sm"
style="
background-color: hsla(var(--info-bg) / 0.15);
color: hsl(var(--info-bg));
"
>
{{ pageState.total }}
</q-badge>
<q-btn
class="q-ml-sm"
icon="mdi-pin-outline"
color="primary"
size="sm"
flat
dense
rounded
@click="pageState.hideStat = !pageState.hideStat"
:style="pageState.hideStat ? 'rotate: 90deg' : ''"
style="transition: 0.1s ease-in-out"
/>
</section>
<transition name="slide">
<div v-if="!pageState.hideStat" class="scroll q-mb-md">
<div style="display: inline-block">
<StatCardComponent
labelI18n
:branch="[
{
icon: 'fluent:receipt-money-16-regular',
count: pageState.total,
label: 'quotation.status.PaymentSuccess',
color: 'light-green',
},
]"
:dark="$q.dark.isActive"
/>
</div>
</div>
</transition>
<section class="col surface-1 rounded bordered overflow-hidden">
<div class="column full-height">
<!-- SEC: header content -->
<header
class="row surface-3 justify-between full-width items-center bordered-b"
style="z-index: 1"
>
<div class="row q-py-sm q-px-md justify-between full-width">
<q-input
for="input-search"
outlined
dense
:label="$t('general.search')"
class="col col-md-3"
:bg-color="$q.dark.isActive ? 'dark' : 'white'"
v-model="pageState.inputSearch"
debounce="200"
>
<template #prepend>
<q-icon name="mdi-magnify" />
</template>
<template v-slot:append>
<q-separator vertical inset class="q-mr-xs" />
<AdvanceSearch
v-model="pageState.searchDate"
:active="$q.screen.lt.md && pageState.statusFilter !== 'None'"
>
<div
v-if="$q.screen.lt.md"
class="q-mt-sm text-weight-medium"
>
{{ $t('general.status') }}
</div>
<q-select
v-if="$q.screen.lt.md"
ref="refFilter"
v-model="pageState.statusFilter"
outlined
dense
option-value="value"
option-label="label"
map-options
emit-value
:for="'field-select-status'"
:options="[
{
label: $t('general.all'),
value: 'None',
},
]"
/>
</AdvanceSearch>
</template>
</q-input>
<div class="row col-md-5" style="white-space: nowrap">
<q-select
v-if="$q.screen.gt.sm"
ref="refFilter"
v-model="pageState.statusFilter"
outlined
dense
option-value="value"
option-label="label"
class="col"
:class="{ 'offset-md-5': pageState.gridView }"
map-options
emit-value
:for="'field-select-status'"
:hide-dropdown-icon="$q.screen.lt.sm"
:options="[
{
label: $t('general.all'),
value: 'None',
},
]"
/>
<q-select
v-if="!pageState.gridView"
id="select-field"
for="select-field"
class="col q-ml-sm"
:options="
fieldSelectedOption.map((v) => ({
...v,
label: v.label && $t(v.label),
}))
"
:display-value="$t('general.displayField')"
:hide-dropdown-icon="$q.screen.lt.sm"
v-model="pageState.fieldSelected"
option-label="label"
option-value="value"
map-options
emit-value
outlined
multiple
dense
/>
<q-btn-toggle
id="btn-mode"
v-model="pageState.gridView"
dense
class="no-shadow bordered rounded surface-1 q-ml-sm"
:toggle-color="$q.dark.isActive ? 'grey-9' : 'grey-2'"
size="xs"
:options="[
{ value: true, slot: 'folder' },
{ value: false, slot: 'list' },
]"
>
<template v-slot:folder>
<q-icon
name="mdi-view-grid-outline"
size="16px"
class="q-px-sm q-py-xs rounded"
:style="{
color: $q.dark.isActive
? pageState.gridView
? '#C9D3DB '
: '#787B7C'
: pageState.gridView
? '#787B7C'
: '#C9D3DB',
}"
/>
</template>
<template v-slot:list>
<q-icon
name="mdi-format-list-bulleted"
class="q-px-sm q-py-xs rounded"
size="16px"
:style="{
color: $q.dark.isActive
? pageState.gridView === false
? '#C9D3DB'
: '#787B7C'
: pageState.gridView === false
? '#787B7C'
: '#C9D3DB',
}"
/>
</template>
</q-btn-toggle>
</div>
</div>
</header>
<!-- SEC: body content -->
<article
v-if="data.length === 0"
class="col surface-2 flex items-center justify-center"
>
<NoData :not-found="!!pageState.inputSearch" />
</article>
<article v-else class="col surface-2 full-width scroll q-pa-md">
<q-infinite-scroll
:offset="10"
@load="
(_, done) => {
if ($q.screen.gt.xs || page === pageMax) return;
page = page + 1;
fetchList().then(() => done(page >= pageMax));
}
"
>
<TableReceipt
:columns="columns"
:rows="data"
:grid="pageState.gridView"
@view="
(data) =>
triggerView({ quotationId: data.invoice.quotation.id })
"
@preview="(data) => viewDocExample(data.id)"
>
<template #grid="{ item }">
<div class="col-md-4 col-sm-6 col-12">
<QuotationCard
hide-action
:code="item.row.code"
:title="item.row.invoice.quotation.workName"
:status="$t(`invoice.status.${item.row.paymentStatus}`)"
:badge-color="hslaColors[item.row.paymentStatus] || ''"
:custom-data="[
{
label: $t('general.customer'),
value:
item.row.invoice.quotation.customerBranch.customer
.customerType === 'CORP'
? $i18n.locale === 'tha'
? item.row.invoice.quotation.customerBranch
.registerName
: item.row.invoice.quotation.customerBranch
.registerNameEN
: $i18n.locale === 'tha'
? `${item.row.invoice.quotation.customerBranch?.firstName || '-'} ${item.row.invoice.quotation.customerBranch?.lastName || ''}`
: `${item.row.invoice.quotation.customerBranch?.firstNameEN || '-'} ${item.row.invoice.quotation.customerBranch?.lastNameEN || ''}`,
},
{
label: $t('taskOrder.issueDate'),
value: new Date(
item.row.invoice.quotation.createdAt,
).toLocaleString('th-TH', {
hour12: false,
}),
},
{
label: $t('invoice.paymentDueDate'),
value: new Date(
item.row.invoice.quotation.dueDate,
).toLocaleDateString('th-TH', {
year: 'numeric',
month: '2-digit',
day: 'numeric',
}),
},
{
label: $t('quotation.payType'),
value: $t(
`quotation.type.${item.row.invoice.quotation.payCondition}`,
),
},
{
label: $t('preview.netValue'),
value: item.row.amount,
},
]"
@view="
() =>
triggerView({
quotationId: item.row.invoice.quotation.id,
})
"
@preview="
() => {
viewDocExample(item.row.invoice.quotation.id);
}
"
/>
</div>
</template>
</TableReceipt>
<template v-slot:loading>
<div
v-if="$q.screen.lt.sm && page !== pageMax"
class="row justify-center"
>
<q-spinner-dots color="primary" size="40px" />
</div>
</template>
</q-infinite-scroll>
</article>
<!-- SEC: footer content -->
<footer
class="row justify-between items-center q-px-md q-py-sm surface-2"
v-if="pageMax > 0 && $q.screen.gt.xs"
>
<div class="col-4">
<div class="row items-center no-wrap">
<div class="app-text-muted q-mr-sm" v-if="$q.screen.gt.sm">
{{ $t('general.recordPerPage') }}
</div>
<div><PaginationPageSize v-model="pageSize" /></div>
</div>
</div>
<div class="col-4 row justify-center app-text-muted">
{{
$q.screen.gt.sm
? $t('general.recordsPage', {
resultcurrentPage: data.length,
total: pageState.inputSearch
? data.length
: pageState.total,
})
: $t('general.ofPage', {
current: data.length,
total: pageState.inputSearch
? data.length
: pageState.total,
})
}}
</div>
<nav class="col-4 row justify-end">
<PaginationComponent
v-model:current-page="page"
v-model:max-page="pageMax"
:fetch-data="
() => {
fetchList({ rotateFlowId: true });
}
"
/>
</nav>
</footer>
</div>
</section>
</div>
</template>
<style scoped></style>