refactor code ลาออก ขอโอน

This commit is contained in:
AnandaTon 2023-09-21 14:53:14 +07:00
parent 4e7432bc50
commit bf5b67ee36
5 changed files with 318 additions and 339 deletions

View file

@ -1,3 +1,116 @@
<script setup lang="ts">
import { ref, onMounted } from "vue"
import { useQuasar } from "quasar"
import { useRouter, useRoute } from "vue-router"
import { useCounterMixin } from "@/stores/mixin"
import http from "@/plugins/http"
import config from "@/app.config"
import type { QForm } from "quasar"
const router = useRouter()
const $q = useQuasar()
const mixin = useCounterMixin()
const myform = ref<QForm | null>(null)
const { fails, success, messageError, showLoader, hideLoader } = mixin
const fileDocDataUpload = ref<File[]>([])
const route = useRoute()
const files = ref<any>()
const tranferOrg = ref("")
const noteReason = ref("")
const id = ref<string>("")
const nameFile = ref<string>("")
const routeName = router.currentRoute.value.name
onMounted(() => {
if (route.params.id !== undefined) {
id.value = route.params.id.toString()
fecthDataTransfer(id.value)
}
})
const filesNull = () => {
files.value = null
}
const saveData = async () => {
if (myform.value != null) {
await myform.value.validate().then(async (saveDataTest: Boolean) => {
if (saveDataTest) {
saveTransfer()
}
})
}
}
//
const saveTransfer = () => {
$q.dialog({
title: "ยืนยันการยื่นข้อมูลการโอน",
message: "ต้องการยื่นข้อมูลการโอนนี้ใช่หรือไม่?",
cancel: {
flat: true,
color: "negative",
},
persistent: true,
})
.onOk(async () => {
if (files.value == undefined) {
fails($q, "กรุณากรอกอัพโหลดเอกสารเพิ่มเติม")
} else {
createTransfer()
}
})
.onCancel(() => {})
.onDismiss(() => {})
}
const createTransfer = async () => {
const formData = new FormData()
const blob = files.value.slice(0, files.value[0].size)
const newFile = new File(blob, nameFile.value, {
type: files.value[0].type,
})
formData.append("Organization", tranferOrg.value)
formData.append("Reason", noteReason.value)
formData.append("file", newFile)
await http
.post(config.API.listtransfer(), formData)
.then((res: any) => {
success($q, "บันทึกข้อมูลสำเร็จ")
router.push(`/transfer`)
})
.catch((e: any) => {
messageError($q, e)
})
}
const fecthDataTransfer = async (id: string) => {
showLoader()
await http
.get(config.API.transferByid(id))
.then((res: any) => {
let data = res.data.result
tranferOrg.value = data.organization
noteReason.value = data.reason
files.value = data.docs
})
.catch((e: any) => {
messageError($q, e)
})
.finally(() => {
hideLoader()
})
}
const fileUploadDoc = async (file: any) => {
fileDocDataUpload.value.push(file)
nameFile.value = file[0].name
files.value = file
}
</script>
<template>
<div class="col-12 row justify-center">
<div class="col-xs-12 col-sm-12 col-md-11">
@ -56,123 +169,3 @@
</div>
</div>
</template>
<script setup lang="ts">
import type { QTableProps } from "quasar"
import { ref, onMounted } from "vue"
import { useQuasar } from "quasar"
import { useRouter, useRoute } from "vue-router"
import { useCounterMixin } from "@/stores/mixin"
import http from "@/plugins/http"
import config from "@/app.config"
import type { QForm } from "quasar"
const router = useRouter()
const $q = useQuasar()
const mixin = useCounterMixin()
const myform = ref<QForm | null>(null)
const { date2Thai, fails, success, messageError, showLoader, hideLoader } = mixin
const fileDocDataUpload = ref<File[]>([])
const route = useRoute()
const files = ref<any>()
const tranferOrg = ref("")
const noteReason = ref("")
const id = ref<string>("")
const nameFile = ref<string>("")
const routeName = router.currentRoute.value.name
onMounted(() => {
if (route.params.id !== undefined) {
id.value = route.params.id.toString()
fecthDataTransfer(id.value)
}
})
const filesNull = () => {
files.value = null
}
const saveData = async () => {
console.log(myform.value)
if (myform.value != null) {
await myform.value.validate().then(async (saveDataTest: Boolean) => {
if (saveDataTest) {
saveTransfer()
}
})
}
}
const saveTransfer = () => {
$q.dialog({
title: "ยืนยันการยื่นข้อมูลการโอน",
message: "ต้องการยื่นข้อมูลการโอนนี้ใช่หรือไม่?",
cancel: {
flat: true,
color: "negative",
},
persistent: true,
})
.onOk(async () => {
if (files.value == undefined) {
fails($q, "กรุณากรอกอัพโหลดเอกสารเพิ่มเติม")
} else {
createTransfer()
}
})
.onCancel(() => {})
.onDismiss(() => {})
}
const createTransfer = async () => {
const formData = new FormData()
const blob = files.value.slice(0, files.value[0].size)
const newFile = new File(blob, nameFile.value, {
type: files.value[0].type,
})
formData.append("Organization", tranferOrg.value)
formData.append("Reason", noteReason.value)
formData.append("file", newFile)
console.log(files.value)
console.log(formData)
await http
.post(config.API.listtransfer(), formData)
.then((res: any) => {
console.log(res)
success($q, "บันทึกข้อมูลสำเร็จ")
router.push(`/transfer`)
})
.catch((e: any) => {
messageError($q, e)
console.log(e)
})
}
const fecthDataTransfer = async (id: string) => {
showLoader()
await http
.get(config.API.transferByid(id))
.then((res: any) => {
let data = res.data.result
// console.log(data);
tranferOrg.value = data.organization
noteReason.value = data.reason
files.value = data.docs
console.log(files.value)
})
.catch((e: any) => {
messageError($q, e)
})
.finally(() => {
hideLoader()
})
}
const fileUploadDoc = async (file: any) => {
fileDocDataUpload.value.push(file)
nameFile.value = file[0].name
files.value = file
}
</script>

View file

@ -106,16 +106,13 @@ onMounted(async () => {
await fecthListTransfer()
})
//
const fecthListTransfer = async () => {
console.log(config.API.listUserTransfer())
showLoader()
await http
.get(config.API.listUserTransfer())
.then((res: any) => {
// console.log(res);
let data = res.data.result
console.log(data)
rows.value = data.map((e: any) => ({
id: e.id,
date: date2Thai(e.createdAt),
@ -129,7 +126,6 @@ const fecthListTransfer = async () => {
}))
})
.catch((e: any) => {
console.log("e")
messageError($q, e)
})
.finally(() => {