ออกคำสังโครงสร้าง
This commit is contained in:
parent
f891926553
commit
54395379b5
3 changed files with 107 additions and 75 deletions
|
|
@ -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<boolean>("modal", { required: true });
|
||||
|
||||
const props = defineProps({
|
||||
commandTypeCode: String, // ไอดีประเภทคำสั่ง
|
||||
persons: Array, // ไอดีคนที่เลือกออกคำสั่งส่งมาเป็น array
|
||||
|
|
@ -36,22 +34,14 @@ const props = defineProps({
|
|||
|
||||
const commandOp = ref<ListCommand[]>([]); // ประเภทคำสั่ง
|
||||
const commandType = ref<string>(""); //ประเภทคำสั่ง
|
||||
const commandNo = ref<string>("");
|
||||
const commandYear = ref<number>(new Date().getFullYear());
|
||||
const commandNo = ref<string>(""); //คำสั่งเลขที่
|
||||
const commandYear = ref<number>(new Date().getFullYear()); //ปี
|
||||
|
||||
const rows = ref<DataListCommand[]>([]); // รายการคำสั่ง
|
||||
const selected = ref<any[]>([]); // id คำสั่งที่เลือก
|
||||
const selected = ref<DataOrder[]>([]); // id คำสั่งที่เลือก
|
||||
const filter = ref<string>(""); // คำค้นหา
|
||||
|
||||
const total = ref<number>(0);
|
||||
const totalList = ref<number>(1);
|
||||
const pagination = ref({
|
||||
sortBy: "createdAt",
|
||||
descending: true,
|
||||
page: 1,
|
||||
rowsPerPage: 10,
|
||||
});
|
||||
|
||||
const total = ref<number>(0); //จำนวนรายการ
|
||||
const totalList = ref<number>(1); //จำนวนหน้า
|
||||
const visibleColumns = ref<string[]>([
|
||||
"commandNo",
|
||||
"issue",
|
||||
|
|
@ -125,9 +115,41 @@ const columns = ref<QTableProps["columns"]>([
|
|||
style: "font-size: 14px",
|
||||
},
|
||||
]);
|
||||
const pagination = ref({
|
||||
sortBy: "createdAt",
|
||||
descending: true,
|
||||
page: 1,
|
||||
rowsPerPage: 10,
|
||||
});
|
||||
|
||||
const selectCreate = ref<string | null>("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<string | null>("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 () => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue