Refactoring code module 11_discipline

This commit is contained in:
STW_TTTY\stwtt 2024-09-19 16:37:16 +07:00
parent 202fbf27b6
commit 9653ae78cb
58 changed files with 1021 additions and 1305 deletions

View file

@ -1,30 +1,22 @@
<script setup lang="ts">
import { onMounted, reactive, ref, useAttrs } from "vue";
import router from "@/router";
import { onMounted, ref } from "vue";
import { useQuasar } from "quasar";
import type { QTableProps } from "quasar";
import http from "@/plugins/http";
import config from "@/app.config";
import type { QTableProps } from "quasar";
import type { FormOrderPlacementMainData } from "@/modules/10_order/interface/request/Main";
import type {
DataOption,
DataOption1,
} from "@/modules/10_order/interface/index/Main";
import PopupHistory from "@/modules/10_order/components/PopupHistory.vue";
import TableOrder from "@/modules/11_discipline/components/9_Order/TableOrder.vue";
import router from "@/router";
import { checkPermission } from "@/utils/permissions";
import { useOrderPlacementDataStore } from "@/modules/10_order/store";
import { useOrderStore } from "@/modules/11_discipline/store/OrderStore";
import { useCounterMixin } from "@/stores/mixin";
import { useOrderPlacementDataStore } from "@/modules/10_order/store";
import { checkPermission } from "@/utils/permissions";
import type { DataOption1 } from "@/modules/10_order/interface/index/Main";
import PopupHistory from "@/modules/10_order/components/PopupHistory.vue";
import TableOrder from "@/modules/11_discipline/components/9_Order/TableOrder.vue";
const $q = useQuasar(); // noti quasar
const mixin = useCounterMixin();
const DataStore = useOrderPlacementDataStore();
const stroe = useOrderStore();
const { showLoader, hideLoader, messageError, date2Thai } = mixin;
@ -41,116 +33,11 @@ const commandCodes = ref<string[]>([
"C-PM-32",
]);
//
const columns = ref<QTableProps["columns"]>([
{
name: "Order",
align: "left",
label: "คำสั่ง",
sortable: true,
field: "Order",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "OrderNum",
align: "left",
label: "เลขที่คำสั่ง",
sortable: true,
field: "OrderNum",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "OrderType",
align: "left",
label: "ประเภท",
sortable: false,
field: "OrderType",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "OrderDate",
align: "left",
label: "สั่ง ณ วันที่/วันที่คำสั่งมีผล",
sortable: true,
field: "OrderDate",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a, b) => parseInt(a) - parseInt(b),
},
{
name: "OrderBy",
align: "left",
label: "คำสั่งโดย",
sortable: true,
field: "OrderBy",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "Signer",
align: "left",
label: "ผู้ลงนาม",
sortable: true,
field: "Signer",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "OrderStatus",
align: "center",
label: "สถานะคำสั่ง",
sortable: true,
field: "OrderStatus",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
]);
async function fetchOrderlist() {
showLoader();
await http
.get(config.API.listOrder())
.then((res: any) => {
const data = res.data.result;
const typeid = OrderTypeOption.value.map((e) => e.id);
const filterListOrder = data.filter((e: any) =>
typeid.includes(e.orderTypeValue)
);
stroe.fetchOrder(filterListOrder);
})
.catch((e: any) => {
messageError($q, e);
})
.finally(async () => {
hideLoader();
});
}
//
const clickAdd = () => {
router.push({ name: "disciplineOrderAdd" });
};
//
const fiscalyear = ref<number | null>(0);
const fiscalyearOP = ref<any>([{ id: 0, name: "ทั้งหมด" }]);
const fiscalyearFilter1 = ref<any>([]);
const fiscalYearFilter = async () => {
async function fiscalYearFilter() {
await http.get(config.API.yearOptionsOrder()).then((res) => {
const response = res.data.result;
fiscalyearOP.value = [{ id: 0, name: "ทั้งหมด" }];
@ -166,7 +53,7 @@ const fiscalYearFilter = async () => {
});
});
});
};
}
//
const OrderType = ref<string>("");
@ -187,11 +74,13 @@ const addedOrderStatusValues: string[] = [];
const filterKeyword = ref<string>("");
const filterRef = ref<any>(null);
/** ล้างค่า input */
function resetFilter() {
filterKeyword.value = "";
filterRef.value.focus();
}
/** ประเภทครับสั่ง ฟิลเตอร์ */
async function OrderTypeFilter() {
await http
.get(config.API.typeOrder())
@ -217,6 +106,7 @@ async function searchFilterTable() {
stroe.filterListOrder(OrderType.value, OrderStatus.value, fiscalyear.value);
}
/** สถานะคำสั่ง ฟิลเตอร์ */
async function OrderStatusFilter() {
for (let data of stroe.mainData) {
const OrderStatusValue = data.orderStatusName;
@ -272,6 +162,32 @@ function filterSelector(val: any, update: Function, refData: string) {
}
}
async function fetchOrderlist() {
showLoader();
await http
.get(config.API.listOrder())
.then((res: any) => {
const data = res.data.result;
const typeid = OrderTypeOption.value.map((e) => e.id);
const filterListOrder = data.filter((e: any) =>
typeid.includes(e.orderTypeValue)
);
stroe.fetchOrder(filterListOrder);
})
.catch((e: any) => {
messageError($q, e);
})
.finally(async () => {
hideLoader();
});
}
//
function clickAdd() {
router.push({ name: "disciplineOrderAdd" });
}
onMounted(async () => {
await fiscalYearFilter();
await OrderTypeFilter();

View file

@ -1,11 +1,11 @@
<script setup lang="ts">
import { ref, onMounted } from "vue";
import router from "@/router";
/** importType */
import type { QTableProps } from "quasar";
/** importStroe */
import router from "@/router";
import { useOrderStore } from "@/modules/11_discipline/store/OrderStore";
import { checkPermission } from "@/utils/permissions";
const OrderStore = useOrderStore();
/** รับ props มาจากหน้าหลัก */
@ -190,7 +190,7 @@ const pagination = ref({
* @param id id ออกคำส
* @param status status
*/
const redirectToPage = (id?: string, status?: string) => {
function redirectToPage(id?: string, status?: string) {
let step = 1;
switch (status) {
case "จัดทำร่างคำสั่ง":
@ -207,13 +207,14 @@ const redirectToPage = (id?: string, status?: string) => {
break;
}
router.push(`/discipline-order/detail/${id}?step=${step}`);
};
}
/**
* งช redirect
* @param id id ออกคำส
* @param status status
*/
const redirectToDetailPage = (id?: string, status?: string) => {
function redirectToDetailPage(id?: string, status?: string) {
let step = 1;
switch (status) {
case "จัดทำร่างคำสั่ง":
@ -230,7 +231,7 @@ const redirectToDetailPage = (id?: string, status?: string) => {
break;
}
router.push(`/discipline-order-detail/detail/${id}?step=${step}`);
};
}
/** โหลดข้อมูลเมื่อเข้าหน้านี้ */
onMounted(() => {