โครงสร้าง สร้างคำสั่ง

This commit is contained in:
setthawutttty 2024-10-18 12:58:18 +07:00
parent 5d9131d5b7
commit 97a62de026
5 changed files with 150 additions and 104 deletions

View file

@ -1,5 +1,5 @@
<script setup lang="ts">
import { ref, watch } from "vue";
import { nextTick, ref, watch, computed } from "vue";
import { useQuasar } from "quasar";
import http from "@/plugins/http";
@ -31,9 +31,13 @@ const {
} = mixin;
const modal = defineModel<boolean>("modal", { required: true });
const isOfficer = defineModel<boolean>("isOfficer");
const isStaff = defineModel<boolean>("isStaff");
const rootId = defineModel<string>("rootId");
const props = defineProps({
commandTypeCode: String, //
orgPublishDate: { type: Date, defult: undefined },
orgPublishDate: { type: Date || undefined, defult: undefined },
});
const commandOp = ref<ListCommand[]>([]); //
@ -42,49 +46,36 @@ const commandNo = ref<string>(""); //คำสั่งเลขที่
const commandYear = ref<number>(new Date().getFullYear());
const commandAffectDate = ref<Date | null>(null); //
const commandExcecuteDate = ref<Date | null>(null); //
const group = ref<string>(
"กลุ่มที่ 1.1 : ปฏิบัติงาน ชำนาญงาน ปฏิบัติการ ชำนาญการ"
); //
const group = ref<string>("GROUP1"); //
const isCheckOrgPublishDate = ref<boolean>(false); //
const groupOp = ref<DataOption[]>([]);
const groupDataOp = ref<DataOption[]>([
{
id: "1.1",
id: "GROUP1",
name: "กลุ่มที่ 1.1 : ปฏิบัติงาน ชำนาญงาน ปฏิบัติการ ชำนาญการ",
},
{
id: "1.2",
id: "GROUP1.2",
name: "กลุ่มที่ 1.2 : อาวุโส ชำนาญการพิเศษ อำนวยการต้น",
},
{
id: "2",
id: "GROUP2",
name: "กลุ่มที่ 2 : ทักษะพิเศษ เชี่ยวชาญ ทรงคุณวุฒิ อำนวยการสูง บริหารต้น บริหารสูง",
},
]);
const groupOp = ref<DataOption[]>(groupDataOp.value);
const dataMapToSend = computed(() => {
return selected.value.map((i: any) => ({
refId: i.id,
profileId: i.profileId,
prefix: i.prefix,
firstName: i.firstName,
lastName: i.lastName,
citizenId: i.citizenId,
}));
});
//Table
const rows = ref<any[]>([
{
id: "1",
posMasterNo: "สกก.3",
positionName: "นักจัดการงานทั่วไป",
posTypeName: "ทั่วไป",
posLevelName: "ปฏิบัติงาน",
positionIsSelected: "นายศรัณย์ ศิลาดี",
group: "1.1",
selected: true,
},
{
id: "4",
posMasterNo: "สกก.4",
positionName: "นักจัดการงานทั่วไป",
posTypeName: "วิชาการ",
posLevelName: "ปฏิบัติการ",
positionIsSelected: "นางเกษมณี ใจดี",
group: "1.1",
selected: true,
},
]);
const rows = ref<any[]>([]);
const selected = ref<any[]>([]);
const columns = ref<QTableProps["columns"]>([
{
@ -106,20 +97,20 @@ const columns = ref<QTableProps["columns"]>([
style: "font-size: 14px",
},
{
name: "posTypeName",
name: "posType",
align: "left",
label: "ประเภทตำแหน่ง",
sortable: false,
field: "posTypeName",
field: "posType",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "posLevelName",
name: "posLevel",
align: "left",
label: "ระดับตำแหน่ง",
sortable: false,
field: "posLevelName",
field: "posLevel",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
@ -137,28 +128,28 @@ const columns = ref<QTableProps["columns"]>([
/** ฟังก์ชันบันทึกและไปยังหน้าคำสั่ง*/
function onSubmit() {
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();
// });
showLoader();
const body = {
commandTypeId: commandType.value,
commandAffectDate: commandAffectDate.value,
commandExcecuteDate: commandExcecuteDate.value,
commandYear: commandYear.value,
commandNo: commandNo.value,
persons: selected.value ? dataMapToSend.value : [],
};
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();
});
});
}
@ -172,10 +163,10 @@ function closeModal() {
commandYear.value = new Date().getFullYear();
commandAffectDate.value = null;
commandExcecuteDate.value = null;
group.value = "กลุ่มที่ 1.1 : ปฏิบัติงาน ชำนาญงาน ปฏิบัติการ ชำนาญการ";
group.value = "GROUP1";
isCheckOrgPublishDate.value = false;
// rows.value = [];
// selected.value = [];
rows.value = [];
selected.value = [];
}
/** ฟังก์ชันดึงข้อมูลคำสั่ง */
@ -207,50 +198,47 @@ function filterOption(val: string, update: Function) {
* งกนเลอกกล
* @param val กลมทองการคนหา
*/
function updateGroup(val: string) {
const data = [
{
id: "1",
posMasterNo: "สกก.3",
positionName: "นักจัดการงานทั่วไป",
posTypeName: "ทั่วไป",
posLevelName: "ปฏิบัติงาน",
positionIsSelected: "นายศรัณย์ ศิลาดี",
group: "1.1",
selected: true,
},
{
id: "2",
posMasterNo: "สกก.2",
positionName: "นักทรัพยากรบุคคล",
posTypeName: "วิชาการ",
posLevelName: "ชำนาญการพิเศษ",
positionIsSelected: "นางสาวพรทิพย์ กาญจนา",
group: "1.2",
selected: true,
},
{
id: "3",
posMasterNo: "สกก.1",
positionName: "นักบริหาร",
posTypeName: "บริหาร",
posLevelName: "สูง",
positionIsSelected: "นางสาวพรทิพย์ กาญจนา",
group: "2",
selected: true,
},
];
rows.value = data.filter((e: any) => e.group === val);
function updateGroup() {
getPerson();
}
watch(modal, () => {
/** ดึงข้อมูลคน */
function getPerson() {
const body = {
rootId: rootId.value ? rootId.value : "",
type: group.value,
};
showLoader();
http
.post(config.API.orgPosReport, body)
.then((res) => {
const data = res.data.result;
rows.value = data;
hideLoader();
})
.catch((e) => {
messageError($q, e);
hideLoader();
})
.finally(() => {});
}
watch(modal, async () => {
if (modal.value) {
fetchCommandType();
if (props.orgPublishDate) {
commandExcecuteDate.value = props.orgPublishDate;
isCheckOrgPublishDate.value = true;
}
await nextTick();
if (isOfficer.value) {
group.value = "GROUP1.2";
groupDataOp.value = groupDataOp.value.filter(
(item) => item.id !== "GROUP1"
);
}
getPerson();
}
});
</script>
@ -444,11 +432,10 @@ watch(modal, () => {
option-value="id"
class="inputgreen"
dense
:readonly="isStaff"
emit-value
map-options
lazy-rules
use-input
hide-bottom-space
outlined
@update:model-value="updateGroup"
@filter="(inputValue:any,doneFn:Function) => filterOption(inputValue, doneFn) "
@ -493,7 +480,7 @@ watch(modal, () => {
keep-color
color="primary"
dense
v-model="props.row.selected"
v-model="props.selected"
/>
</q-td>
@ -518,6 +505,13 @@ watch(modal, () => {
: "-"
}}
</div>
<div v-else-if="col.name === 'positionIsSelected'">
{{
props.row.firstName
? `${props.row.prefix}${props.row.firstName} ${props.row.lastName}`
: "-"
}}
</div>
<div v-else>
{{ col.value ? col.value : "-" }}
</div>
@ -548,7 +542,7 @@ watch(modal, () => {
label="ส่งไปออกคำสั่ง"
:disable="
commandType == '' ||
rows.filter((x) => x.selected).length === 0 ||
selected.length === 0 ||
!commandNo ||
!commandYear
"