diff --git a/src/pages/04_product-service/MainPage.vue b/src/pages/04_product-service/MainPage.vue index 1becab05..8dfd34dd 100644 --- a/src/pages/04_product-service/MainPage.vue +++ b/src/pages/04_product-service/MainPage.vue @@ -1,24 +1,32 @@ - - - - - - {{ groupName }} - - / - - {{ $t('ProductAndServiceType') }} - - - - - - {{ groupName }} - - / - - {{ 'บริการพิสูจน์สัญชาติ' }} - - / - - {{ $t('mainProductTitle') }} - + + + {{ $t('productAndService') }} - + + + + + (dialogInputForm = true)" + /> + + - - - - {{ $t('ProductAndServiceType') }} + + + + + + + {{ groupName }} - - {{ $t('ProductAndServiceAll') }} + / + + {{ $t('productAndServiceType') }} + + + + + {{ groupName }} + + / + + {{ 'บริการพิสูจน์สัญชาติ' }} + + / + + {{ $t('mainProductTitle') }} + + + + + + + + + + {{ $t('productAndServiceType') }} + + + {{ $t('productAndServiceAll') }} + + + + + + + + + + + + {{ $t('all') }} + + + {{ $t('statusACTIVE') }} + + + {{ $t('statusINACTIVE') }} + + + + + + + + + { + clearForm(); + currentIdType = v.id; + assignFormData(v); + isEdit = false; + drawerInfo = true; + } + " + @on-click=" + () => { + currentIdType = v.id; + productMode = 'service'; + } + " + /> + { + clearForm(); + assignFormData(v); + isEdit = false; + currentId = v.id; + + drawerInfo = true; + } + " + @on-click=" + async () => { + currentId = v.id; + console.log(v.id); + productMode = 'type'; + await fetchListType(); + } + " + /> + + + { + clearForm(); + dialogInputForm = true; + } + " + /> + { + clearForm(); + dialogInputForm = true; + } + " + /> + + + + { - - - - {{ $t('all') }} - - - {{ $t('statusACTIVE') }} - - - {{ $t('statusINACTIVE') }} - - - - - - - - - { - currentId = v.id; - drawerInfo = true; - } - " - @on-click=" - () => { - currentId = v.id; - productMode = 'service'; - } - " + @click="dialogProductServiceType = true" /> - { - assignFormData(v); - currentId = v.id; - drawerInfo = true; - } - " - @on-click=" - () => { - currentId = v.id; - productMode = 'type'; - } - " + ปุ่มรวมสินค้าทั้งหมด >> + - - (dialogInputForm = true)" - /> - (dialogInputForm = true)" - /> + + asdasdasd - - - - - - - - - - - ปุ่มรวมสินค้าทั้งหมด >> - - - - asdasdasd - - + + diff --git a/src/stores/product-service/index.ts b/src/stores/product-service/index.ts index 3fbe29bf..3c7f45bb 100644 --- a/src/stores/product-service/index.ts +++ b/src/stores/product-service/index.ts @@ -1,8 +1,119 @@ import { defineStore } from 'pinia'; import { api } from 'src/boot/axios'; -import { ProductGroup, ProductGroupCreate, ProductGroupUpdate } from './types'; +import { Product, ProductCreate, ProductUpdate } from './types'; const useProductServiceStore = defineStore('api-product-service', () => { + async function fetchStatsProductType() { + const res = await api.get('/product-type/stats'); + + if (!res) return false; + + if (res.status === 200) { + return res.data; + } + } + + async function fetchListProductServiceByIdType(groupId: string) { + const res = await api.get( + `/product-type/${groupId}`, + ); + + if (!res) return false; + + if (res.status === 200) { + return res.data; + } + } + + async function fetchListProductServiceType( + opts?: { query?: string; productGroupId?: string }, + flow?: { + sessionId: string; + refTransactionId: string; + transactionId: string; + }, + ) { + const params = new URLSearchParams(); + + for (const [k, v] of Object.entries(opts || {})) { + v !== undefined && params.append(k, v.toString()); + } + + const query = params.toString(); + + const res = await api.get<(Product & { productGroupId: string })[]>( + `/product-type${(params && '?'.concat(query)) || ''}`, + { + headers: { + 'X-Session-Id': flow?.sessionId, + 'X-Rtid': flow?.refTransactionId, + 'X-Tid': flow?.transactionId, + }, + }, + ); + + if (!res) return false; + if (res.status === 200) { + return res.data; + } + + return false; + } + + async function createProductServiceType(id: string, data: ProductCreate) { + const { code, ...payload } = data; + + const res = await api.post( + '/product-type', + { + productGroupId: id, + ...payload, + }, + ); + + if (!res) return false; + + if (res.status === 200) { + return res.data; + } + + return false; + } + + async function editProductServiceType( + groupId: string, + data: ProductUpdate & { productGroupId: string }, + ) { + const { code, ...payload } = data; + + const res = await api.put( + `/product-type/${groupId}`, + { + ...payload, + }, + ); + + if (!res) return false; + + if (res.status === 200) { + return res.data; + } + + return false; + } + + async function deleteProductServiceType(groupId: string) { + const res = await api.delete(`/product-type/${groupId}`); + + if (!res) return false; + + if (res.status === 200) { + return res.data; + } + + return false; + } + async function fetchStatsProductGroup() { const res = await api.get('/product-group/stats'); @@ -14,7 +125,7 @@ const useProductServiceStore = defineStore('api-product-service', () => { } async function fetchListProductServiceById(groupId: string) { - const res = await api.get(`/product-group/${groupId}`); + const res = await api.get(`/product-group/${groupId}`); if (!res) return false; @@ -39,7 +150,7 @@ const useProductServiceStore = defineStore('api-product-service', () => { const query = params.toString(); - const res = await api.get( + const res = await api.get( `/product-group${(params && '?'.concat(query)) || ''}`, { headers: { @@ -58,26 +169,26 @@ const useProductServiceStore = defineStore('api-product-service', () => { return false; } - async function createProductService(data: ProductGroupCreate) { + async function createProductService(data: ProductCreate) { const { code, ...payload } = data; - const res = await api.post('/product-group', { + const res = await api.post('/product-group', { ...payload, }); if (!res) return false; - if (res.status === 200) { + if (res.status === 201) { return res.data; } return false; } - async function editProductService(groupId: string, data: ProductGroupUpdate) { + async function editProductService(groupId: string, data: ProductUpdate) { const { code, ...payload } = data; - const res = await api.put(`/product-group/${groupId}`, { + const res = await api.put(`/product-group/${groupId}`, { ...payload, }); @@ -103,6 +214,13 @@ const useProductServiceStore = defineStore('api-product-service', () => { } return { + fetchStatsProductType, + fetchListProductServiceByIdType, + fetchListProductServiceType, + createProductServiceType, + editProductServiceType, + deleteProductServiceType, + fetchStatsProductGroup, fetchListProductServiceById, fetchListProductService, diff --git a/src/stores/product-service/types.ts b/src/stores/product-service/types.ts index 3dc25e2e..fa3ec81f 100644 --- a/src/stores/product-service/types.ts +++ b/src/stores/product-service/types.ts @@ -1,6 +1,6 @@ import { Status } from '../types'; -export type ProductGroup = { +export type Product = { id: string; code: string; name: string; @@ -13,14 +13,14 @@ export type ProductGroup = { updatedAt: string; }; -export interface ProductGroupCreate { +export interface ProductCreate { remark: string; detail: string; name: string; code: string; } -export interface ProductGroupUpdate { +export interface ProductUpdate { remark: string; detail: string; name: string;