refactor: fetchby id branch

This commit is contained in:
Thanaphon Frappet 2024-10-18 12:01:07 +07:00
parent 3d08ace2ee
commit 3952af95dc

View file

@ -9,6 +9,8 @@ import useOptionStore from 'stores/options';
import { formatNumberDecimal } from 'stores/utils';
import { useQuotationForm } from 'pages/05_quotation/form';
import { useConfigStore } from 'stores/config';
import useBranchStore from 'stores/branch';
import { baseUrl } from 'stores/utils';
import { commaInput } from 'stores/utils';
// NOTE Import Types
@ -24,6 +26,7 @@ import PrintButton from 'src/components/button/PrintButton.vue';
const quotationForm = useQuotationForm();
const optionStore = useOptionStore();
const configStore = useConfigStore();
const branchStore = useBranchStore();
const { data: config } = storeToRefs(configStore);
@ -48,6 +51,7 @@ type SummaryPrice = {
const note = ref<string>('');
const productList = ref<Product[]>([]);
const bankList = ref<BankBook[]>([]);
const elements = ref<HTMLElement[]>([]);
const chunks = ref<Product[][]>([[]]);
@ -61,21 +65,6 @@ const summaryPrice = ref<SummaryPrice>({
finalPrice: 0,
});
const bankList = ref<BankBook[]>([
{
id: 'cm14grwo30003z8chvzouoc87',
currentlyUse: true,
branchId: 'cm14grwo30002z8ch55keto89',
bankUrl:
'http://192.168.1.61:20102/api/v1/branch/cm14grwo30002z8ch55keto89/bank-qr/cm14grwo30003z8chvzouoc87?ts=1729148488206',
bankName: 'ktb',
bankBranch: 'โรงพยาบาลศิริราชปิยมหาราชการุณย์',
accountType: '',
accountNumber: '1-520-361442-23',
accountName: 'บริษัท สยามเทคโนโลยี จำกัด',
},
]);
async function assignData() {
for (let i = 0; i < productList.value.length; i++) {
let el = elements.value.at(-1);
@ -128,7 +117,16 @@ onMounted(async () => {
data.value = JSON.parse(sessionStorage.getItem('quotation-preview') || '{}');
if (data) {
if (data.value) {
const res = await branchStore.fetchById(data.value?.registeredBranchId);
if (res) {
bankList.value = res.bank.map((v) => ({
...v,
bankUrl: `${baseUrl}/branch/${res.id}/bank-qr/${v.id}?ts=${Date.now()}`,
}));
}
productList.value =
data.value?.productServiceList.map((v) => ({
id: v.product.id,