diff --git a/src/pages/04_product-service/MainPage.vue b/src/pages/04_product-service/MainPage.vue index cc0f99fa..15eec7ad 100644 --- a/src/pages/04_product-service/MainPage.vue +++ b/src/pages/04_product-service/MainPage.vue @@ -77,12 +77,12 @@ const dialogProduct = ref(false); const dialogService = ref(false); const statusToggle = ref(false); const profileSubmit = ref(false); -const profileFile = ref(undefined); +const imageProduct = ref(undefined); const profileUrl = ref(''); const groupName = ref('งาน MOU'); const dialogProductServiceType = ref(false); -const dialogTotalProduct = ref(true); +const dialogTotalProduct = ref(false); const productMode = ref<'group' | 'type' | 'service' | 'product'>('group'); const productGroup = ref(); @@ -109,6 +109,7 @@ const formDataProduct = ref({ detail: '', name: '', code: '', + image: undefined, }); const serviceTab = [ @@ -141,9 +142,9 @@ const inputFile = (() => { }); element.addEventListener('change', () => { - profileFile.value = element.files?.[0]; - if (profileFile.value) { - reader.readAsDataURL(profileFile.value); + imageProduct.value = element.files?.[0]; + if (imageProduct.value) { + reader.readAsDataURL(imageProduct.value); } }); @@ -307,6 +308,7 @@ function assignFormDataProduct(data: ProductList) { detail: data.detail, name: data.name, code: data.code, + image: undefined, }; } @@ -332,6 +334,7 @@ function clearFormProduct() { detail: '', name: '', code: '', + image: undefined, }; dialogProduct.value = false; @@ -339,6 +342,10 @@ function clearFormProduct() { async function submitProduct() { formDataProduct.value.productTypeId = currentIdType.value; + if (profileSubmit.value) { + formDataProduct.value.image = imageProduct.value; + } + await createProduct(formDataProduct.value); dialogProduct.value = false; @@ -693,7 +700,6 @@ watch(currentStatus, async () => { @on-click=" async () => { currentId = v.id; - console.log(v.id); productMode = 'type'; await fetchListType(); } @@ -861,6 +867,7 @@ watch(currentStatus, async () => { :code="i.code" :price="i.price" :process="i.process" + :id="i.id" @viewDetail="() => {}" /> diff --git a/src/stores/product-service/index.ts b/src/stores/product-service/index.ts index f8c5d9ae..f57181b6 100644 --- a/src/stores/product-service/index.ts +++ b/src/stores/product-service/index.ts @@ -1,6 +1,8 @@ import { defineStore } from 'pinia'; import { api } from 'src/boot/axios'; +import axios from 'axios'; + import { Pagination } from 'src/stores/types'; import { @@ -278,11 +280,21 @@ const useProductServiceStore = defineStore('api-product-service', () => { } async function createProduct(data: ProductCreate) { - const { ...payload } = data; + const { image, ...payload } = data; - const res = await api.post('/product', { - ...payload, - }); + const res = await api.post( + '/product', + { + ...payload, + }, + ); + image && + (await axios + .put(res.data.imageUploadUrl, image, { + headers: { 'Content-Type': image.type }, + onUploadProgress: (e) => console.log(e), + }) + .catch((e) => console.error(e))); if (!res) return false; diff --git a/src/stores/product-service/types.ts b/src/stores/product-service/types.ts index 543c8b08..f34f143e 100644 --- a/src/stores/product-service/types.ts +++ b/src/stores/product-service/types.ts @@ -109,6 +109,7 @@ export interface ProductCreate { detail: string; name: string; code: string; + image?: File; } export interface ProductUpdate { @@ -119,6 +120,7 @@ export interface ProductUpdate { process: string; detail: string; name: string; + image?: File; } //