diff --git a/src/modules/04_registry/components/Education.vue b/src/modules/04_registry/components/Education.vue index 2266bb578..1863c8e73 100644 --- a/src/modules/04_registry/components/Education.vue +++ b/src/modules/04_registry/components/Education.vue @@ -137,198 +137,262 @@
- - - - - - - - - - +
+ + + + + + +
+ +
+ + + + + + +
+
- - - - - - - - - - +
+ + + + + + +
+
+ + + + + + +
+ @@ -615,6 +679,17 @@ import config from "@/app.config"; import type { EduOps } from "@/modules/04_registry/interface/index/Main"; import type { QTableProps } from "quasar"; +const inputStartDate = ref(""); +const inputEndDate = ref(""); +const inputStartDate2 = ref(""); +const inputEndDate2 = ref(""); +const finishDateInput = ref(""); + +const dayChecked = ref(false); +const dayEndChecked = ref(false); +const dayChecked2 = ref(false); +const dayEndChecked2 = ref(false); + const props = defineProps({ statusEdit: { type: Boolean, @@ -627,8 +702,16 @@ const store = useProfileDataStore(); const { profileData, changeProfileColumns } = store; const mixin = useCounterMixin(); -const { success, dateToISO, date2Thai, messageError, showLoader, hideLoader } = - mixin; +const { + success, + dateToISO, + date2Thai, + messageError, + showLoader, + hideLoader, + convertDate, + convertDateDisplay, +} = mixin; const route = useRoute(); const id = ref(""); const levelId = ref(); @@ -651,11 +734,11 @@ const durationYear = ref(0); const other = ref(); const fundName = ref(); const isDate = ref("true"); -const finishDate = ref(null); -const startDate = ref(new Date().getFullYear()); -const startDate2 = ref(new Date()); -const endDate = ref(new Date().getFullYear()); -const endDate2 = ref(new Date()); +const finishDate = ref(null); +const startDate = ref(new Date().getFullYear()); +const startDate2 = ref(new Date()); +const endDate = ref(new Date().getFullYear()); +const endDate2 = ref(new Date()); const minDate = ref(); const myForm = ref(); //form data input const edit = ref(false); //เช็คการกดปุ่มแก้ไขใน dialog @@ -1214,6 +1297,11 @@ const getData = () => { startDate.value = row.startDate; endDate.value = row.endDate; startDate2.value = row.startDate2; + inputStartDate.value = (Number(row.startDate) + 543).toLocaleString(); + inputEndDate.value = (Number(row.endDate) + 543).toLocaleString(); + inputStartDate2.value = convertDateDisplay(row.startDate2); + inputEndDate2.value = convertDateDisplay(row.endDate2); + finishDateInput.value = row.finishDate ? convertDateDisplay(row.finishDate):'-'; endDate2.value = row.endDate2; id.value = row.id; }; @@ -1256,10 +1344,34 @@ const clickAdd = async () => { const clickSave = async () => { myForm.value.validate().then(async (result: boolean) => { if (result) { - if (modalEdit.value) { - await editData(); + if (isDate.value == "false") { + dayChecked2.value = false; + dayEndChecked2.value = false; + if (inputStartDate.value == "") { + dayChecked.value = true; + } else if (inputEndDate.value === "") { + dayEndChecked.value = true; + } else { + if (modalEdit.value) { + await editData(); + } else { + await saveData(); + } + } } else { - await saveData(); + dayChecked.value = false; + dayEndChecked.value = false; + if (inputStartDate2.value === "") { + dayChecked2.value = true; + } else if (inputEndDate2.value === "") { + dayEndChecked2.value = true; + } else { + if (modalEdit.value) { + await editData(); + } else { + await saveData(); + } + } } } }); @@ -1293,14 +1405,14 @@ const saveData = async () => { other: other.value, fundName: fundName.value, isDate: isDate.value == "true" ? true : false, - finishDate: finishDate.value ? dateToISO(finishDate.value) : null, + finishDate: finishDate.value ? dateToISO(finishDate.value as Date) : null, startDate: isDate.value == "true" - ? dateToISO(startDate2.value) + ? dateToISO(startDate2.value as Date) : new Date(`${startDate.value}-01-01`), endDate: isDate.value == "true" - ? dateToISO(endDate2.value) + ? dateToISO(endDate2.value as Date) : new Date(`${endDate.value}-01-01`), }) .then((res) => { @@ -1343,14 +1455,14 @@ const editData = async () => { other: other.value, fundName: fundName.value, isDate: isDate.value == "true" ? true : false, - finishDate: finishDate.value ? dateToISO(finishDate.value) : null, + finishDate: finishDate.value ? dateToISO(finishDate.value as Date) : null, startDate: isDate.value == "true" - ? dateToISO(startDate2.value) + ? dateToISO(startDate2.value as Date) : new Date(`${startDate.value}-01-01`), endDate: isDate.value == "true" - ? dateToISO(endDate2.value) + ? dateToISO(endDate2.value as Date) : new Date(`${endDate.value}-01-01`), }) .then((res) => { @@ -1424,6 +1536,7 @@ const clickClose = async () => { * @param _props ค่า props ใน row ที่เลือก */ const selectData = async (_props: DataProps) => { + console.log(_props) modalEdit.value = true; modal.value = true; edit.value = false; @@ -1447,6 +1560,11 @@ const selectData = async (_props: DataProps) => { startDate2.value = _props.row.startDate2; endDate2.value = _props.row.endDate2; id.value = _props.row.id; + inputStartDate.value = (Number(_props.row.startDate) + 543).toLocaleString(); + inputEndDate.value = (Number(_props.row.endDate) + 543).toLocaleString(); + inputStartDate2.value = convertDateDisplay(_props.row.startDate2); + inputEndDate2.value = convertDateDisplay(_props.row.endDate2); + finishDateInput.value = _props.row.finishDate ? convertDateDisplay(_props.row.finishDate):'-'; await checkRowPage(); }; @@ -1474,6 +1592,11 @@ const addData = () => { endDate.value = new Date().getFullYear(); startDate2.value = new Date(); endDate2.value = new Date(); + inputStartDate2.value = ""; + inputEndDate2.value = ""; + inputStartDate.value = ""; + inputEndDate.value = ""; + finishDateInput.value = ""; }; /** @@ -1575,6 +1698,68 @@ const getClass = (val: boolean) => { "full-width cursor-pointer": !val, }; }; + +watch( + () => inputStartDate2.value, + (value: string) => { + if (value.length === 10) { + const dateVal = convertDate(value); + if (dateVal.isValid) { + dayChecked2.value = false; + startDate2.value = dateVal.value; + } else { + dayChecked.value = true; + inputStartDate2.value = ""; + } + } + } +); +watch( + () => inputEndDate2.value, + (value: string) => { + if (value.length === 10) { + const dateVal = convertDate(value); + if (dateVal.isValid) { + dayEndChecked2.value = false; + endDate2.value = dateVal.value; + } else { + dayEndChecked.value = true; + inputEndDate2.value = ""; + } + } + } +); +watch( + () => inputStartDate.value, + (value: string) => { + if (value.length === 4) { + const dateVal = Number(value) - 543; + dayChecked.value = false; + startDate.value = dateVal; + } + } +); +watch( + () => inputEndDate.value, + (value: string) => { + if (value.length === 4) { + const dateVal = Number(value) - 543; + dayEndChecked.value = false; + endDate.value = dateVal; + } + } +); + +watch( + () => finishDateInput.value, + (value: string) => { + if (value.length === 10) { + const dateVal = convertDate(value); + finishDate.value = dateVal.value; + + } + } +);