Merge branch 'develop' into devTee

This commit is contained in:
setthawutttty 2024-03-19 18:02:33 +07:00
commit 3e60af46be

View file

@ -1,6 +1,7 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref, onMounted } from "vue"; import { ref, onMounted } from "vue";
import { useQuasar } from "quasar"; import { useQuasar } from "quasar";
import axios from "axios";
import http from "@/plugins/http"; import http from "@/plugins/http";
import config from "@/app.config"; import config from "@/app.config";
@ -12,7 +13,14 @@ import { useSalaryEmployeeListSDataStore } from "@/modules/13_salary/store/Salar
const $q = useQuasar(); // noti quasar const $q = useQuasar(); // noti quasar
const mixin = useCounterMixin(); const mixin = useCounterMixin();
const store = useSalaryEmployeeListSDataStore(); const store = useSalaryEmployeeListSDataStore();
const { messageError, dialogConfirm, showLoader, hideLoader, success } = mixin; const {
messageError,
dialogConfirm,
showLoader,
hideLoader,
success,
dialogRemove,
} = mixin;
const props = defineProps({ const props = defineProps({
rootId: String, rootId: String,
@ -21,23 +29,19 @@ const props = defineProps({
}); });
const sendStep = ref<number>(1); const sendStep = ref<number>(1);
const fileUpload = ref<any[]>([]); const fileUpload = ref<any>(null);
const document = ref<string>(""); const document = ref<string>("");
const type = ref<string>(""); const type = ref<string>("");
const listFile = ref<any>([]);
/** /**
* function ปโหลดไฟลเจาหนาท * function ปโหลดไฟลเจาหนาท
* @param event file * @param event file
*/ */
async function uploadFile(event: any) { async function uploadFile(event: any) {
console.log(event);
const fileName = event.map((e: any) => ({ fileName: e.name }));
dialogConfirm( dialogConfirm(
$q, $q,
async () => { async () => {
const selectedFile = event; showLoader();
const formdata = new FormData();
formdata.append("Document", selectedFile);
http http
.post( .post(
config.API.subFile( config.API.subFile(
@ -48,21 +52,25 @@ async function uploadFile(event: any) {
), ),
{ {
replace: false, // replace: false, //
fileList: fileName, fileList: [
{
fileName: event.name, //
},
],
} }
) )
.then(async () => { .then(async (res) => {
// await fecthInsigniaByOc( const foundKey: any = Object.keys(res.data).find(
// round.value, (key) =>
// DataStore.agency, res.data[key]?.fileName !== undefined &&
// "officer", res.data[key]?.fileName !== ""
// tab.value );
// ); const link = res.data[foundKey]?.uploadUrl;
// success($q, ""); fileUpLoad(link);
// fileUpload.value = null;
}) })
.catch((err) => { .catch((err) => {
messageError($q, err); messageError($q, err);
hideLoader();
}); });
}, },
"ยืนยันการอัปโหลดไฟล์", "ยืนยันการอัปโหลดไฟล์",
@ -70,6 +78,25 @@ async function uploadFile(event: any) {
); );
} }
function fileUpLoad(url: string) {
axios
.put(url, fileUpload.value, {
headers: { "Content-Type": fileUpload.value?.type },
onUploadProgress: (e) => console.log(e),
})
.then(() => {
success($q, "อัปโหลดไฟล์สำเร็จ");
fileUpload.value = null;
fetchListFile();
})
.catch((e) => {
messageError($q, e);
})
.finally(() => {
hideLoader();
});
}
function saveReccommend(reason: string) { function saveReccommend(reason: string) {
dialogConfirm( dialogConfirm(
$q, $q,
@ -152,11 +179,64 @@ function fetchListFile() {
props.rootId ? props.rootId : "" props.rootId ? props.rootId : ""
) )
) )
.then(async () => {}) .then(async (res) => {
listFile.value = res.data;
})
.catch((err) => { .catch((err) => {
messageError($q, err); messageError($q, err);
}); });
} }
function onDeleteFile(fileName: string) {
dialogRemove($q, () => {
showLoader();
http
.delete(
config.API.subFileByFileName(
"ระบบเงินเดือน",
"เลื่อนค่าจ้าง",
props.periodId ? props.periodId : "",
props.rootId ? props.rootId : "",
fileName
)
)
.then(() => {
success($q, "ลบไฟล์สำเร็จ");
setTimeout(() => {
fetchListFile();
hideLoader();
}, 1000);
})
.catch((e) => {
messageError($q, e);
})
.finally(async () => {});
});
}
function downloadFile(fileName: string) {
showLoader();
http
.get(
config.API.subFileByFileName(
"ระบบเงินเดือน",
"เลื่อนค่าจ้าง",
props.periodId ? props.periodId : "",
props.rootId ? props.rootId : "",
fileName
)
)
.then((res) => {
const data = res.data;
window.open(data.downloadUrl, "_blank");
})
.catch((e) => {
messageError($q, e);
})
.finally(async () => {
hideLoader();
});
}
onMounted(() => { onMounted(() => {
fetchListFile(); fetchListFile();
}); });
@ -166,14 +246,13 @@ onMounted(() => {
<div class="row col-12 q-pa-md"> <div class="row col-12 q-pa-md">
<q-toolbar style="padding: 0px"> <q-toolbar style="padding: 0px">
<q-file <q-file
v-if="sendStep == 1" v-if="store.statusQuota == 'PENDING'"
bg-color="white" bg-color="white"
clearable clearable
outlined outlined
dense dense
v-model="fileUpload" v-model="fileUpload"
label="อัปโหลดไฟล์" label="อัปโหลดไฟล์"
multiple
> >
<template v-slot:prepend> <template v-slot:prepend>
<q-icon color="light-blue" name="attach_file" /> <q-icon color="light-blue" name="attach_file" />
@ -188,19 +267,6 @@ onMounted(() => {
@click="uploadFile(fileUpload)" @click="uploadFile(fileUpload)"
v-if="fileUpload !== null" v-if="fileUpload !== null"
/> />
<div v-if="document">
<q-btn
dense
color="primary"
icon-right="mdi-download"
label="ดาวน์โหลดไฟล์"
outline
:href="document"
target="_blank"
>
<q-tooltip>ดาวนโหลด</q-tooltip></q-btn
>
</div>
<q-space /> <q-space />
<div> <div>
@ -267,41 +333,47 @@ onMounted(() => {
/> />
</div> </div>
</q-toolbar> </q-toolbar>
<div class="col-6">
<q-list bordered>
<q-item clickable v-ripple>
<q-item-section>Icon as avatar</q-item-section>
<q-item-section avatar>
<q-icon color="primary" name="bluetooth" />
</q-item-section>
</q-item>
<q-item clickable v-ripple> <div class="col-6" v-if="listFile.length !== 0">
<q-item-section>Avatar-type icon</q-item-section> <q-card bordered style="border: 1px solid #d6dee1">
<q-item-section avatar> <div class="text-weight-medium bg-grey-1 q-py-sm q-px-md">
<q-avatar color="teal" text-color="white" icon="bluetooth" /> ไฟลปโหล
</q-item-section> </div>
</q-item> <q-list bordered separator>
<q-item clickable v-ripple v-for="item in listFile">
<q-item clickable v-ripple> <q-item-section>{{ item.fileName }}</q-item-section>
<q-item-section>Rounded avatar-type icon</q-item-section> <q-item-section avatar>
<q-item-section avatar> <div class="row">
<q-avatar <div>
rounded <q-btn
color="purple" dense
text-color="white" flat
icon="bluetooth" round
/> size="12px"
</q-item-section> color="blue"
</q-item> icon="mdi-download-outline"
@click="downloadFile(item.fileName)"
<q-item clickable v-ripple> >
<q-item-section>Letter avatar-type</q-item-section> <q-tooltip>ดาวนโหลดเอกสาร</q-tooltip>
<q-item-section avatar> </q-btn>
<q-avatar color="primary" text-color="white"> R </q-avatar> </div>
</q-item-section> <div>
</q-item> <q-btn
</q-list> dense
flat
round
size="12px"
color="red"
icon="mdi-delete-outline"
@click="onDeleteFile(item.fileName)"
><q-tooltip>ลบเอกสาร</q-tooltip></q-btn
>
</div>
</div>
</q-item-section>
</q-item>
</q-list>
</q-card>
</div> </div>
</div> </div>