fix file ทะเบียรประวัติช่วยราชการ
This commit is contained in:
parent
a9651ef0f5
commit
94f51b0eb6
3 changed files with 78 additions and 21 deletions
|
|
@ -11,7 +11,10 @@ import config from "@/app.config";
|
|||
|
||||
import type { QTableProps } from "quasar";
|
||||
import type { DatAssistance } from "@/modules/04_registryPerson/interface/request/Government";
|
||||
import type { ResAssistanceData } from "@/modules/04_registryPerson/interface/response/Government";
|
||||
import type {
|
||||
ResAssistanceData,
|
||||
ResFileData,
|
||||
} from "@/modules/04_registryPerson/interface/response/Government";
|
||||
|
||||
import DialogHeader from "@/components/DialogHeader.vue";
|
||||
import DialogHistory from "@/modules/04_registryPerson/components/detail/GovernmentInformation/06_HelpGovernmentHistory.vue";
|
||||
|
|
@ -104,6 +107,8 @@ const visibleColumns = ref<String[]>([
|
|||
|
||||
/** Dialog*/
|
||||
const isStatusEdit = ref<boolean>(false);
|
||||
const isUpload = ref<boolean>(false);
|
||||
|
||||
const rowId = ref<string>("");
|
||||
const modal = ref<boolean>(false);
|
||||
const modalHistory = ref<boolean>(false);
|
||||
|
|
@ -114,9 +119,10 @@ const formData = reactive<DatAssistance>({
|
|||
dateEnd: null,
|
||||
commandNo: "",
|
||||
document: "",
|
||||
isUpload: false,
|
||||
// isUpload: false,
|
||||
});
|
||||
const fileUpload = ref<File>();
|
||||
const fileData = ref<ResFileData>();
|
||||
|
||||
/** ฟังก์ค้นหาข้อมูลรายการ */
|
||||
function serchDataTable() {
|
||||
|
|
@ -149,15 +155,16 @@ function onSubmit() {
|
|||
const body = {
|
||||
...formData,
|
||||
profileId: isStatusEdit.value ? undefined : profileId.value,
|
||||
isUpload: isStatusEdit.value
|
||||
? formData.isUpload
|
||||
? formData.isUpload
|
||||
: fileUpload.value
|
||||
? true
|
||||
: false
|
||||
: fileUpload.value
|
||||
? true
|
||||
: false,
|
||||
isUpload: !isStatusEdit.value ? undefined : isUpload.value,
|
||||
// isUpload: isStatusEdit.value
|
||||
// ? formData.isUpload
|
||||
// ? formData.isUpload
|
||||
// : fileUpload.value
|
||||
// ? true
|
||||
// : false
|
||||
// : fileUpload.value
|
||||
// ? true
|
||||
// : false,
|
||||
};
|
||||
const method = isStatusEdit.value ? "patch" : "post";
|
||||
await http[method](
|
||||
|
|
@ -209,7 +216,7 @@ async function uploadProfile(id: string) {
|
|||
)
|
||||
.then(async (res) => {
|
||||
const uploadUrl = res.data["เอกสารหลักฐาน"].uploadUrl;
|
||||
await uploadFileURL(uploadUrl, fileUpload.value);
|
||||
await uploadFileURL(uploadUrl, fileUpload.value, id);
|
||||
})
|
||||
.catch((err) => {
|
||||
messageError($q, err);
|
||||
|
|
@ -221,16 +228,27 @@ async function uploadProfile(id: string) {
|
|||
* @param uploadUrl Path อัปโหลดไฟล์
|
||||
* @param file ไฟล์เอกสาร
|
||||
*/
|
||||
async function uploadFileURL(uploadUrl: string, file: any) {
|
||||
async function uploadFileURL(uploadUrl: string, file: any, id: string) {
|
||||
await axios
|
||||
.put(uploadUrl, file, {
|
||||
headers: {
|
||||
"Content-Type": file.type,
|
||||
},
|
||||
})
|
||||
.then(() => {
|
||||
.then(async () => {
|
||||
await updateIsUpload(id, true);
|
||||
fileUpload.value = undefined;
|
||||
})
|
||||
.catch(async (err) => {
|
||||
await updateIsUpload(id, false);
|
||||
messageError($q, err);
|
||||
});
|
||||
}
|
||||
|
||||
async function updateIsUpload(id: string, val: boolean) {
|
||||
await http
|
||||
.patch(config.API.profileAssistance(empType.value, id), { isUpload: val })
|
||||
.then(async (res) => {})
|
||||
.catch((err) => {
|
||||
messageError($q, err);
|
||||
});
|
||||
|
|
@ -240,7 +258,7 @@ async function uploadFileURL(uploadUrl: string, file: any) {
|
|||
* ฟังก์ชันโหลไฟลเอกสารหลักฐาน
|
||||
* @param id รายการที่ต้องการโหลด
|
||||
*/
|
||||
async function onDownloadFile(id: string) {
|
||||
async function onDownloadFile(id: string, isLoad: boolean = true) {
|
||||
showLoader();
|
||||
await http
|
||||
.get(
|
||||
|
|
@ -253,8 +271,11 @@ async function onDownloadFile(id: string) {
|
|||
)
|
||||
)
|
||||
.then(async (res) => {
|
||||
const data = res.data.downloadUrl;
|
||||
window.open(data, "_blank");
|
||||
const data = res.data;
|
||||
fileData.value = data;
|
||||
if (isLoad) {
|
||||
window.open(data.downloadUrl, "_blank");
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
messageError($q, err);
|
||||
|
|
@ -273,7 +294,10 @@ function openEditDialog(data: ResAssistanceData) {
|
|||
formData.dateEnd = data.dateEnd;
|
||||
formData.commandNo = data.commandNo;
|
||||
formData.document = data.document;
|
||||
formData.isUpload = data.isUpload;
|
||||
isUpload.value = data.isUpload;
|
||||
if (isUpload.value) {
|
||||
onDownloadFile(data.id, false);
|
||||
}
|
||||
}
|
||||
|
||||
function showHistoryDialog(id: string) {
|
||||
|
|
@ -290,7 +314,7 @@ function closeDialogForm() {
|
|||
formData.dateEnd = null;
|
||||
formData.commandNo = "";
|
||||
formData.document = "";
|
||||
formData.isUpload = false;
|
||||
isUpload.value = false;
|
||||
fileUpload.value = undefined;
|
||||
}
|
||||
|
||||
|
|
@ -643,6 +667,7 @@ onMounted(() => {
|
|||
</div>
|
||||
<div class="col-xs-12 col-sm-12 col-md-12">
|
||||
<q-uploader
|
||||
v-if="!isUpload"
|
||||
color="gray"
|
||||
type="file"
|
||||
flat
|
||||
|
|
@ -715,6 +740,31 @@ onMounted(() => {
|
|||
</div>
|
||||
</template>
|
||||
</q-uploader>
|
||||
|
||||
<q-list bordered dense separator v-else>
|
||||
<q-item>
|
||||
<q-item-section> {{ fileData?.fileName }}</q-item-section>
|
||||
<q-item-section avatar>
|
||||
<div class="row">
|
||||
<q-btn
|
||||
flat
|
||||
round
|
||||
color="primary"
|
||||
icon="mdi-download"
|
||||
@click="onDownloadFile(rowId)"
|
||||
/>
|
||||
|
||||
<q-btn
|
||||
flat
|
||||
round
|
||||
color="grey"
|
||||
icon="close"
|
||||
@click="isUpload = false"
|
||||
/>
|
||||
</div>
|
||||
</q-item-section>
|
||||
</q-item>
|
||||
</q-list>
|
||||
</div>
|
||||
</div>
|
||||
</q-card-section>
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ interface DatAssistance {
|
|||
agency: string;
|
||||
commandNo: string;
|
||||
document: string;
|
||||
isUpload: boolean;
|
||||
// isUpload: boolean;
|
||||
}
|
||||
|
||||
export type { DataActing, DatAssistance };
|
||||
|
|
|
|||
|
|
@ -33,4 +33,11 @@ interface ResAssistanceData {
|
|||
profileId: string;
|
||||
}
|
||||
|
||||
export type { ResActingPosData, ResAssistanceData };
|
||||
interface ResFileData {
|
||||
downloadUrl: string;
|
||||
fileName: string;
|
||||
path: string;
|
||||
pathname: string;
|
||||
}
|
||||
|
||||
export type { ResActingPosData, ResAssistanceData, ResFileData };
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue