diff --git a/src/modules/05_leave/components/FormLeave/Form.vue b/src/modules/05_leave/components/FormLeave/Form.vue index e455ea9..dc834c6 100644 --- a/src/modules/05_leave/components/FormLeave/Form.vue +++ b/src/modules/05_leave/components/FormLeave/Form.vue @@ -18,6 +18,25 @@ const dataStore = useLeaveStore(); const storeData = useDataStore(); const { date2Thai, messageError } = useCounterMixin(); +/** ฟังก์ชันสำหรับลบคำที่ซ้ำติดกัน */ +function removeDuplicateWords(text: string): string { + if (!text) return text; + + // แยกคำด้วยการหาคำที่ซ้ำติดกัน + const words = text.split(/(?=[ก-๙])/); + const result: string[] = []; + + for (let i = 0; i < words.length; i++) { + const word = words[i]; + if (i === 0 || word !== words[i - 1]) { + result.push(word); + } + } + + // วิธีที่ดีกว่า: ใช้ regex เพื่อหาและลบคำที่ซ้ำ + return text.replace(/([ก-๙]+)\1+/g, "$1"); +} + /** รับ props มาจากหน้าหลัก */ const props = defineProps({ model: { @@ -56,11 +75,14 @@ const columns = ref([ style: "font-size: 14px", }, { - name: "posExecutiveName", + name: "posExecutiveNameOrg", align: "left", label: "ตำแหน่งทางการบริหาร", sortable: true, - field: "posExecutiveName", + field: "posExecutiveNameOrg", + format(val) { + return removeDuplicateWords(val || ""); + }, headerStyle: "font-size: 14px", style: "font-size: 14px", }, @@ -136,7 +158,9 @@ function onSubmit() { ? `${selected.value[0].prefix}${selected.value[0].firstName} ${selected.value[0].lastName}` : ""; - dataStore.commanderPosition = selected.value[0].posExecutiveName; + dataStore.commanderPosition = removeDuplicateWords( + selected.value[0].posExecutiveNameOrg || "" + ); } /**