refactor(DialogOrgSelect): fetch data

This commit is contained in:
DESKTOP-1R2VSQH\Lenovo ThinkPad E490 2026-05-06 09:39:53 +07:00
parent 999a2d1b45
commit e513586b65

View file

@ -24,14 +24,14 @@ import DialogHeader from "@/components/DialogHeader.vue";
const props = defineProps({ const props = defineProps({
dataRows: { dataRows: {
type: Object, type: Object,
require: true, required: true,
}, },
onSubmit: Function, onSubmit: Function,
}); });
const $q = useQuasar(); const $q = useQuasar();
const route = useRoute(); const route = useRoute();
const storeTree = useStructureTree(); const storeTree = useStructureTree();
const { fetchStructureTree } = useStructureTree(); const { fetchStructureTree } = storeTree;
const mixin = useCounterMixin(); const mixin = useCounterMixin();
const { const {
dialogConfirm, dialogConfirm,
@ -47,10 +47,10 @@ const {
/** props*/ /** props*/
const modal = defineModel<boolean>("modal", { required: true }); const modal = defineModel<boolean>("modal", { required: true });
const title = defineModel<string>("title", { required: true }); const title = defineModel<string>("title", { required: true });
const type = defineModel<any>("type", { required: true }); const type = defineModel<string | null>("type", { required: true });
const posType = defineModel<any>("posType", { required: true }); const posType = defineModel<string | null>("posType", { required: true });
const posLevel = defineModel<any>("posLevel", { required: true }); const posLevel = defineModel<string | null>("posLevel", { required: true });
const position = defineModel<any>("position", { required: true }); const position = defineModel<string | null>("position", { required: true });
// const routeName = ref<string>(route?.name); // const routeName = ref<string>(route?.name);
const orgRevisionId = ref<string>(""); const orgRevisionId = ref<string>("");
@ -64,7 +64,7 @@ const itemTaps = ref<string[]>();
const filters = ref<string>(""); const filters = ref<string>("");
const positionId = ref<string>(""); const positionId = ref<string>("");
const selectedPos = ref<any[]>([]); const selectedPos = ref<any[]>([]);
const seletcId = ref<string>(""); const selectId = ref<string>("");
const datePos = ref<Date>(new Date()); const datePos = ref<Date>(new Date());
const rowsPosition = ref<Positions[]>([]); const rowsPosition = ref<Positions[]>([]);
const positionData = ref<any[]>([]); const positionData = ref<any[]>([]);
@ -79,7 +79,6 @@ const formActive = reactive<FormActive>({
}); });
/** node */ /** node */
const nodes = ref<Array<OrgTree>>([]); const nodes = ref<Array<OrgTree>>([]);
const lazy = ref(nodes);
const expanded = ref<string[]>([]); const expanded = ref<string[]>([]);
const nodeLevel = ref<number>(0); const nodeLevel = ref<number>(0);
const nodeId = ref<string>(""); // id Tree const nodeId = ref<string>(""); // id Tree
@ -150,7 +149,7 @@ const columns = ref<QTableProps["columns"]>([
style: "font-size: 14px", style: "font-size: 14px",
}, },
]); ]);
const columnsPostition = ref<QTableProps["columns"]>([ const columnsPosition = ref<QTableProps["columns"]>([
{ {
name: "no", name: "no",
align: "left", align: "left",
@ -181,7 +180,7 @@ const columnsPostition = ref<QTableProps["columns"]>([
{ {
name: "posTypeName", name: "posTypeName",
align: "left", align: "left",
label: "ประเภทตำเเหน่ง", label: "ประเภทตำหน่ง",
sortable: true, sortable: true,
field: "posTypeName", field: "posTypeName",
headerStyle: "font-size: 14px", headerStyle: "font-size: 14px",
@ -335,11 +334,11 @@ async function getDataTable(id: string, level: number = 0) {
function updateSelected(data: DataTree) { function updateSelected(data: DataTree) {
if (props?.dataRows?.nodeId === data.orgTreeId) { if (props?.dataRows?.nodeId === data.orgTreeId) {
positionId.value = props?.dataRows?.posmasterId; positionId.value = props?.dataRows?.posmasterId;
seletcId.value = props?.dataRows?.positionId; selectId.value = props?.dataRows?.positionId;
datePos.value = props?.dataRows?.reportingDate; datePos.value = props?.dataRows?.reportingDate;
} else { } else {
positionId.value = ""; positionId.value = "";
seletcId.value = ""; selectId.value = "";
selectedPos.value = []; selectedPos.value = [];
datePos.value = new Date(); datePos.value = new Date();
} }
@ -386,9 +385,9 @@ async function onClickSelectPos(id: string) {
// //
if (position) { if (position) {
rowsPosition.value = position.positions; rowsPosition.value = position.positions;
if (seletcId.value) { if (selectId.value) {
selectedPos.value = rowsPosition.value.filter( selectedPos.value = rowsPosition.value.filter(
(e) => e.id === seletcId.value (e) => e.id === selectId.value
); );
} }
} }
@ -412,12 +411,14 @@ async function fetchPosFind(level: number, id: string) {
expanded.value = data; expanded.value = data;
nodeId.value = id; nodeId.value = id;
positionId.value = props?.dataRows?.posmasterId; positionId.value = props?.dataRows?.posmasterId;
seletcId.value = props?.dataRows?.positionId; selectId.value = props?.dataRows?.positionId;
datePos.value = props?.dataRows?.reportingDate; datePos.value = props?.dataRows?.reportingDate;
await getDataTable(nodeId.value, level); await getDataTable(nodeId.value, level);
}) })
.catch((e) => { .catch((e) => {
messageError($q, e); messageError($q, e);
})
.finally(() => {
hideLoader(); hideLoader();
}); });
} }
@ -461,20 +462,16 @@ function fetchPositionUes() {
watch( watch(
() => isAll.value, () => isAll.value,
(value, oldVal) => { () => {
if (value !== oldVal) {
getDataTable(nodeId.value, nodeLevel.value); getDataTable(nodeId.value, nodeLevel.value);
} }
}
); );
watch( watch(
() => isBlank.value, () => isBlank.value,
(value, oldVal) => { () => {
if (value !== oldVal) {
getDataTable(nodeId.value, nodeLevel.value); getDataTable(nodeId.value, nodeLevel.value);
} }
}
); );
watch( watch(
@ -489,9 +486,17 @@ function onSubmit() {
const dataPosMaster = posMasterMain.value?.find( const dataPosMaster = posMasterMain.value?.find(
(e: any) => e.id === positionId.value (e: any) => e.id === positionId.value
); );
if (!dataPosMaster) {
dialogMessageNotify($q, "ไม่พบข้อมูลตำแหน่ง");
return;
}
if (selectedPos.value.length === 0) { if (selectedPos.value.length === 0) {
dialogMessageNotify($q, "กรุณาเลือกตำแหน่ง"); dialogMessageNotify($q, "กรุณาเลือกตำแหน่ง");
} else { return;
}
dialogConfirm($q, async () => { dialogConfirm($q, async () => {
const body = { const body = {
personalId: props?.dataRows?.id, personalId: props?.dataRows?.id,
@ -518,7 +523,6 @@ function onSubmit() {
close(); close();
}); });
} }
}
function onSearch() { function onSearch() {
positionNo.value = onSearchDataTable( positionNo.value = onSearchDataTable(
@ -564,7 +568,7 @@ onMounted(async () => {
<q-tree <q-tree
class="q-pa-sm q-gutter-sm" class="q-pa-sm q-gutter-sm"
dense dense
:nodes="lazy" :nodes="nodes"
node-key="orgTreeId" node-key="orgTreeId"
label-key="labelName" label-key="labelName"
:filter="filter" :filter="filter"
@ -830,7 +834,7 @@ onMounted(async () => {
</q-toolbar> </q-toolbar>
<d-table <d-table
ref="table" ref="table"
:columns="columnsPostition" :columns="columnsPosition"
:rows="rowsPosition" :rows="rowsPosition"
row-key="id" row-key="id"
flat flat