diff --git a/src/modules/18_command/components/DialogCreateCommand.vue b/src/modules/18_command/components/DialogCreateCommand.vue index 30937102d..414f7ed72 100644 --- a/src/modules/18_command/components/DialogCreateCommand.vue +++ b/src/modules/18_command/components/DialogCreateCommand.vue @@ -9,8 +9,12 @@ import { useCounterMixin } from "@/stores/mixin"; import { useCommandMainStore } from "@/modules/18_command/store/Main"; import type { QTableProps } from "quasar"; +import type { + ListCommand, + DataOrder, + Pagination, +} from "@/modules/18_command/interface/index/Main"; import type { DataListCommand } from "@/modules/18_command/interface/response/Main"; -import type { ListCommand } from "@/modules/18_command/interface/index/Main"; import DialogHeader from "@/components/DialogHeader.vue"; @@ -18,17 +22,11 @@ const storeCommand = useCommandMainStore(); const router = useRouter(); const $q = useQuasar(); const mixin = useCounterMixin(); -const { - showLoader, - success, - messageError, - dialogConfirm, - hideLoader, - date2Thai, -} = mixin; +const { showLoader, messageError, dialogConfirm, hideLoader, date2Thai } = + mixin; +/** props*/ const modal = defineModel("modal", { required: true }); - const props = defineProps({ commandTypeCode: String, // ไอดีประเภทคำสั่ง persons: Array, // ไอดีคนที่เลือกออกคำสั่งส่งมาเป็น array @@ -36,22 +34,14 @@ const props = defineProps({ const commandOp = ref([]); // ประเภทคำสั่ง const commandType = ref(""); //ประเภทคำสั่ง -const commandNo = ref(""); -const commandYear = ref(new Date().getFullYear()); +const commandNo = ref(""); //คำสั่งเลขที่ +const commandYear = ref(new Date().getFullYear()); //ปี const rows = ref([]); // รายการคำสั่ง -const selected = ref([]); // id คำสั่งที่เลือก +const selected = ref([]); // id คำสั่งที่เลือก const filter = ref(""); // คำค้นหา - -const total = ref(0); -const totalList = ref(1); -const pagination = ref({ - sortBy: "createdAt", - descending: true, - page: 1, - rowsPerPage: 10, -}); - +const total = ref(0); //จำนวนรายการ +const totalList = ref(1); //จำนวนหน้า const visibleColumns = ref([ "commandNo", "issue", @@ -125,9 +115,41 @@ const columns = ref([ style: "font-size: 14px", }, ]); +const pagination = ref({ + sortBy: "createdAt", + descending: true, + page: 1, + rowsPerPage: 10, +}); + +const selectCreate = ref("NEW"); //ประเภทการออกคำสั่ง สร้างใหม่/คำสั่งแบบร่าง + +/** ฟังก์ชันเรียกข้อมูลรายการคำสั่ง*/ +async function getListCommandDraf() { + showLoader(); + await http + .get( + config.API.commandList + + `?page=${pagination.value.page}&pageSize=${pagination.value.rowsPerPage}&year=${commandYear.value}&keyword=${filter.value}&status=DRAFT&commandTypeId=${commandType.value}` + ) + .then(async (res) => { + totalList.value = Math.ceil( + res.data.result.total / pagination.value.rowsPerPage + ); + total.value = res.data.result.total; + rows.value = res.data.result.data; + }) + .catch((err) => { + messageError($q, err); + }) + .finally(() => { + hideLoader(); + }); +} /** * ฟังก์ชันสร้างคำสั่งใหม่ + * @param isRedirect บันทึกและไปยังหน้าคำสั่ง เป็น true บันทึกและเลือกรายชื่อต่อ เป็น false */ function createCommand(isRedirect: boolean) { dialogConfirm($q, async () => { @@ -153,7 +175,6 @@ function createCommand(isRedirect: boolean) { if (isRedirect) { router.push(`/command/edit/${id}`); } else { - // modal.value = false; clearValue(); } }) @@ -168,6 +189,7 @@ function createCommand(isRedirect: boolean) { /** * ฟังก์ชันเพิ่มคนเข้าไปในคำสั่งที่เป็นแบบร่าง + * @param isRedirect บันทึกและไปยังหน้าคำสั่ง เป็น true บันทึกและเลือกรายชื่อต่อ เป็น false */ function addPersonalToCommand(isRedirect: boolean) { dialogConfirm($q, async () => { @@ -204,6 +226,10 @@ function addPersonalToCommand(isRedirect: boolean) { }); } +/** + * ฟังก์ชันบันทึกข้อมูล + * @param isRedirect บันทึกและไปยังหน้าคำสั่ง เป็น true บันทึกและเลือกรายชื่อต่อ เป็น false + */ function onSubmit(isRedirect: boolean) { if (selectCreate.value === "NEW") { createCommand(isRedirect); @@ -212,61 +238,41 @@ function onSubmit(isRedirect: boolean) { } } -/** ปิด popup */ +/** ฟังก์ชันปิด popup */ function closeModal() { modal.value = false; clearValue(); } +/** ฟังก์ชันกำหน้ค่าเป็น Defult*/ function clearValue() { commandNo.value = ""; commandYear.value = new Date().getFullYear(); - selectCreate.value = "NEW"; selected.value = []; filter.value = ""; } -const selectCreate = ref("NEW"); - -async function getListCommandDraf() { - showLoader(); - await http - .get( - config.API.commandList + - `?page=${pagination.value.page}&pageSize=${pagination.value.rowsPerPage}&year=${commandYear.value}&keyword=${filter.value}&status=DRAFT&commandTypeId=${commandType.value}` - ) - .then(async (res) => { - totalList.value = Math.ceil( - res.data.result.total / pagination.value.rowsPerPage - ); - total.value = res.data.result.total; - rows.value = res.data.result.data; - console.log("🚀 ~ .then ~ rows.value:", rows.value); - }) - .catch((err) => { - messageError($q, err); - }) - .finally(() => { - hideLoader(); - }); -} - -/** ดึงข้อมูลคำสั่ง */ +/** ฟังก์ชันดึงข้อมูลคำสั่ง */ async function fetchCommandType() { const data = await storeCommand.getCommandTypes(); // ยิงไป get ที่ store // filter เฉพาะ code ของคำสั่งที่เลือก commandOp.value = await data.filter( - (v: any) => v.code == props.commandTypeCode + (v: ListCommand) => v.code == props.commandTypeCode ); commandType.value = commandOp.value[0].id; } -function updatePagination(newPagination: any) { +/** + * ฟังก์ชันอัปเดทจำนวนแถวต่อหน้า + * @param newPagination จำนวนแถวที่ต้องการ + */ +function updatePagination(newPagination: Pagination) { pagination.value.page = 1; pagination.value.rowsPerPage = newPagination.rowsPerPage; } +/** ดูการเปลี่ยนแปลงของจำนวนแถวต่อหน้า*/ watch( () => pagination.value.rowsPerPage, async () => { @@ -274,12 +280,14 @@ watch( } ); +/** ดูการเปลี่ยนแปลงของ modal*/ watch(modal, () => { if (modal.value && props.persons?.length !== 0) { fetchCommandType(); } }); +/** ดูการเปลี่ยนแปลงของประเภทการออกคำสั่ง*/ watch( () => selectCreate.value, async () => { diff --git a/src/modules/18_command/components/DialogCreateCommandORG.vue b/src/modules/18_command/components/DialogCreateCommandORG.vue index ac96ff82b..701ad93a2 100644 --- a/src/modules/18_command/components/DialogCreateCommandORG.vue +++ b/src/modules/18_command/components/DialogCreateCommandORG.vue @@ -37,32 +37,53 @@ const commandYear = ref(new Date().getFullYear()); const commandAffectDate = ref(null); //วันที่ลงนาม const commandExcecuteDate = ref(null); //วันที่คำสั่งมีผล -/** - * ฟังก์ชันสร้างคำสั่งใหม่ - */ +/** ฟังก์ชันบันทึกและไปยังหน้าคำสั่ง*/ function onSubmit() { - dialogConfirm($q, () => {}); + dialogConfirm($q, async () => { + showLoader(); + const body = { + commandYear: commandYear.value, + commandNo: commandNo.value, + commandTypeId: commandType.value, + commandAffectDate: commandAffectDate.value, + commandExcecuteDate: commandExcecuteDate.value, + persons: [], + }; + + await http + .post(config.API.command + `/person`, body) + .then(async (res) => { + const id = await res.data.result; + router.push(`/command/edit/${id}`); + modal.value = false; + }) + .catch((e) => { + messageError($q, e); + }) + .finally(() => { + hideLoader(); + }); + }); } -/** ปิด popup */ +/** + * ฟังก์ชันปิด popup สร้างคำสั่ง + * และกำหนดตัวแปรให้เป็นค่า Defult + */ function closeModal() { modal.value = false; - clearValue(); -} - -function clearValue() { commandNo.value = ""; commandYear.value = new Date().getFullYear(); commandAffectDate.value = null; commandExcecuteDate.value = null; } -/** ดึงข้อมูลคำสั่ง */ +/** ฟังก์ชันดึงข้อมูลคำสั่ง */ async function fetchCommandType() { const data = await storeCommand.getCommandTypes(); // ยิงไป get ที่ store // filter เฉพาะ code ของคำสั่งที่เลือก commandOp.value = await data.filter( - (v: any) => v.code == props.commandTypeCode + (v: ListCommand) => v.code == props.commandTypeCode ); commandType.value = commandOp.value[0].id; } @@ -250,16 +271,6 @@ watch(modal, () => { -