fix bug

parent eb5aea7c
...@@ -159,6 +159,8 @@ export type ProductType = { ...@@ -159,6 +159,8 @@ export type ProductType = {
name: string; name: string;
numIndex: number; numIndex: number;
status: number; status: number;
url?: string;
file?: File;
}; };
export type ArtistOwner = { export type ArtistOwner = {
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
<q-card flat style="max-height: 200px" v-if="urlFileLocal"> <q-card flat style="max-height: 200px" v-if="urlFileLocal">
<div align="center"> <div align="center">
<q-img <q-img
:src="urlFileLocal" :src="imageAPI ? imageAPI : urlFileLocal"
style="max-height: 200px; aspect-ratio: 16/9" style="max-height: 200px; aspect-ratio: 16/9"
> >
</q-img> </q-img>
......
...@@ -4,7 +4,7 @@ import { i18n } from 'src/boot/i18n'; ...@@ -4,7 +4,7 @@ import { i18n } from 'src/boot/i18n';
// import { isMobilePhone } from '../../../boot/functions'; // import { isMobilePhone } from '../../../boot/functions';
import UploadImage from '../../upload-image/index.vue'; import UploadImage from '../../upload-image/index.vue';
import { ProductType } from 'src/assets/type'; import { ProductType } from 'src/assets/type';
import { config } from 'src/assets/configurations';
export default defineComponent({ export default defineComponent({
components: { components: {
UploadImage, UploadImage,
...@@ -22,16 +22,20 @@ export default defineComponent({ ...@@ -22,16 +22,20 @@ export default defineComponent({
}, },
setup(props, context) { setup(props, context) {
const configImg = config;
const file: Ref<File | string> = ref(''); const file: Ref<File | string> = ref('');
const code: Ref<string> = ref(''); const code: Ref<string> = ref('');
const embeddedUrl: Ref<string> = ref(''); const embeddedUrl: Ref<string> = ref('');
const urlFileLocal: Ref<string> = ref(''); const urlFileLocal: Ref<string> = ref('');
const imageAPI: Ref<string | null> = ref(null);
const status: Ref<number> = ref(2); const status: Ref<number> = ref(2);
const id: Ref<number | null> = ref(null); const id: Ref<number | null> = ref(null);
const uploadAvatar = (value: FileList) => { const uploadAvatar = (value: FileList) => {
urlFileLocal.value = URL.createObjectURL(value[0]); urlFileLocal.value = URL.createObjectURL(value[0]);
file.value = value[0]; file.value = value[0];
imageAPI.value = null;
}; };
watch( watch(
() => props.openUpdateHotProduct, () => props.openUpdateHotProduct,
(value) => { (value) => {
...@@ -41,6 +45,10 @@ export default defineComponent({ ...@@ -41,6 +45,10 @@ export default defineComponent({
embeddedUrl.value = props.dataUpdate?.embeddedUrl as string; embeddedUrl.value = props.dataUpdate?.embeddedUrl as string;
status.value = props.dataUpdate?.status as number; status.value = props.dataUpdate?.status as number;
urlFileLocal.value = props.dataUpdate?.imageUrl as string; urlFileLocal.value = props.dataUpdate?.imageUrl as string;
imageAPI.value =
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
configImg.API_IMAGE_ENDPOINT + props.dataUpdate?.imageUrl;
} }
} }
); );
...@@ -59,7 +67,7 @@ export default defineComponent({ ...@@ -59,7 +67,7 @@ export default defineComponent({
status: status.value, status: status.value,
embeddedUrl: embeddedUrl.value, embeddedUrl: embeddedUrl.value,
imageUrl: urlFileLocal.value, imageUrl: urlFileLocal.value,
id:id.value id: id.value,
}); });
}; };
const product_code = [ const product_code = [
...@@ -89,6 +97,9 @@ export default defineComponent({ ...@@ -89,6 +97,9 @@ export default defineComponent({
product_code, product_code,
url_embed, url_embed,
id, id,
configImg,
imageAPI,
}; };
}, },
......
...@@ -3,6 +3,7 @@ import { defineComponent, onMounted, Ref, ref } from 'vue'; ...@@ -3,6 +3,7 @@ import { defineComponent, onMounted, Ref, ref } from 'vue';
import Pagination from 'components/pagination/index.vue'; import Pagination from 'components/pagination/index.vue';
import { ProductType } from 'src/assets/type'; import { ProductType } from 'src/assets/type';
import { HotProductStatus } from 'src/assets/enums'; import { HotProductStatus } from 'src/assets/enums';
import { config } from 'src/assets/configurations';
export default defineComponent({ export default defineComponent({
components: { components: {
Pagination, Pagination,
...@@ -12,6 +13,7 @@ export default defineComponent({ ...@@ -12,6 +13,7 @@ export default defineComponent({
// DataInsertHotProduct: { type: Object, requied: false } // DataInsertHotProduct: { type: Object, requied: false }
}, },
setup(_, context) { setup(_, context) {
const configImg = config;
const userTableColumnsHotProduct = [ const userTableColumnsHotProduct = [
{ {
name: 'STT', name: 'STT',
...@@ -70,29 +72,6 @@ export default defineComponent({ ...@@ -70,29 +72,6 @@ export default defineComponent({
const pageIndex = ref(1); const pageIndex = ref(1);
const pageSize = ref(20); const pageSize = ref(20);
const totalPage = ref(10); const totalPage = ref(10);
const getListHotProduct = () => {
// const response = (await api({
// url: API_PATHS.getListArtist,
// method: 'GET',
// params: {
// pageIndex: pageIndex.value,
// pageSize: pageSize.value,
// },
// })) as AxiosResponse<BaseResponseBody<unknown>>;
const fakeData: unknown[] = [
{
productCode: 91239381,
urlEmbed: 'urlEmbel',
productImage: 'Image',
status: true,
},
];
userTableRowsHotProduct.value = fakeData;
};
const changePageSize = () => {
pageIndex.value = 1;
void getListHotProduct();
};
const updateProduct = (item: { row: ProductType }) => { const updateProduct = (item: { row: ProductType }) => {
context.emit('setDataUpdate', { context.emit('setDataUpdate', {
code: item.row.code, code: item.row.code,
...@@ -112,18 +91,14 @@ export default defineComponent({ ...@@ -112,18 +91,14 @@ export default defineComponent({
context.emit('deleteRow', index); context.emit('deleteRow', index);
}; };
onMounted(() => {
void getListHotProduct();
});
return { return {
configImg,
userTableColumnsHotProduct, userTableColumnsHotProduct,
userTableRowsHotProduct, userTableRowsHotProduct,
pageIndex, pageIndex,
pageSize, pageSize,
totalPage, totalPage,
deleteRow, deleteRow,
getListHotProduct,
changePageSize,
clickAdd, clickAdd,
updateProduct, updateProduct,
HotProductStatus, HotProductStatus,
......
...@@ -44,17 +44,6 @@ ...@@ -44,17 +44,6 @@
</div> </div>
</q-td> </q-td>
</template> </template>
<!-- <template v-slot:body-cell-status="rowData">
<q-td>
<div align="center">
<q-checkbox
:true-value="1"
:false-value="2"
v-model="rowData.value"
/>
</div>
</q-td>
</template> -->
<template v-slot:body-cell-STT="item"> <template v-slot:body-cell-STT="item">
<q-td style="padding: 0; height: 100%"> <q-td style="padding: 0; height: 100%">
<div align="center"> <div align="center">
...@@ -90,7 +79,14 @@ ...@@ -90,7 +79,14 @@
<template v-slot:body-cell-imageUrl="rowData"> <template v-slot:body-cell-imageUrl="rowData">
<q-td style="padding: 0; height: 100%"> <q-td style="padding: 0; height: 100%">
<div align="center"> <div align="center">
<q-img :src="rowData.value" style="max-width: 70px"> </q-img> <q-img
:src="
rowData.row.file === undefined
? configImg.API_IMAGE_ENDPOINT + rowData.value
: rowData.value
"
style="max-width: 70px"
></q-img>
</div> </div>
</q-td> </q-td>
</template> </template>
......
...@@ -602,6 +602,23 @@ export default defineComponent({ ...@@ -602,6 +602,23 @@ export default defineComponent({
} }
} catch (error) {} } catch (error) {}
}; };
const callAPIUploadHotProduct = async (file: File, idx: number) => {
try {
const bodyFormData = new FormData();
bodyFormData.append('file', file);
const response = (await api({
headers: { 'Content-Type': 'multipart/form-data' },
url: config.API_IMAGE_ENDPOINT,
method: 'POST',
data: bodyFormData,
})) as AxiosResponse<BaseResponseBody<FileUploadType>>;
if (response.data.error.code === config.API_RES_CODE.OK.code) {
const urlHotProductUpload = response.data.data.fileName;
products.value[idx].imageUrl = urlHotProductUpload;
}
} catch (error) {}
};
const checkValidate = () => { const checkValidate = () => {
let hasError = false; let hasError = false;
if (!artistCode.value || !artistCode.value?.trim().length) { if (!artistCode.value || !artistCode.value?.trim().length) {
...@@ -705,6 +722,12 @@ export default defineComponent({ ...@@ -705,6 +722,12 @@ export default defineComponent({
await callApiUploadStories(item.file, idx); await callApiUploadStories(item.file, idx);
} }
} }
for (let idx = 0; idx < products.value.length; idx++) {
const item = products.value[idx];
if (item.file !== undefined) {
await callAPIUploadHotProduct(item.file, idx);
}
}
const response = (await api({ const response = (await api({
url: API_PATHS.updateArtist, url: API_PATHS.updateArtist,
......
...@@ -116,7 +116,7 @@ export default defineComponent({ ...@@ -116,7 +116,7 @@ export default defineComponent({
const pageIndex = ref(1); const pageIndex = ref(1);
const pageSize = ref(20); const pageSize = ref(20);
const totalPage = ref(10); const totalPage = ref(10);
const fullNameKeyword = ref(''); const fullNameKeyword: Ref<string | null> = ref(null);
const sexOptions = ref([ const sexOptions = ref([
{ id: 1, name: 'Nam' }, { id: 1, name: 'Nam' },
{ id: 2, name: 'Nữ' }, { id: 2, name: 'Nữ' },
...@@ -170,7 +170,8 @@ export default defineComponent({ ...@@ -170,7 +170,8 @@ export default defineComponent({
if (response.data.error.code === config.API_RES_CODE.OK.code) { if (response.data.error.code === config.API_RES_CODE.OK.code) {
userTableRowsArtist.value = response.data.data.data; userTableRowsArtist.value = response.data.data.data;
totalPage.value = response.data.data.totalPages; totalPage.value = response.data.data.totalPages;
console.log(response.data.data); // pageSize.value = response.data.data.pageSize as number;
// pageIndex.value = response.data.data.pageIndex as number;
} }
} catch (error) {} } catch (error) {}
}; };
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
dense dense
outlined outlined
:label="$t('artist.tableColumnsArtist.artistName')" :label="$t('artist.tableColumnsArtist.artistName')"
clearable
></q-input> ></q-input>
</div> </div>
<div class="col-2" dense outlined> <div class="col-2" dense outlined>
...@@ -18,6 +19,7 @@ ...@@ -18,6 +19,7 @@
label="Lĩnh vực" label="Lĩnh vực"
dense dense
outlined outlined
clearable
></q-select> ></q-select>
</div> </div>
...@@ -30,6 +32,7 @@ ...@@ -30,6 +32,7 @@
dense dense
outlined outlined
label="Độ chuyên" label="Độ chuyên"
clearable
></q-select> ></q-select>
</div> </div>
<div class="col-2" dense outlined> <div class="col-2" dense outlined>
...@@ -41,6 +44,7 @@ ...@@ -41,6 +44,7 @@
dense dense
outlined outlined
label="Xếp hạng" label="Xếp hạng"
clearable
></q-select> ></q-select>
</div> </div>
<div class="col-auto"> <div class="col-auto">
......
...@@ -545,6 +545,23 @@ export default defineComponent({ ...@@ -545,6 +545,23 @@ export default defineComponent({
} }
} catch (error) {} } catch (error) {}
}; };
const callAPIUploadHotProduct = async (file: File, idx: number) => {
try {
const bodyFormData = new FormData();
bodyFormData.append('file', file);
const response = (await api({
headers: { 'Content-Type': 'multipart/form-data' },
url: config.API_IMAGE_ENDPOINT,
method: 'POST',
data: bodyFormData,
})) as AxiosResponse<BaseResponseBody<FileUploadType>>;
if (response.data.error.code === config.API_RES_CODE.OK.code) {
const urlHotProductUpload = response.data.data.fileName;
products.value[idx].imageUrl = urlHotProductUpload;
}
} catch (error) {}
};
const checkValidate = () => { const checkValidate = () => {
let hasError = false; let hasError = false;
if (!artistCode.value || !artistCode.value?.trim().length) { if (!artistCode.value || !artistCode.value?.trim().length) {
...@@ -642,6 +659,12 @@ export default defineComponent({ ...@@ -642,6 +659,12 @@ export default defineComponent({
await callApiUploadStories(item.file, idx); await callApiUploadStories(item.file, idx);
} }
} }
for (let idx = 0; idx < products.value.length; idx++) {
const item = products.value[idx];
if (item.file !== undefined) {
await callAPIUploadHotProduct(item.file, idx);
}
}
const response = (await api({ const response = (await api({
url: API_PATHS.addArtist, url: API_PATHS.addArtist,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment