diff --git a/src/api/05_command/api.command.ts b/src/api/05_command/api.command.ts index 74be17ad..6d174539 100644 --- a/src/api/05_command/api.command.ts +++ b/src/api/05_command/api.command.ts @@ -1,6 +1,7 @@ import env from "../index"; -const order = `${env.API_URI}/order`; +const order = `${env.API_URI}/org`; export default { - commandType: `${order}/order-type`, + commandType: `${order}/commandType`, + commandSysList: `${order}/commandSys/list`, }; diff --git a/src/modules/05_command/components/FormTemplate.vue b/src/modules/05_command/components/FormTemplate.vue index 2a95bf12..2362dc3c 100644 --- a/src/modules/05_command/components/FormTemplate.vue +++ b/src/modules/05_command/components/FormTemplate.vue @@ -1,71 +1,73 @@ @@ -83,24 +85,6 @@ watch( v-model="textHeader" label="เนื้อหาคำสั่งส่วนต้น" /> - @@ -114,25 +98,6 @@ watch( v-model="textBody" label="เนื้อหาคำสั่งส่วนกลาง" /> - - @@ -146,24 +111,6 @@ watch( v-model="textFooter" label="เนื้อหาคำสั่งส่วนท้าย" /> - diff --git a/src/modules/05_command/components/ViewPdf.vue b/src/modules/05_command/components/ViewPdf.vue index ba84b18a..b9d755df 100644 --- a/src/modules/05_command/components/ViewPdf.vue +++ b/src/modules/05_command/components/ViewPdf.vue @@ -1,14 +1,16 @@ @@ -222,7 +227,31 @@ watch( - + + + + + + + diff --git a/src/modules/05_command/interface/index/Main.ts b/src/modules/05_command/interface/index/Main.ts index b7292feb..6a801da2 100644 --- a/src/modules/05_command/interface/index/Main.ts +++ b/src/modules/05_command/interface/index/Main.ts @@ -16,8 +16,9 @@ interface ListOrder { id: string; commandCode: string; name: string; - status: boolean; + isActive: boolean; category?: string; + commandSysId: string; } interface ListTemplateSalary { diff --git a/src/modules/05_command/interface/response/Main.ts b/src/modules/05_command/interface/response/Main.ts index e4ea7770..21d04973 100644 --- a/src/modules/05_command/interface/response/Main.ts +++ b/src/modules/05_command/interface/response/Main.ts @@ -1 +1,22 @@ -export type {}; +interface DataCommandSys { + id: string; + createdAt: string; + lastUpdatedAt: string; + createdFullName: string; + lastUpdateFullName: string; + sysName: string; + sysDescription: string; +} + +interface DataTemplateDetail { + id: string; + name: string; + code: string; + detailHeader: string; + detailBody: string; + detailFooter: string; + isActive: boolean; + commandSysId: string; +} + +export type { DataCommandSys, DataTemplateDetail }; diff --git a/src/modules/05_command/views/lists.vue b/src/modules/05_command/views/lists.vue index 56d7cb98..f15f5856 100644 --- a/src/modules/05_command/views/lists.vue +++ b/src/modules/05_command/views/lists.vue @@ -13,6 +13,10 @@ import type { Tabs, DateOption, } from "@/modules/05_command/interface/index/Main"; +import type { + DataCommandSys, + DataTemplateDetail, +} from "@/modules/05_command/interface/response/Main"; import Header from "@/components/DialogHeader.vue"; import PageOrder from "@/modules/05_command/components/ViewPdf.vue"; @@ -30,7 +34,12 @@ const { messageError, } = mixin; -const isActive = ref(""); // สถานะของรายการคำสั่ง +const childTemplateDetailRef = ref | null>( + null +); //ref components ข้อความต้นแบบ +const childPageOrderRef = ref | null>(null); //ref components คำสั่ง + +const isActive = ref(true); // สถานะของรายการคำสั่ง // options สถานะการใช้งาน const activeOptions = ref([ { @@ -70,20 +79,73 @@ const listOrder = ref([]); // list คำสั่ง const status = ref(false); // สถานะ const isEdit = ref(false); //เก็บ true/false เช็คแก้ไข const dialogFormCommand = ref(false); // model คำสั่ง +const dataTemplateDetail = ref(); + +const page = ref(1); // หน้า +const pageSize = ref(13); // จำนวนข้อมูล +const maxPage = ref(0); // จำนวนหน้า + +/** + * ฟังก์ชั่นดึงรายการประเภทคำสั่ง + */ +async function fetchCommandType() { + showLoader(); + await http + .get(config.API.commandType + `/admin`, { + params: { + page: page.value, + pageSize: pageSize.value, + isActive: isActive.value, + }, + }) + .then(async (res) => { + const data = res.data.result; + listOrder.value = data.commandTypes; + maxPage.value = Math.ceil(data.total / pageSize.value); + }) + .catch((err) => { + messageError($q, err); + }) + .finally(() => { + hideLoader(); + }); +} + +/** + * ฟังก์ชันดึงข้อมูลรายการหมวดหมู่ + */ +function fetchCommandSys() { + showLoader(); + http + .get(config.API.commandSysList) + .then((res) => { + const data = res.data.result; + const option = data.map((e: DataCommandSys) => ({ + id: e.id, + name: e.sysName, + })); + dataCategory.value = option; + categoryOP.value = option; + }) + .catch((err) => { + messageError($q, err); + }) + .finally(() => { + hideLoader(); + }); +} /** * ฟังก์ชั่นค้นหาคำสั่ง ตามสถานะ * @param val สถานะ true/false */ -function searchByStatus(val: string) { - console.log(val); +function searchByStatus() { + activeOrderId.value = ""; + page.value = 1; + pageSize.value = 13; + fetchCommandType(); } -/** เปิด dialog */ -function onDialogAdd() { - isEdit.value = false; - dialogFormCommand.value = true; -} /** * เปิด dialog Edit * @param data ข้อมูลคำสั่ง @@ -91,8 +153,8 @@ function onDialogAdd() { function onDialogEdit(data: ListOrder) { idOrder.value = data.id; name.value = data.name; - status.value = data.status; - + status.value = data.isActive; + category.value = data.commandSysId; isEdit.value = true; dialogFormCommand.value = true; } @@ -103,52 +165,82 @@ function onDialogEdit(data: ListOrder) { */ function onDelete(id: string) { dialogRemove($q, () => { - // http - // .delete(config.API.) - // .then((res) => {}) - // .catch((e) => { - // messageError($q, e); - // }) - // .finally(() => {}); + showLoader(); + http + .delete(config.API.commandType + `/${id}`) + .then(async () => { + await fetchCommandType(); + }) + .catch((e) => { + messageError($q, e); + }) + .finally(() => { + hideLoader(); + }); }); } -/** ปิด dialog */ +/** + * ปิด dialog + */ function closeDialog() { idOrder.value = ""; isEdit.value = false; dialogFormCommand.value = false; name.value = ""; status.value = false; -} - -/** บันทึกข้อมูล dialog */ -function onSubmit() { - dialogConfirm($q, () => {}); -} - -/** เก็บ id list คำสั่งที่เลือก เพื่อใช้ class */ -function selectInbox(data: ListOrder) { - activeOrderId.value = data.id; + category.value = ""; } /** - * ฟังก์ชั่นดึงรายการประเภทคำสั่ง + * บันทึกข้อมูลการแก้ไขคำสั่ง */ -async function fetchOrderType() { +function onSubmit() { + dialogConfirm($q, async () => { + showLoader(); + await http + .put(config.API.commandType + `/${idOrder.value}`, { + name: name.value, + commandSysId: category.value, + isActive: status.value, + }) + .then(async () => { + await fetchCommandType(); + success($q, "บันทึกข้อมูลสำเร็จ"); + closeDialog(); + }) + .catch((err) => { + messageError($q, err); + }) + .finally(() => { + hideLoader(); + }); + }); +} + +/** + * เก็บ id list คำสั่งที่เลือก เพื่อใช้ class + */ +function selectInbox(data: ListOrder) { + activeOrderId.value = data.id; + fetchDataCommandTypeId(data.id); +} + +/** + * ฟังก์ชันดึงข้อมูลรายละเอียดคำสั่ง + * @param id คำสั่ง + */ +async function fetchDataCommandTypeId(id: string) { showLoader(); await http - .get(config.API.commandType) + .get(config.API.commandType + `/${id}`) .then(async (res) => { - listOrder.value = res.data.result.map((item: any) => { - return { - name: item.name, - category: item.category, - commandCode: item.commandCode, - id: item.id, - status: true, - }; - }); + const data = res.data.result; + dataTemplateDetail.value = data; + await Promise.all([ + childTemplateDetailRef?.value?.fetchData(data), + childPageOrderRef?.value?.fetchDocumentTemplate(data), + ]); }) .catch((err) => { messageError($q, err); @@ -167,14 +259,14 @@ function filterSelector(val: string, update: Function) { update(() => { category.value = val ? "" : category.value; categoryOP.value = dataCategory.value.filter( - (v: any) => v.name.indexOf(val) > -1 + (v: DateOption) => v.name.indexOf(val) > -1 ); }); } /** เริ่มเมื่อโหลดหน้านี้*/ -onMounted(() => { - fetchOrderType(); +onMounted(async () => { + await Promise.all([fetchCommandType(), fetchCommandSys()]); }); @@ -182,11 +274,12 @@ onMounted(() => { รายการคำสั่งและ Template - + + - + - + { option-label="label" option-value="value" emit-value + map-options @update:model-value="searchByStatus" > - - + - - - - {{ item.name }} - - - - - - - + + {{ item.name }} + + + + + + + + - - - - แก้ไข - - - + + แก้ไข + + + + - - - - ลบ - + + + ลบ + - - - - - - - + + + + + + + + + + + {{ "ไม่พบข้อมูล" }} + + + + + + + @@ -313,20 +438,27 @@ onMounted(() => {