ออกคำสังโครงสร้าง

This commit is contained in:
DESKTOP-1R2VSQH\Lenovo ThinkPad E490 2024-10-08 10:35:55 +07:00
parent f891926553
commit 54395379b5
3 changed files with 107 additions and 75 deletions

View file

@ -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 () => {

View file

@ -37,32 +37,53 @@ const commandYear = ref<number>(new Date().getFullYear());
const commandAffectDate = ref<Date | null>(null); //
const commandExcecuteDate = ref<Date | null>(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, () => {
<q-separator />
<q-card-actions align="right">
<!-- <q-btn
label="บันทึกและเลือกรายชื่อต่อ"
@click="() => onSubmit(false)"
:disable="
selectCreate === 'NEW' ? commandType == '' : selected.length == 0
"
color="blue"
>
<q-tooltip>นทกและเลอกรายชอต</q-tooltip>
</q-btn> -->
<q-btn
label="บันทึกและไปยังหน้าคำสั่ง"
:disable="commandType == ''"