refactor: export product
Some checks failed
Spell Check / Spell Check with Typos (push) Failing after 6s

This commit is contained in:
Thanaphon Saengchan 2025-09-18 13:21:11 +07:00
parent d53eb15a88
commit d2acd6ba4c
3 changed files with 82 additions and 3 deletions

View file

@ -10,6 +10,7 @@ defineProps<{
outlined?: boolean; outlined?: boolean;
disabled?: boolean; disabled?: boolean;
dark?: boolean; dark?: boolean;
color?: string;
label?: string; label?: string;
icon?: string; icon?: string;
@ -23,7 +24,7 @@ defineProps<{
@click="(e) => $emit('click', e)" @click="(e) => $emit('click', e)"
v-bind="{ ...$props, ...$attrs }" v-bind="{ ...$props, ...$attrs }"
:icon="icon || 'mdi-content-save-outline'" :icon="icon || 'mdi-content-save-outline'"
color="207 96% 32%" :color="color || '207 96% 32%'"
:title="iconOnly ? $t('general.save') : undefined" :title="iconOnly ? $t('general.save') : undefined"
> >
{{ label || $t('general.save') }} {{ label || $t('general.save') }}

View file

@ -102,6 +102,8 @@ const {
deleteWork, deleteWork,
importProduct, importProduct,
productExport,
} = productServiceStore; } = productServiceStore;
const { workNameItems } = storeToRefs(productServiceStore); const { workNameItems } = storeToRefs(productServiceStore);
@ -1896,6 +1898,25 @@ async function submitWorkName(
else await editWork(workId, data); else await editWork(workId, data);
} }
async function triggerExport() {
productExport({
pageSize: 100_000,
productGroupId: currentIdGroup.value,
query: !!inputSearchProductAndService.value
? inputSearchProductAndService.value
: undefined,
status:
currentStatus.value === 'INACTIVE'
? 'INACTIVE'
: currentStatus.value === 'ACTIVE'
? 'ACTIVE'
: undefined,
startDate: new Date(searchDate.value[0]),
endDate: new Date(searchDate.value[1]),
});
}
watch( watch(
() => formService.value.attributes.workflowId, () => formService.value.attributes.workflowId,
async (a, b) => { async (a, b) => {
@ -2229,7 +2250,6 @@ watch(
</AdvanceSearch> </AdvanceSearch>
</template> </template>
</q-input> </q-input>
<div class="row col-md-6" style="white-space: nowrap"> <div class="row col-md-6" style="white-space: nowrap">
<q-select <q-select
v-show="$q.screen.gt.sm" v-show="$q.screen.gt.sm"
@ -2780,6 +2800,13 @@ watch(
} }
" "
/> />
<SaveButton
icon-only
:icon="'material-symbols:download'"
color="var(--info-bg)"
@click.stop="triggerExport()"
/>
</div> </div>
<div class="row col-md-6" style="white-space: nowrap"> <div class="row col-md-6" style="white-space: nowrap">
@ -3632,7 +3659,7 @@ watch(
:delete-data="() => deleteGroupById()" :delete-data="() => deleteGroupById()"
:close=" :close="
() => { () => {
(drawerInfo = false), (currentIdGroupType = ''); ((drawerInfo = false), (currentIdGroupType = ''));
} }
" "
hide-action hide-action

View file

@ -2,6 +2,7 @@ import { defineStore } from 'pinia';
import { api } from 'src/boot/axios'; import { api } from 'src/boot/axios';
import { Pagination } from 'stores/types'; import { Pagination } from 'stores/types';
import { getToken } from 'src/services/keycloak';
import { import {
ProductGroup, ProductGroup,
@ -19,6 +20,7 @@ import {
import { ref } from 'vue'; import { ref } from 'vue';
const useProductServiceStore = defineStore('api-product-service', () => { const useProductServiceStore = defineStore('api-product-service', () => {
const baseUrl = import.meta.env.VITE_API_BASE_URL;
const splitPay = ref<number>(0); const splitPay = ref<number>(0);
const workNameItems = ref< const workNameItems = ref<
{ {
@ -528,6 +530,53 @@ const useProductServiceStore = defineStore('api-product-service', () => {
if (!res) return false; if (!res) return false;
} }
async function productExport(params: {
status?: 'CREATED' | 'ACTIVE' | 'INACTIVE';
shared?: boolean;
productGroupId?: string;
query?: string;
page?: number;
pageSize?: number;
orderField?: string;
orderBy?: string;
activeOnly?: boolean;
startDate?: Date;
endDate?: Date;
}) {
let url = baseUrl + '/' + 'product-export';
const queryParams = new URLSearchParams(
Object.keys(params).reduce((acc: Record<string, string>, key) => {
const value = params[key as keyof typeof params];
if (value !== undefined && value !== null && value !== '') {
const stringValue =
typeof value === 'boolean' || typeof value === 'number'
? String(value)
: value instanceof Date
? value.toISOString()
: String(value);
acc[key] = stringValue;
}
return acc;
}, {}),
);
url += '?' + queryParams.toString();
const res = await fetch(url, {
headers: { ['Authorization']: 'Bearer ' + (await getToken()) },
});
const text = await res.json();
const blob = new Blob([text], { type: 'text/csv' });
if (res.ok && blob) {
const a = document.createElement('a');
a.download = 'customer-report' + '.csv';
a.href = window.URL.createObjectURL(blob);
a.click();
a.remove();
}
}
return { return {
workNameItems, workNameItems,
splitPay, splitPay,
@ -568,6 +617,8 @@ const useProductServiceStore = defineStore('api-product-service', () => {
deleteImageByName, deleteImageByName,
importProduct, importProduct,
productExport,
}; };
}); });