diff --git a/src/modules/04_registry/components/Assessment.vue b/src/modules/04_registry/components/Assessment.vue index c93364503..5d42ad985 100644 --- a/src/modules/04_registry/components/Assessment.vue +++ b/src/modules/04_registry/components/Assessment.vue @@ -366,7 +366,9 @@ const tittleHistory = ref("ประวัติแก้ไขผลก const filterHistory = ref(""); //search data table history const modalHistory = ref(false); //modal ประวัติการแก้ไขข้อมูล const checkValidate = ref(false); //validate data ผ่านหรือไม่ -const profileId = ref(route.params.id.toString()); +const profileId = ref( + route.params.id ? route.params.id.toString() : "" +); const rows = ref([]); const filter = ref(""); //search data table const visibleColumns = ref([]); @@ -595,34 +597,36 @@ onMounted(async () => { }); const fetchData = async () => { - loaderPage(true); - await http - .get(config.API.profileAssessmentId(profileId.value)) - .then((res) => { - let data = res.data.result; - rows.value = []; - data.map((e: ResponseObject) => { - rows.value.push({ - id: e.id, - name: e.name, - point1Total: e.point1Total, - point1: e.point1, - point2Total: e.point2Total, - point2: e.point2, - pointSumTotal: e.pointSumTotal, - pointSum: e.pointSum, - date: new Date(e.date), - createdAt: new Date(e.createdAt), - createdFullName: e.createdFullName, + if (profileId.value) { + loaderPage(true); + await http + .get(config.API.profileAssessmentId(profileId.value)) + .then((res) => { + let data = res.data.result; + rows.value = []; + data.map((e: ResponseObject) => { + rows.value.push({ + id: e.id, + name: e.name, + point1Total: e.point1Total, + point1: e.point1, + point2Total: e.point2Total, + point2: e.point2, + pointSumTotal: e.pointSumTotal, + pointSum: e.pointSum, + date: new Date(e.date), + createdAt: new Date(e.createdAt), + createdFullName: e.createdFullName, + }); }); + }) + .catch((e) => { + messageError($q, e); + }) + .finally(() => { + loaderPage(false); }); - }) - .catch((e) => { - messageError($q, e); - }) - .finally(() => { - loaderPage(false); - }); + } }; /** @@ -712,29 +716,31 @@ const clickSave = async () => { * บันทึกเพิ่มข้อมูล */ const saveData = async () => { - loaderPage(true); - await http - .post(config.API.profileAssessmentId(profileId.value), { - id: id.value, - name: name.value, - point1Total: point1Total.value, - point1: point1.value, - point2Total: point2Total.value, - point2: point2.value, - pointSumTotal: pointSumTotal.value, - pointSum: pointSum.value, - date: dateToISO(date.value), - }) - .then((res) => { - success($q, "บันทึกข้อมูลสำเร็จ"); - modal.value = false; - }) - .catch((e) => { - messageError($q, e); - }) - .finally(async () => { - await fetchData(); - }); + if (profileId.value) { + loaderPage(true); + await http + .post(config.API.profileAssessmentId(profileId.value), { + id: id.value, + name: name.value, + point1Total: point1Total.value, + point1: point1.value, + point2Total: point2Total.value, + point2: point2.value, + pointSumTotal: pointSumTotal.value, + pointSum: pointSum.value, + date: dateToISO(date.value), + }) + .then((res) => { + success($q, "บันทึกข้อมูลสำเร็จ"); + modal.value = false; + }) + .catch((e) => { + messageError($q, e); + }) + .finally(async () => { + await fetchData(); + }); + } }; /** diff --git a/src/modules/04_registry/components/Coin.vue b/src/modules/04_registry/components/Coin.vue index 122508ea6..a478b85b7 100644 --- a/src/modules/04_registry/components/Coin.vue +++ b/src/modules/04_registry/components/Coin.vue @@ -319,7 +319,9 @@ const tittleHistory = ref("ประวัติแก้ไขประ const filterHistory = ref(""); //search data table history const modalHistory = ref(false); //modal ประวัติการแก้ไขข้อมูล const checkValidate = ref(false); //validate data ผ่านหรือไม่ -const profileId = ref(route.params.id.toString()); +const profileId = ref( + route.params.id ? route.params.id.toString() : "" +); const rows = ref([]); const filter = ref(""); //search data table const visibleColumns = ref([]); @@ -487,32 +489,34 @@ onMounted(async () => { }); const fetchData = async () => { - loaderPage(true); - await http - .get(config.API.profileHonorId(profileId.value)) - .then((res) => { - let data = res.data.result; - rows.value = []; - data.map((e: ResponseObject) => { - rows.value.push({ - id: e.id, - issuer: e.issuer, - detail: e.detail, - issueDate: new Date(e.issueDate), - refCommandNo: e.refCommandNo, - refCommandDate: - e.refCommandDate == null ? null : new Date(e.refCommandDate), - createdAt: new Date(e.createdAt), - createdFullName: e.createdFullName, + if (profileId.value) { + loaderPage(true); + await http + .get(config.API.profileHonorId(profileId.value)) + .then((res) => { + let data = res.data.result; + rows.value = []; + data.map((e: ResponseObject) => { + rows.value.push({ + id: e.id, + issuer: e.issuer, + detail: e.detail, + issueDate: new Date(e.issueDate), + refCommandNo: e.refCommandNo, + refCommandDate: + e.refCommandDate == null ? null : new Date(e.refCommandDate), + createdAt: new Date(e.createdAt), + createdFullName: e.createdFullName, + }); }); + }) + .catch((e) => { + messageError($q, e); + }) + .finally(() => { + loaderPage(false); }); - }) - .catch((e) => { - messageError($q, e); - }) - .finally(() => { - loaderPage(false); - }); + } }; /** @@ -599,27 +603,29 @@ const clickSave = async () => { * บันทึกเพิ่มข้อมูล */ const saveData = async () => { - loaderPage(true); - await http - .post(config.API.profileHonorId(profileId.value), { - id: id.value, - issuer: issuer.value, - detail: detail.value, - issueDate: dateToISO(issueDate.value), - refCommandNo: refCommandNo.value, - refCommandDate: - refCommandDate.value == null ? null : dateToISO(refCommandDate.value), - }) - .then((res) => { - success($q, "บันทึกข้อมูลสำเร็จ"); - modal.value = false; - }) - .catch((e) => { - messageError($q, e); - }) - .finally(async () => { - await fetchData(); - }); + if (profileId.value) { + loaderPage(true); + await http + .post(config.API.profileHonorId(profileId.value), { + id: id.value, + issuer: issuer.value, + detail: detail.value, + issueDate: dateToISO(issueDate.value), + refCommandNo: refCommandNo.value, + refCommandDate: + refCommandDate.value == null ? null : dateToISO(refCommandDate.value), + }) + .then((res) => { + success($q, "บันทึกข้อมูลสำเร็จ"); + modal.value = false; + }) + .catch((e) => { + messageError($q, e); + }) + .finally(async () => { + await fetchData(); + }); + } }; /** diff --git a/src/modules/04_registry/components/Discipline.vue b/src/modules/04_registry/components/Discipline.vue index 2299c82ab..ae43a8383 100644 --- a/src/modules/04_registry/components/Discipline.vue +++ b/src/modules/04_registry/components/Discipline.vue @@ -381,7 +381,9 @@ const tittleHistory = ref("ประวัติแก้ไขวิน const filterHistory = ref(""); //search data table history const modalHistory = ref(false); //modal ประวัติการแก้ไขข้อมูล const checkValidate = ref(false); //validate data ผ่านหรือไม่ -const profileId = ref(route.params.id.toString()); +const profileId = ref( + route.params.id ? route.params.id.toString() : "" +); const rows = ref([]); const filter = ref(""); //search data table const visibleColumns = ref([]); @@ -587,33 +589,35 @@ const filterSelector = (val: string, update: Function, refData: string) => { }; const fetchData = async () => { - loaderPage(true); - await http - .get(config.API.profileDisId(profileId.value)) - .then((res) => { - let data = res.data.result; - rows.value = []; - data.map((e: ResponseObject) => { - rows.value.push({ - id: e.id, - level: e.level, - detail: e.detail, - unStigma: e.unStigma, - refCommandNo: e.refCommandNo, - refCommandDate: - e.refCommandDate == null ? null : new Date(e.refCommandDate), - date: new Date(e.date), - createdFullName: e.createdFullName, - createdAt: new Date(e.createdAt), + if (profileId.value) { + loaderPage(true); + await http + .get(config.API.profileDisId(profileId.value)) + .then((res) => { + let data = res.data.result; + rows.value = []; + data.map((e: ResponseObject) => { + rows.value.push({ + id: e.id, + level: e.level, + detail: e.detail, + unStigma: e.unStigma, + refCommandNo: e.refCommandNo, + refCommandDate: + e.refCommandDate == null ? null : new Date(e.refCommandDate), + date: new Date(e.date), + createdFullName: e.createdFullName, + createdAt: new Date(e.createdAt), + }); }); + }) + .catch((e) => { + messageError($q, e); + }) + .finally(() => { + loaderPage(false); }); - }) - .catch((e) => { - messageError($q, e); - }) - .finally(() => { - loaderPage(false); - }); + } }; /** @@ -701,28 +705,30 @@ const clickSave = async () => { * บันทึกเพิ่มข้อมูล */ const saveData = async () => { - loaderPage(true); - await http - .post(config.API.profileDisId(profileId.value), { - id: id.value, - level: level.value, - detail: detail.value, - unStigma: unStigma.value, - refCommandNo: refCommandNo.value, - refCommandDate: - refCommandDate.value == null ? null : dateToISO(refCommandDate.value), - date: dateToISO(date.value), - }) - .then((res) => { - success($q, "บันทึกข้อมูลสำเร็จ"); - modal.value = false; - }) - .catch((e) => { - messageError($q, e); - }) - .finally(async () => { - await fetchData(); - }); + if (profileId.value) { + loaderPage(true); + await http + .post(config.API.profileDisId(profileId.value), { + id: id.value, + level: level.value, + detail: detail.value, + unStigma: unStigma.value, + refCommandNo: refCommandNo.value, + refCommandDate: + refCommandDate.value == null ? null : dateToISO(refCommandDate.value), + date: dateToISO(date.value), + }) + .then((res) => { + success($q, "บันทึกข้อมูลสำเร็จ"); + modal.value = false; + }) + .catch((e) => { + messageError($q, e); + }) + .finally(async () => { + await fetchData(); + }); + } }; /** diff --git a/src/modules/04_registry/components/Document.vue b/src/modules/04_registry/components/Document.vue index f539f31d9..4b6bfe21b 100644 --- a/src/modules/04_registry/components/Document.vue +++ b/src/modules/04_registry/components/Document.vue @@ -162,7 +162,9 @@ const $q = useQuasar(); // show dialog const mixin = useCounterMixin(); const route = useRoute(); const { success, messageError } = mixin; -const profileId = ref(route.params.id.toString()); +const profileId = ref( + route.params.id ? route.params.id.toString() : "" +); const edit = ref(false); const uploader = ref(); const files = ref([]); @@ -174,19 +176,21 @@ onMounted(async () => { }); const getData = async () => { - loaderPage(true); - await http - .get(config.API.profilePaperId(profileId.value)) - .then((res) => { - const data = res.data.result; - files.value = data; - }) - .catch((e) => { - messageError($q, e); - }) - .finally(() => { - loaderPage(false); - }); + if (profileId.value) { + loaderPage(true); + await http + .get(config.API.profilePaperId(profileId.value)) + .then((res) => { + const data = res.data.result; + files.value = data; + }) + .catch((e) => { + messageError($q, e); + }) + .finally(() => { + loaderPage(false); + }); + } }; const deleteData = async (id: string) => { @@ -205,39 +209,41 @@ const deleteData = async (id: string) => { }; const uploadData = async () => { - if (file.value.length > 0) { - const blob = file.value.slice(0, file.value[0].size); - const newFile = new File(blob, name.value, { - type: file.value[0].type, - }); - const formData = new FormData(); - formData.append("avatar", newFile); - formData.append("moss", "newFile"); - console.log(formData); - loaderPage(true); - await http - .post(config.API.profilePaperId(profileId.value), formData) - .then((res) => { - const data = res.data.result; - success($q, "บันทึกข้อมูลสำเร็จ"); - }) - .catch((e) => { - messageError($q, e); - }) - .finally(async () => { - uploader.value.reset(); - name.value = ""; - edit.value = false; - emit("update:statusEdit", false); - await getData(); + if (profileId.value) { + if (file.value.length > 0) { + const blob = file.value.slice(0, file.value[0].size); + const newFile = new File(blob, name.value, { + type: file.value[0].type, }); - } else { - // modalError( - // $q, - // "ไม่สามารถอัปโหลดไฟล์ได้", - // "กรุณาเลือกไฟล์ที่ต้องการอัปโหลด" - // ); - getData(); + const formData = new FormData(); + formData.append("avatar", newFile); + formData.append("moss", "newFile"); + console.log(formData); + loaderPage(true); + await http + .post(config.API.profilePaperId(profileId.value), formData) + .then((res) => { + const data = res.data.result; + success($q, "บันทึกข้อมูลสำเร็จ"); + }) + .catch((e) => { + messageError($q, e); + }) + .finally(async () => { + uploader.value.reset(); + name.value = ""; + edit.value = false; + emit("update:statusEdit", false); + await getData(); + }); + } else { + // modalError( + // $q, + // "ไม่สามารถอัปโหลดไฟล์ได้", + // "กรุณาเลือกไฟล์ที่ต้องการอัปโหลด" + // ); + getData(); + } } }; diff --git a/src/modules/04_registry/components/Education.vue b/src/modules/04_registry/components/Education.vue index ed081db6f..b5956d931 100644 --- a/src/modules/04_registry/components/Education.vue +++ b/src/modules/04_registry/components/Education.vue @@ -655,7 +655,9 @@ const tittleHistory = ref("ประวัติแก้ไขประ const filterHistory = ref(""); //search data table history const modalHistory = ref(false); //modal ประวัติการแก้ไขข้อมูล const checkValidate = ref(false); //validate data ผ่านหรือไม่ -const profileId = ref(route.params.id.toString()); +const profileId = ref( + route.params.id ? route.params.id.toString() : "" +); const rows = ref([]); const filter = ref(""); //search data table const visibleColumns = ref([]); @@ -1110,45 +1112,47 @@ const filterSelector = (val: any, update: Function, refData: string) => { }; const fetchData = async () => { - loaderPage(true); - await http - .get(config.API.profileEduId(profileId.value)) - .then((res) => { - let data = res.data.result; - rows.value = []; - data.map((e: ResponseObject) => { - rows.value.push({ - id: e.id, - level: e.educationLevel, - levelId: e.educationLevelId, - positionPath: e.positionPath, - isEducation: e.isEducation, - institute: e.institute, - degree: e.degree, - field: e.field, - gpa: e.gpa, - country: e.country, - duration: e.duration, - durationYear: e.durationYear, - other: e.other, - fundName: e.fundName, - isDate: e.isDate.toString(), - finishDate: new Date(e.finishDate), - startDate: new Date(e.startDate).getFullYear(), - endDate: new Date(e.endDate).getFullYear(), - startDate2: new Date(e.startDate), - endDate2: new Date(e.endDate), - createdFullName: e.createdFullName, - createdAt: new Date(e.createdAt), + if (profileId.value) { + loaderPage(true); + await http + .get(config.API.profileEduId(profileId.value)) + .then((res) => { + let data = res.data.result; + rows.value = []; + data.map((e: ResponseObject) => { + rows.value.push({ + id: e.id, + level: e.educationLevel, + levelId: e.educationLevelId, + positionPath: e.positionPath, + isEducation: e.isEducation, + institute: e.institute, + degree: e.degree, + field: e.field, + gpa: e.gpa, + country: e.country, + duration: e.duration, + durationYear: e.durationYear, + other: e.other, + fundName: e.fundName, + isDate: e.isDate.toString(), + finishDate: new Date(e.finishDate), + startDate: new Date(e.startDate).getFullYear(), + endDate: new Date(e.endDate).getFullYear(), + startDate2: new Date(e.startDate), + endDate2: new Date(e.endDate), + createdFullName: e.createdFullName, + createdAt: new Date(e.createdAt), + }); }); + }) + .catch((e) => { + messageError($q, e); + }) + .finally(() => { + loaderPage(false); }); - }) - .catch((e) => { - messageError($q, e); - }) - .finally(() => { - loaderPage(false); - }); + } }; /** @@ -1253,43 +1257,45 @@ const saveData = async () => { // const filterPositionPath = OpsFilter.value.positionPathOptions.filter( // (r: any) => r.id == isEducation.value // ); - loaderPage(true); - await http - .post(config.API.profileEduId(profileId.value), { - id: id.value, - // educationLevel: filter[0].name, - educationLevelId: levelId.value, - isEducation: isEducation.value, - institute: institute.value, - degree: degree.value, - field: field.value, - gpa: gpa.value, - country: country.value, - duration: duration.value, - durationYear: durationYear.value, - other: other.value, - fundName: fundName.value, - isDate: isDate.value == "true" ? true : false, - finishDate: dateToISO(finishDate.value), - startDate: - isDate.value == "true" - ? dateToISO(startDate2.value) - : new Date(`${startDate.value}-01-01`), - endDate: - isDate.value == "true" - ? dateToISO(endDate2.value) - : new Date(`${endDate.value}-01-01`), - }) - .then((res) => { - success($q, "บันทึกข้อมูลสำเร็จ"); - modal.value = false; - }) - .catch((e) => { - messageError($q, e); - }) - .finally(async () => { - await fetchData(); - }); + if (profileId.value) { + loaderPage(true); + await http + .post(config.API.profileEduId(profileId.value), { + id: id.value, + // educationLevel: filter[0].name, + educationLevelId: levelId.value, + isEducation: isEducation.value, + institute: institute.value, + degree: degree.value, + field: field.value, + gpa: gpa.value, + country: country.value, + duration: duration.value, + durationYear: durationYear.value, + other: other.value, + fundName: fundName.value, + isDate: isDate.value == "true" ? true : false, + finishDate: dateToISO(finishDate.value), + startDate: + isDate.value == "true" + ? dateToISO(startDate2.value) + : new Date(`${startDate.value}-01-01`), + endDate: + isDate.value == "true" + ? dateToISO(endDate2.value) + : new Date(`${endDate.value}-01-01`), + }) + .then((res) => { + success($q, "บันทึกข้อมูลสำเร็จ"); + modal.value = false; + }) + .catch((e) => { + messageError($q, e); + }) + .finally(async () => { + await fetchData(); + }); + } }; /** diff --git a/src/modules/04_registry/components/Information/Address.vue b/src/modules/04_registry/components/Information/Address.vue index 64f63ecf4..8b8ffbf67 100644 --- a/src/modules/04_registry/components/Information/Address.vue +++ b/src/modules/04_registry/components/Information/Address.vue @@ -5,11 +5,12 @@ header="ข้อมูลที่อยู่" icon="mdi-map-marker" :save="saveData" - :history="true" + :history="!statusAdd()" :changeBtn="changeBtn" :disable="statusEdit" :cancel="refreshData" :historyClick="clickHistory" + :addEmployee="statusAdd()" />
@@ -311,6 +312,10 @@ const props = defineProps({ type: Boolean, required: true, }, + statusAdd: { + type: Boolean, + default: false, + }, }); const emit = defineEmits(["update:statusEdit"]); @@ -507,8 +512,28 @@ const visibleColumnsHistory = ref([ onMounted(async () => { await getNewData(); emit("update:statusEdit", false); + defaultAdd(); }); +const statusAdd = () => props.statusAdd; + +const defaultAdd = () => { + if (props.statusAdd) { + edit.value = props.statusAdd; + addressData.value = { + address: null, + provinceId: null, + districtId: null, + subdistrictId: null, + addressC: null, + provinceIdC: null, + districtIdC: null, + subdistrictIdC: null, + same: "0", + }; + } +}; + const filterSelector = (val: any, update: Function, refData: string) => { switch (refData) { case "provinceOps": @@ -606,27 +631,29 @@ const getNewData = async () => { }; const fetchData = async () => { - loaderPage(true); - await http - .get(config.API.profileAdrsId(route.params.id.toString())) - .then((res) => { - const data: ResponseObject = res.data.result; - addressData.value.address = data.registrationAddress; - addressData.value.addressC = data.currentAddress; - addressData.value.districtId = data.registrationDistrictId; - addressData.value.districtIdC = data.currentDistrictId; - addressData.value.provinceId = data.registrationProvinceId; - addressData.value.provinceIdC = data.currentProvinceId; - addressData.value.subdistrictId = data.registrationSubDistrictId; - addressData.value.subdistrictIdC = data.currentSubDistrictId; - addressData.value.same = data.registrationSame ? "1" : "0"; - }) - .catch((e) => { - messageError($q, e); - }) - .finally(() => { - loaderPage(false); - }); + if (route.params.id) { + loaderPage(true); + await http + .get(config.API.profileAdrsId(route.params.id.toString())) + .then((res) => { + const data: ResponseObject = res.data.result; + addressData.value.address = data.registrationAddress; + addressData.value.addressC = data.currentAddress; + addressData.value.districtId = data.registrationDistrictId; + addressData.value.districtIdC = data.currentDistrictId; + addressData.value.provinceId = data.registrationProvinceId; + addressData.value.provinceIdC = data.currentProvinceId; + addressData.value.subdistrictId = data.registrationSubDistrictId; + addressData.value.subdistrictIdC = data.currentSubDistrictId; + addressData.value.same = data.registrationSame ? "1" : "0"; + }) + .catch((e) => { + messageError($q, e); + }) + .finally(() => { + loaderPage(false); + }); + } }; const editData = async () => { @@ -673,10 +700,32 @@ const editData = async () => { }); }; +const addData = async () => { + // loaderPage(true); + // await http + // .put(config.API.profileInforId(route.params.id.toString()), body) + // .then((res) => { + // success($q, "บันทึกข้อมูลสำเร็จ"); + // }) + // .catch((e) => { + // messageError($q, e); + // }) + // .finally(async () => { + // edit.value = false; + // emit("update:statusEdit", false); + // await fetchData(); + // await changeBirth(informaData.value.birthDate ?? new Date()); + // }); +}; + const saveData = async () => { await myform.value.validate().then(async (success: boolean) => { if (success) { - await editData(); + if (props.statusAdd) { + await addData(); + } else { + await editData(); + } } else { } }); diff --git a/src/modules/04_registry/components/Information/Certicate.vue b/src/modules/04_registry/components/Information/Certicate.vue index 721bf17c0..d08e8c3b2 100644 --- a/src/modules/04_registry/components/Information/Certicate.vue +++ b/src/modules/04_registry/components/Information/Certicate.vue @@ -316,7 +316,9 @@ const tittleHistory = ref("ประวัติแก้ไขใบอ const filterHistory = ref(""); //search data table history const modalHistory = ref(false); //modal ประวัติการแก้ไขข้อมูล const checkValidate = ref(false); //validate data ผ่านหรือไม่ -const profileId = ref(route.params.id.toString()); +const profileId = ref( + route.params.id ? route.params.id.toString() : "" +); const rows = ref([]); const filter = ref(""); //search data table const visibleColumns = ref([]); @@ -484,31 +486,33 @@ onMounted(async () => { }); const fetchData = async () => { - loaderPage(true); - await http - .get(config.API.profileCertId(profileId.value)) - .then((res) => { - let data = res.data.result; - rows.value = []; - data.map((e: ResponseObject) => { - rows.value.push({ - id: e.id, - certificateNo: e.certificateNo, - issuer: e.issuer, - issueDate: new Date(e.issueDate), - expireDate: new Date(e.expireDate), - certificateType: e.certificateType, - createdFullName: e.createdFullName, - createdAt: new Date(e.createdAt), + if (profileId.value) { + loaderPage(true); + await http + .get(config.API.profileCertId(profileId.value)) + .then((res) => { + let data = res.data.result; + rows.value = []; + data.map((e: ResponseObject) => { + rows.value.push({ + id: e.id, + certificateNo: e.certificateNo, + issuer: e.issuer, + issueDate: new Date(e.issueDate), + expireDate: new Date(e.expireDate), + certificateType: e.certificateType, + createdFullName: e.createdFullName, + createdAt: new Date(e.createdAt), + }); }); + }) + .catch((e) => { + messageError($q, e); + }) + .finally(() => { + loaderPage(false); }); - }) - .catch((e) => { - messageError($q, e); - }) - .finally(() => { - loaderPage(false); - }); + } }; /** diff --git a/src/modules/04_registry/components/Information/Family.vue b/src/modules/04_registry/components/Information/Family.vue index 6c49531e0..8b9eaf90c 100644 --- a/src/modules/04_registry/components/Information/Family.vue +++ b/src/modules/04_registry/components/Information/Family.vue @@ -5,11 +5,12 @@ header="ข้อมูลครอบครัว" icon="mdi-account-group" :save="saveData" - :history="true" + :history="!statusAdd()" :changeBtn="changeBtn" :disable="statusEdit" :cancel="refreshData" :historyClick="historyData" + :addEmployee="statusAdd()" />
@@ -1114,6 +1115,10 @@ const props = defineProps({ type: Function, default: () => console.log("not function"), }, + statusAdd: { + type: Boolean, + default: false, + }, }); const emit = defineEmits(["update:statusEdit"]); @@ -1171,8 +1176,43 @@ onMounted(async () => { await fetchPrefix(); await fetchData(); emit("update:statusEdit", false); + defaultAdd(); }); +const statusAdd = () => props.statusAdd; + +const defaultAdd = () => { + if (props.statusAdd) { + edit.value = props.statusAdd; + familyData.value = { + prefixC: null, + prefixIdC: null, + firstnameC: null, + lastnameC: null, + lastnameCOld: null, + occupationC: null, + citizenIdC: null, + liveC: null, + prefixM: null, + prefixIdM: null, + firstnameM: null, + lastnameM: null, + occupationM: null, + citizenIdM: null, + liveM: null, + prefixF: null, + prefixIdF: null, + firstnameF: null, + lastnameF: null, + occupationF: null, + citizenIdF: null, + liveF: null, + same: "0", + childrens: [], + }; + } +}; + const historyData = async () => { await fetchHistory(); }; @@ -1299,61 +1339,63 @@ const fetchHistory = async () => { }; const fetchData = async () => { - loaderPage(true); - await http - .get(config.API.profileFamiId(route.params.id.toString())) - .then((res) => { - const data: ResponseObject = res.data.result; - familyData.value.prefixC = ""; - familyData.value.prefixIdC = data.couplePrefixId; - familyData.value.firstnameC = data.coupleFirstName; - familyData.value.lastnameC = data.coupleLastName; - familyData.value.lastnameCOld = data.coupleLastNameOld; - familyData.value.occupationC = data.coupleCareer; - familyData.value.liveC = data.coupleLive ? "1" : "0"; - familyData.value.citizenIdC = data.coupleCitizenId; + if (route.params.id) { + loaderPage(true); + await http + .get(config.API.profileFamiId(route.params.id.toString())) + .then((res) => { + const data: ResponseObject = res.data.result; + familyData.value.prefixC = ""; + familyData.value.prefixIdC = data.couplePrefixId; + familyData.value.firstnameC = data.coupleFirstName; + familyData.value.lastnameC = data.coupleLastName; + familyData.value.lastnameCOld = data.coupleLastNameOld; + familyData.value.occupationC = data.coupleCareer; + familyData.value.liveC = data.coupleLive ? "1" : "0"; + familyData.value.citizenIdC = data.coupleCitizenId; - familyData.value.prefixM = ""; - familyData.value.prefixIdM = data.fatherPrefixId; - familyData.value.firstnameM = data.fatherFirstName; - familyData.value.lastnameM = data.fatherLastName; - familyData.value.occupationM = data.fatherCareer; - familyData.value.liveM = data.fatherLive ? "1" : "0"; - familyData.value.citizenIdM = data.fatherCitizenId; + familyData.value.prefixM = ""; + familyData.value.prefixIdM = data.fatherPrefixId; + familyData.value.firstnameM = data.fatherFirstName; + familyData.value.lastnameM = data.fatherLastName; + familyData.value.occupationM = data.fatherCareer; + familyData.value.liveM = data.fatherLive ? "1" : "0"; + familyData.value.citizenIdM = data.fatherCitizenId; - familyData.value.prefixF = ""; - familyData.value.prefixIdF = data.motherPrefixId; - familyData.value.firstnameF = data.motherFirstName; - familyData.value.lastnameF = data.motherLastName; - familyData.value.occupationF = data.motherCareer; - familyData.value.liveF = data.motherLive ? "1" : "0"; - familyData.value.citizenIdF = data.motherCitizenId; - familyData.value.same = data.couple ? "1" : "0"; + familyData.value.prefixF = ""; + familyData.value.prefixIdF = data.motherPrefixId; + familyData.value.firstnameF = data.motherFirstName; + familyData.value.lastnameF = data.motherLastName; + familyData.value.occupationF = data.motherCareer; + familyData.value.liveF = data.motherLive ? "1" : "0"; + familyData.value.citizenIdF = data.motherCitizenId; + familyData.value.same = data.couple ? "1" : "0"; - if (data.childrens.length > 0) { - let dataChild: childrenFamily[] = []; - data.childrens.map((row: childrenFamily, index: number) => { - dataChild.push({ - id: `${index + 1}`, - childrenPrefixId: row.childrenPrefixId, - childrenFirstName: row.childrenFirstName, - childrenLastName: row.childrenLastName, - childrenCareer: row.childrenCareer, - childrenLive: row.childrenLive, - childrenCitizenId: row.childrenCitizenId, + if (data.childrens.length > 0) { + let dataChild: childrenFamily[] = []; + data.childrens.map((row: childrenFamily, index: number) => { + dataChild.push({ + id: `${index + 1}`, + childrenPrefixId: row.childrenPrefixId, + childrenFirstName: row.childrenFirstName, + childrenLastName: row.childrenLastName, + childrenCareer: row.childrenCareer, + childrenLive: row.childrenLive, + childrenCitizenId: row.childrenCitizenId, + }); }); - }); - familyData.value.childrens = dataChild; - } else { - familyData.value.childrens = []; - } - }) - .catch((e) => { - messageError($q, e); - }) - .finally(async () => { - loaderPage(false); - }); + familyData.value.childrens = dataChild; + } else { + familyData.value.childrens = []; + } + }) + .catch((e) => { + messageError($q, e); + }) + .finally(async () => { + loaderPage(false); + }); + } }; const editData = async () => { @@ -1398,10 +1440,32 @@ const editData = async () => { }); }; +const addData = async () => { + // loaderPage(true); + // await http + // .put(config.API.profileInforId(route.params.id.toString()), body) + // .then((res) => { + // success($q, "บันทึกข้อมูลสำเร็จ"); + // }) + // .catch((e) => { + // messageError($q, e); + // }) + // .finally(async () => { + // edit.value = false; + // emit("update:statusEdit", false); + // await fetchData(); + // await changeBirth(informaData.value.birthDate ?? new Date()); + // }); +}; + const saveData = async () => { await myform.value?.validate().then(async (success: boolean) => { if (success) { - await editData(); + if (props.statusAdd) { + await addData(); + } else { + await editData(); + } } else { } }); diff --git a/src/modules/04_registry/components/Information/Information.vue b/src/modules/04_registry/components/Information/Information.vue index ad6287718..ec7a1440b 100644 --- a/src/modules/04_registry/components/Information/Information.vue +++ b/src/modules/04_registry/components/Information/Information.vue @@ -5,11 +5,12 @@ header="ข้อมูลส่วนตัว" icon="mdi-account" :save="saveData" - :history="true" + :history="!statusAdd()" :changeBtn="changeBtn" :disable="statusEdit" :cancel="onCancel" :historyClick="clickHistory" + :addEmployee="statusAdd()" />
@@ -439,6 +440,10 @@ const props = defineProps({ type: Function, default: () => console.log("not function"), }, + statusAdd: { + type: Boolean, + default: false, + }, }); const emit = defineEmits(["update:statusEdit"]); @@ -693,8 +698,36 @@ onMounted(async () => { await fetchPerson(); await fetchData(); emit("update:statusEdit", false); + defaultAdd(); }); +const statusAdd = () => props.statusAdd; + +const defaultAdd = () => { + if (props.statusAdd) { + edit.value = props.statusAdd; + informaData.value = { + cardid: null, + age: null, + prefix: null, + prefixId: null, + firstname: null, + lastname: null, + birthDate: new Date(), + genderId: null, + bloodId: null, + nationality: null, + ethnicity: null, + statusId: null, + religionId: null, + tel: null, + employeeType: null, + employeeClass: null, + profileType: null, + }; + } +}; + const onCancel = async () => { if (myform.value != null) { myform.value.reset(); @@ -962,44 +995,49 @@ const calRetire = async (birth: Date) => { }; const fetchData = async () => { - loaderPage(true); - await http - .get(config.API.profileInforId(route.params.id.toString())) - .then(async (res: any) => { - const data: ResponseObject = res.data.result; - defaultCitizenData.value = data.citizenId; - informaData.value.cardid = data.citizenId; - informaData.value.prefix = ""; - informaData.value.prefixId = data.prefixId; - informaData.value.firstname = data.firstName; - informaData.value.lastname = data.lastName; - informaData.value.birthDate = new Date(data.birthDate); - informaData.value.genderId = data.genderId; - informaData.value.bloodId = data.bloodGroupId; - informaData.value.nationality = data.nationality; - informaData.value.ethnicity = data.race; - informaData.value.statusId = data.relationshipId; - informaData.value.religionId = data.religionId; - informaData.value.tel = data.telephoneNumber; - informaData.value.age = data.age; - informaData.value.employeeType = data.employeeType; - informaData.value.employeeClass = data.employeeClass; - informaData.value.profileType = data.profileType; - dateBefore.value = new Date(data.birthDate); - same.value = data.changeName == true ? "1" : "0"; - await calRetire(new Date(dateToISO(new Date(data.birthDate)))); - if (data.profileType == "officer" && columnsHistory.value.length >= 15) { - columnsHistory.value.splice(13, 1); - columnsHistory.value.splice(12, 1); - } - }) - .catch((e) => { - messageError($q, e); - }) - .finally(async () => { - // loaderPage(false); - await props.fetchDataProfile(); - }); + if (route.params.id) { + loaderPage(true); + await http + .get(config.API.profileInforId(route.params.id.toString())) + .then(async (res: any) => { + const data: ResponseObject = res.data.result; + defaultCitizenData.value = data.citizenId; + informaData.value.cardid = data.citizenId; + informaData.value.prefix = ""; + informaData.value.prefixId = data.prefixId; + informaData.value.firstname = data.firstName; + informaData.value.lastname = data.lastName; + informaData.value.birthDate = new Date(data.birthDate); + informaData.value.genderId = data.genderId; + informaData.value.bloodId = data.bloodGroupId; + informaData.value.nationality = data.nationality; + informaData.value.ethnicity = data.race; + informaData.value.statusId = data.relationshipId; + informaData.value.religionId = data.religionId; + informaData.value.tel = data.telephoneNumber; + informaData.value.age = data.age; + informaData.value.employeeType = data.employeeType; + informaData.value.employeeClass = data.employeeClass; + informaData.value.profileType = data.profileType; + dateBefore.value = new Date(data.birthDate); + same.value = data.changeName == true ? "1" : "0"; + await calRetire(new Date(dateToISO(new Date(data.birthDate)))); + if ( + data.profileType == "officer" && + columnsHistory.value.length >= 15 + ) { + columnsHistory.value.splice(13, 1); + columnsHistory.value.splice(12, 1); + } + }) + .catch((e) => { + messageError($q, e); + }) + .finally(async () => { + // loaderPage(false); + await props.fetchDataProfile(); + }); + } }; const editData = async () => { @@ -1040,11 +1078,33 @@ const editData = async () => { }); }; +const addData = async () => { + // loaderPage(true); + // await http + // .put(config.API.profileInforId(route.params.id.toString()), body) + // .then((res) => { + // success($q, "บันทึกข้อมูลสำเร็จ"); + // }) + // .catch((e) => { + // messageError($q, e); + // }) + // .finally(async () => { + // edit.value = false; + // emit("update:statusEdit", false); + // await fetchData(); + // await changeBirth(informaData.value.birthDate ?? new Date()); + // }); +}; + const saveData = async () => { if (myform.value != null) { await myform.value.validate().then(async (success: boolean) => { if (success) { - await editData(); + if (props.statusAdd) { + await addData(); + } else { + await editData(); + } } else { } }); diff --git a/src/modules/04_registry/components/Information/top.vue b/src/modules/04_registry/components/Information/top.vue index 2a8221cf9..416a8f049 100644 --- a/src/modules/04_registry/components/Information/top.vue +++ b/src/modules/04_registry/components/Information/top.vue @@ -43,7 +43,7 @@ size="12px" flat round - v-if="edit" + v-if="edit && !addEmployee" :color="!edit ? 'grey-7' : 'red'" @click="ClickCancel" icon="mdi-undo" @@ -157,6 +157,10 @@ const props = defineProps({ type: Function, default: () => console.log("not function"), }, + addEmployee: { + type: Boolean, + defualt: false, + }, }); const emit = defineEmits(["update:edit"]); diff --git a/src/modules/04_registry/components/Insignia.vue b/src/modules/04_registry/components/Insignia.vue index b3ebf22ec..fb97d8513 100644 --- a/src/modules/04_registry/components/Insignia.vue +++ b/src/modules/04_registry/components/Insignia.vue @@ -527,7 +527,9 @@ const tittleHistory = ref("ประวัติแก้ไขเคร const filterHistory = ref(""); //search data table history const modalHistory = ref(false); //modal ประวัติการแก้ไขข้อมูล const checkValidate = ref(false); //validate data ผ่านหรือไม่ -const profileId = ref(route.params.id.toString()); +const profileId = ref( + route.params.id ? route.params.id.toString() : "" +); const rows = ref([]); const filter = ref(""); //search data table const visibleColumns = ref([]); @@ -937,41 +939,43 @@ const fetchInsignia = async () => { }; const fetchData = async () => { - loaderPage(true); - await http - .get(config.API.profileInsignId(profileId.value)) - .then((res) => { - let data = res.data.result; - rows.value = []; - data.map((e: ResponseObject) => { - rows.value.push({ - id: e.id, - insignia: e.insignia, - insigniaId: e.insigniaId, - insigniaType: e.insigniaType, - year: e.year, - no: e.no, - issue: e.issue, - volumeNo: e.volumeNo, - volume: e.volume, - section: e.section, - page: e.page, - receiveDate: new Date(e.receiveDate), - dateAnnounce: new Date(e.dateAnnounce), - refCommandNo: e.refCommandNo, - refCommandDate: - e.refCommandDate == null ? null : new Date(e.refCommandDate), - createdFullName: e.createdFullName, - createdAt: new Date(e.createdAt), + if (profileId.value) { + loaderPage(true); + await http + .get(config.API.profileInsignId(profileId.value)) + .then((res) => { + let data = res.data.result; + rows.value = []; + data.map((e: ResponseObject) => { + rows.value.push({ + id: e.id, + insignia: e.insignia, + insigniaId: e.insigniaId, + insigniaType: e.insigniaType, + year: e.year, + no: e.no, + issue: e.issue, + volumeNo: e.volumeNo, + volume: e.volume, + section: e.section, + page: e.page, + receiveDate: new Date(e.receiveDate), + dateAnnounce: new Date(e.dateAnnounce), + refCommandNo: e.refCommandNo, + refCommandDate: + e.refCommandDate == null ? null : new Date(e.refCommandDate), + createdFullName: e.createdFullName, + createdAt: new Date(e.createdAt), + }); }); + }) + .catch((e) => { + messageError($q, e); + }) + .finally(() => { + loaderPage(false); }); - }) - .catch((e) => { - messageError($q, e); - }) - .finally(() => { - loaderPage(false); - }); + } }; /** @@ -1066,35 +1070,37 @@ const clickSave = async () => { * บันทึกเพิ่มข้อมูล */ const saveData = async () => { - loaderPage(true); - await http - .post(config.API.profileInsignId(profileId.value), { - id: id.value, - insigniaId: insigniaId.value, - insigniaType: insigniaType.value, - year: year.value, - no: no.value, - issue: issue.value, - volumeNo: volumeNo.value, - volume: volume.value, - section: section.value, - page: page.value, - receiveDate: dateToISO(receiveDate.value), - dateAnnounce: dateToISO(dateAnnounce.value), - refCommandNo: refCommandNo.value, - refCommandDate: - refCommandDate.value == null ? null : dateToISO(refCommandDate.value), - }) - .then((res) => { - success($q, "บันทึกข้อมูลสำเร็จ"); - modal.value = false; - }) - .catch((e) => { - messageError($q, e); - }) - .finally(async () => { - await fetchData(); - }); + if (profileId.value) { + loaderPage(true); + await http + .post(config.API.profileInsignId(profileId.value), { + id: id.value, + insigniaId: insigniaId.value, + insigniaType: insigniaType.value, + year: year.value, + no: no.value, + issue: issue.value, + volumeNo: volumeNo.value, + volume: volume.value, + section: section.value, + page: page.value, + receiveDate: dateToISO(receiveDate.value), + dateAnnounce: dateToISO(dateAnnounce.value), + refCommandNo: refCommandNo.value, + refCommandDate: + refCommandDate.value == null ? null : dateToISO(refCommandDate.value), + }) + .then((res) => { + success($q, "บันทึกข้อมูลสำเร็จ"); + modal.value = false; + }) + .catch((e) => { + messageError($q, e); + }) + .finally(async () => { + await fetchData(); + }); + } }; /** diff --git a/src/modules/04_registry/components/Leave.vue b/src/modules/04_registry/components/Leave.vue index fc4d1ae29..1c3ecf5fe 100644 --- a/src/modules/04_registry/components/Leave.vue +++ b/src/modules/04_registry/components/Leave.vue @@ -444,7 +444,9 @@ const tittleHistory = ref("ประวัติแก้ไขการ const filterHistory = ref(""); //search data table history const modalHistory = ref(false); //modal ประวัติการแก้ไขข้อมูล const checkValidate = ref(false); //validate data ผ่านหรือไม่ -const profileId = ref(route.params.id.toString()); +const profileId = ref( + route.params.id ? route.params.id.toString() : "" +); const rows = ref([]); const filterTotal = ref(""); const rowsTotal = ref([]); //select data history @@ -715,33 +717,35 @@ onMounted(async () => { const fetchData = async () => { rows.value = []; - loaderPage(true); - await http - .get(config.API.profileLeaveId(profileId.value)) - .then((res) => { - const data = res.data.result; - // console.log(data); - data.map((e: ResponseObject) => { - rows.value.push({ - id: e.id, - typeLeave: e.typeLeave, - dateStartLeave: new Date(e.dateStartLeave), - dateEndLeave: new Date(e.dateEndLeave), - numLeave: e.numLeave, - sumLeave: e.sumLeave, - totalLeave: e.totalLeave, - status: e.status, - reason: e.reason, - typeLeaveId: e.typeLeaveId, + if (profileId.value) { + loaderPage(true); + await http + .get(config.API.profileLeaveId(profileId.value)) + .then((res) => { + const data = res.data.result; + // console.log(data); + data.map((e: ResponseObject) => { + rows.value.push({ + id: e.id, + typeLeave: e.typeLeave, + dateStartLeave: new Date(e.dateStartLeave), + dateEndLeave: new Date(e.dateEndLeave), + numLeave: e.numLeave, + sumLeave: e.sumLeave, + totalLeave: e.totalLeave, + status: e.status, + reason: e.reason, + typeLeaveId: e.typeLeaveId, + }); }); + }) + .catch((e) => { + messageError($q, e); + }) + .finally(() => { + loaderPage(false); }); - }) - .catch((e) => { - messageError($q, e); - }) - .finally(() => { - loaderPage(false); - }); + } }; const filterSelector = (val: any, update: Function, filtername: string) => { @@ -964,28 +968,30 @@ const clickSave = async () => { const saveData = async () => { const sum = Number(numLeave.value) + Number(numUsedLeave.value); - loaderPage(true); - await http - .post(config.API.profileLeaveId(profileId.value), { - dateStartLeave: dateToISO(dateRange.value[0]), - dateEndLeave: dateToISO(dateRange.value[1]), - numLeave: numLeave.value, - sumLeave: numUsedLeave.value, - totalLeave: sum, - status: statLeave.value, - reason: reason.value, - typeLeaveId: typeLeave.value, - }) - .then((res) => { - success($q, "บันทึกข้อมูลสำเร็จ"); - modalAdd.value = false; - }) - .catch((e) => { - messageError($q, e); - }) - .finally(async () => { - await fetchData(); - }); + if (profileId.value) { + loaderPage(true); + await http + .post(config.API.profileLeaveId(profileId.value), { + dateStartLeave: dateToISO(dateRange.value[0]), + dateEndLeave: dateToISO(dateRange.value[1]), + numLeave: numLeave.value, + sumLeave: numUsedLeave.value, + totalLeave: sum, + status: statLeave.value, + reason: reason.value, + typeLeaveId: typeLeave.value, + }) + .then((res) => { + success($q, "บันทึกข้อมูลสำเร็จ"); + modalAdd.value = false; + }) + .catch((e) => { + messageError($q, e); + }) + .finally(async () => { + await fetchData(); + }); + } }; // /** @@ -1185,27 +1191,29 @@ const addData = async () => { */ const clickTotal = async () => { rowsTotal.value = []; - loaderPage(true); - await http - .get(config.API.profileLeaveTotalId(profileId.value)) - .then((res) => { - let data = res.data.result; - data.map((e: ResponseTotalObject) => { - rowsTotal.value.push({ - typeLeaveId: e.typeLeaveId, - totalLeave: e.totalLeave, - limitLeave: e.limitLeave, - remainLeave: e.remainLeave, - typeLeave: e.typeLeave, + if (profileId.value) { + loaderPage(true); + await http + .get(config.API.profileLeaveTotalId(profileId.value)) + .then((res) => { + let data = res.data.result; + data.map((e: ResponseTotalObject) => { + rowsTotal.value.push({ + typeLeaveId: e.typeLeaveId, + totalLeave: e.totalLeave, + limitLeave: e.limitLeave, + remainLeave: e.remainLeave, + typeLeave: e.typeLeave, + }); }); + }) + .catch((e) => { + messageError($q, e); + }) + .finally(() => { + loaderPage(false); }); - }) - .catch((e) => { - messageError($q, e); - }) - .finally(() => { - loaderPage(false); - }); + } }; // /** diff --git a/src/modules/04_registry/components/Other.vue b/src/modules/04_registry/components/Other.vue index 9dd6f1094..715ce6256 100644 --- a/src/modules/04_registry/components/Other.vue +++ b/src/modules/04_registry/components/Other.vue @@ -213,7 +213,9 @@ const tittleHistory = ref("ประวัติแก้ไขอื่ const filterHistory = ref(""); //search data table history const modalHistory = ref(false); //modal ประวัติการแก้ไขข้อมูล const checkValidate = ref(false); //validate data ผ่านหรือไม่ -const profileId = ref(route.params.id.toString()); +const profileId = ref( + route.params.id ? route.params.id.toString() : "" +); const rows = ref([]); const filter = ref(""); //search data table const visibleColumns = ref([]); @@ -302,28 +304,30 @@ onMounted(async () => { }); const fetchData = async () => { - loaderPage(true); - await http - .get(config.API.profileOtherId(profileId.value)) - .then((res) => { - let data = res.data.result; - rows.value = []; - data.map((e: ResponseObject) => { - rows.value.push({ - id: e.id, - date: new Date(e.date), - detail: e.detail, - createdFullName: e.createdFullName, - createdAt: new Date(e.createdAt), + if (profileId.value) { + loaderPage(true); + await http + .get(config.API.profileOtherId(profileId.value)) + .then((res) => { + let data = res.data.result; + rows.value = []; + data.map((e: ResponseObject) => { + rows.value.push({ + id: e.id, + date: new Date(e.date), + detail: e.detail, + createdFullName: e.createdFullName, + createdAt: new Date(e.createdAt), + }); }); + }) + .catch((e) => { + messageError($q, e); + }) + .finally(() => { + loaderPage(false); }); - }) - .catch((e) => { - messageError($q, e); - }) - .finally(() => { - loaderPage(false); - }); + } }; /** @@ -407,23 +411,25 @@ const clickSave = async () => { * บันทึกเพิ่มข้อมูล */ const saveData = async () => { - loaderPage(true); - await http - .post(config.API.profileOtherId(profileId.value), { - id: id.value, - date: date.value, - detail: detail.value, - }) - .then((res) => { - success($q, "บันทึกข้อมูลสำเร็จ"); - modal.value = false; - }) - .catch((e) => { - messageError($q, e); - }) - .finally(async () => { - await fetchData(); - }); + if (profileId.value) { + loaderPage(true); + await http + .post(config.API.profileOtherId(profileId.value), { + id: id.value, + date: date.value, + detail: detail.value, + }) + .then((res) => { + success($q, "บันทึกข้อมูลสำเร็จ"); + modal.value = false; + }) + .catch((e) => { + messageError($q, e); + }) + .finally(async () => { + await fetchData(); + }); + } }; /** diff --git a/src/modules/04_registry/components/Record.vue b/src/modules/04_registry/components/Record.vue index 4eac4635c..a32e0f07f 100644 --- a/src/modules/04_registry/components/Record.vue +++ b/src/modules/04_registry/components/Record.vue @@ -309,7 +309,9 @@ const tittleHistory = ref( ); const filterHistory = ref(""); //search data table history const modalHistory = ref(false); //modal ประวัติการแก้ไขข้อมูล -const profileId = ref(route.params.id.toString()); +const profileId = ref( + route.params.id ? route.params.id.toString() : "" +); const checkValidate = ref(false); //validate data ผ่านหรือไม่ const rows = ref([]); const filter = ref(""); //search data table @@ -478,32 +480,34 @@ onMounted(async () => { }); const fetchData = async () => { - loaderPage(true); - await http - .get(config.API.profileNopaidId(profileId.value)) - .then((res) => { - let data = res.data.result; - rows.value = []; - data.map((e: ResponseObject) => { - rows.value.push({ - id: e.id, - date: new Date(e.date), - detail: e.detail, - reference: e.reference, - refCommandNo: e.refCommandNo, - refCommandDate: - e.refCommandDate == null ? null : new Date(e.refCommandDate), - createdFullName: e.createdFullName, - createdAt: new Date(e.createdAt), + if (profileId.value) { + loaderPage(true); + await http + .get(config.API.profileNopaidId(profileId.value)) + .then((res) => { + let data = res.data.result; + rows.value = []; + data.map((e: ResponseObject) => { + rows.value.push({ + id: e.id, + date: new Date(e.date), + detail: e.detail, + reference: e.reference, + refCommandNo: e.refCommandNo, + refCommandDate: + e.refCommandDate == null ? null : new Date(e.refCommandDate), + createdFullName: e.createdFullName, + createdAt: new Date(e.createdAt), + }); }); + }) + .catch((e) => { + messageError($q, e); + }) + .finally(() => { + loaderPage(false); }); - }) - .catch((e) => { - messageError($q, e); - }) - .finally(() => { - loaderPage(false); - }); + } }; /** @@ -590,27 +594,29 @@ const clickSave = async () => { * บันทึกเพิ่มข้อมูล */ const saveData = async () => { - loaderPage(true); - await http - .post(config.API.profileNopaidId(profileId.value), { - id: id.value, - date: dateToISO(date.value), - detail: detail.value, - reference: reference.value, - refCommandNo: refCommandNo.value, - refCommandDate: - refCommandDate.value == null ? null : dateToISO(refCommandDate.value), - }) - .then((res) => { - success($q, "บันทึกข้อมูลสำเร็จ"); - modal.value = false; - }) - .catch((e) => { - messageError($q, e); - }) - .finally(async () => { - await fetchData(); - }); + if (profileId.value) { + loaderPage(true); + await http + .post(config.API.profileNopaidId(profileId.value), { + id: id.value, + date: dateToISO(date.value), + detail: detail.value, + reference: reference.value, + refCommandNo: refCommandNo.value, + refCommandDate: + refCommandDate.value == null ? null : dateToISO(refCommandDate.value), + }) + .then((res) => { + success($q, "บันทึกข้อมูลสำเร็จ"); + modal.value = false; + }) + .catch((e) => { + messageError($q, e); + }) + .finally(async () => { + await fetchData(); + }); + } }; /** diff --git a/src/modules/04_registry/components/Salary.vue b/src/modules/04_registry/components/Salary.vue index e1e324155..1f2a9c562 100644 --- a/src/modules/04_registry/components/Salary.vue +++ b/src/modules/04_registry/components/Salary.vue @@ -909,7 +909,9 @@ const tittleHistory = ref("ประวัติแก้ไขตำแ const filterHistory = ref(""); //search data table history const modalHistory = ref(false); //modal ประวัติการแก้ไขข้อมูล const checkValidate = ref(false); //validate data ผ่านหรือไม่ -const profileId = ref(route.params.id.toString()); +const profileId = ref( + route.params.id ? route.params.id.toString() : "" +); const rows = ref([]); const filter = ref(""); //search data table const visibleColumns = ref([]); @@ -1512,51 +1514,53 @@ const fetchPosition = async () => { }; const fetchData = async () => { - loaderPage(true); - await http - .get(config.API.profileSalaryId(profileId.value)) - .then((res) => { - let data = res.data.result; - rows.value = []; - data.map((e: ResponseObject) => { - rows.value.push({ - id: e.id, - date: new Date(e.date), - amount: e.amount, - positionSalaryAmount: e.positionSalaryAmount, - mouthSalaryAmount: e.mouthSalaryAmount, - oc: e.oc, - ocId: e.ocId, - position: e.position, - positionId: e.positionId, - posNo: e.posNo, - posNoId: e.posNoId, - positionLine: e.positionLine, - positionLineId: e.positionLineId, - positionPathSide: e.positionPathSide, - positionPathSideId: e.positionPathSideId, - positionType: e.positionType, - positionTypeId: e.positionTypeId, - positionLevel: e.positionLevel, - positionLevelId: e.positionLevelId, - positionExecutive: e.positionExecutive, - positionExecutiveId: e.positionExecutiveId, - positionExecutiveSide: e.positionExecutiveSide, - positionExecutiveSideId: e.positionExecutiveSideId, - salaryClass: e.salaryClass, - salaryRef: e.salaryRef, - refCommandNo: e.refCommandNo, - createdFullName: e.createdFullName, - createdAt: new Date(e.createdAt), + if (profileId.value) { + loaderPage(true); + await http + .get(config.API.profileSalaryId(profileId.value)) + .then((res) => { + let data = res.data.result; + rows.value = []; + data.map((e: ResponseObject) => { + rows.value.push({ + id: e.id, + date: new Date(e.date), + amount: e.amount, + positionSalaryAmount: e.positionSalaryAmount, + mouthSalaryAmount: e.mouthSalaryAmount, + oc: e.oc, + ocId: e.ocId, + position: e.position, + positionId: e.positionId, + posNo: e.posNo, + posNoId: e.posNoId, + positionLine: e.positionLine, + positionLineId: e.positionLineId, + positionPathSide: e.positionPathSide, + positionPathSideId: e.positionPathSideId, + positionType: e.positionType, + positionTypeId: e.positionTypeId, + positionLevel: e.positionLevel, + positionLevelId: e.positionLevelId, + positionExecutive: e.positionExecutive, + positionExecutiveId: e.positionExecutiveId, + positionExecutiveSide: e.positionExecutiveSide, + positionExecutiveSideId: e.positionExecutiveSideId, + salaryClass: e.salaryClass, + salaryRef: e.salaryRef, + refCommandNo: e.refCommandNo, + createdFullName: e.createdFullName, + createdAt: new Date(e.createdAt), + }); }); + }) + .catch((e) => { + messageError($q, e); + }) + .finally(() => { + loaderPage(false); }); - }) - .catch((e) => { - messageError($q, e); - }) - .finally(() => { - loaderPage(false); - }); + } }; const onSelected = async (id: string) => { @@ -1762,36 +1766,38 @@ const clickSave = async () => { * บันทึกเพิ่มข้อมูล */ const saveData = async () => { - loaderPage(true); - await http - .post(config.API.profileSalaryId(profileId.value), { - date: dateToISO(date.value), - amount: amount.value, - positionSalaryAmount: positionSalaryAmount.value, - mouthSalaryAmount: mouthSalaryAmount.value, - ocId: selected.value, - positionId: positionId.value, - posNoId: posNoId.value, - positionLineId: positionLineId.value, - positionPathSideId: positionPathSideId.value, - positionTypeId: positionTypeId.value, - positionLevelId: positionLevelId.value, - positionExecutiveId: positionExecutiveId.value, - positionExecutiveSideId: positionExecutiveSideId.value, - salaryClass: salaryClass.value, - salaryRef: salaryRef.value, - refCommandNo: refCommandNo.value, - }) - .then((res) => { - success($q, "บันทึกข้อมูลสำเร็จ"); - modal.value = false; - }) - .catch((e) => { - messageError($q, e); - }) - .finally(async () => { - await fetchData(); - }); + if (profileId.value) { + loaderPage(true); + await http + .post(config.API.profileSalaryId(profileId.value), { + date: dateToISO(date.value), + amount: amount.value, + positionSalaryAmount: positionSalaryAmount.value, + mouthSalaryAmount: mouthSalaryAmount.value, + ocId: selected.value, + positionId: positionId.value, + posNoId: posNoId.value, + positionLineId: positionLineId.value, + positionPathSideId: positionPathSideId.value, + positionTypeId: positionTypeId.value, + positionLevelId: positionLevelId.value, + positionExecutiveId: positionExecutiveId.value, + positionExecutiveSideId: positionExecutiveSideId.value, + salaryClass: salaryClass.value, + salaryRef: salaryRef.value, + refCommandNo: refCommandNo.value, + }) + .then((res) => { + success($q, "บันทึกข้อมูลสำเร็จ"); + modal.value = false; + }) + .catch((e) => { + messageError($q, e); + }) + .finally(async () => { + await fetchData(); + }); + } }; /** diff --git a/src/modules/04_registry/components/SalaryEmployee.vue b/src/modules/04_registry/components/SalaryEmployee.vue index f85c2e02a..b38af4d3d 100644 --- a/src/modules/04_registry/components/SalaryEmployee.vue +++ b/src/modules/04_registry/components/SalaryEmployee.vue @@ -918,7 +918,9 @@ const tittleHistory = ref("ประวัติแก้ไขตำแ const filterHistory = ref(""); //search data table history const modalHistory = ref(false); //modal ประวัติการแก้ไขข้อมูล const checkValidate = ref(false); //validate data ผ่านหรือไม่ -const profileId = ref(route.params.id.toString()); +const profileId = ref( + route.params.id ? route.params.id.toString() : "" +); const rows = ref([]); const filter = ref(""); //search data table const visibleColumns = ref([]); @@ -1466,48 +1468,50 @@ const filterSelector = (val: any, update: Function, filtername: string) => { }; const fetchData = async () => { - loaderPage(true); - await http - .get(config.API.profileSalaryEmployeeId(profileId.value)) - .then((res) => { - const data = res.data.result; - // console.log(data); - rows.value = []; - data.map((e: ResponseObjectEmployee) => { - rows.value.push({ - id: e.id, - date: new Date(e.date), - amount: e.amount, - positionSalaryAmount: e.positionSalaryAmount, - mouthSalaryAmount: e.mouthSalaryAmount, - oc: e.oc, - ocId: e.ocId, - posNo: e.posNo, - posNoId: e.posNoId, - posNoEmployee: e.posNoEmployee, - positionEmployeeGroup: e.positionEmployeeGroup, - positionEmployeeGroupId: e.positionEmployeeGroupId, - positionEmployeeLevel: e.positionEmployeeLevel, - positionEmployeeLevelId: e.positionEmployeeLevelId, - positionEmployeePosition: e.positionEmployeePosition, - positionEmployeePositionId: e.positionEmployeePositionId, - positionEmployeePositionSide: e.positionEmployeePositionSide, - positionEmployeePositionSideId: e.positionEmployeePositionSideId, - salaryClass: e.salaryClass, - salaryRef: e.salaryRef, - refCommandNo: e.refCommandNo, - // refCommandDate: new Date(e.refCommandDate), - createdFullName: e.createdFullName, - createdAt: new Date(e.createdAt), + if (profileId.value) { + loaderPage(true); + await http + .get(config.API.profileSalaryEmployeeId(profileId.value)) + .then((res) => { + const data = res.data.result; + // console.log(data); + rows.value = []; + data.map((e: ResponseObjectEmployee) => { + rows.value.push({ + id: e.id, + date: new Date(e.date), + amount: e.amount, + positionSalaryAmount: e.positionSalaryAmount, + mouthSalaryAmount: e.mouthSalaryAmount, + oc: e.oc, + ocId: e.ocId, + posNo: e.posNo, + posNoId: e.posNoId, + posNoEmployee: e.posNoEmployee, + positionEmployeeGroup: e.positionEmployeeGroup, + positionEmployeeGroupId: e.positionEmployeeGroupId, + positionEmployeeLevel: e.positionEmployeeLevel, + positionEmployeeLevelId: e.positionEmployeeLevelId, + positionEmployeePosition: e.positionEmployeePosition, + positionEmployeePositionId: e.positionEmployeePositionId, + positionEmployeePositionSide: e.positionEmployeePositionSide, + positionEmployeePositionSideId: e.positionEmployeePositionSideId, + salaryClass: e.salaryClass, + salaryRef: e.salaryRef, + refCommandNo: e.refCommandNo, + // refCommandDate: new Date(e.refCommandDate), + createdFullName: e.createdFullName, + createdAt: new Date(e.createdAt), + }); }); + }) + .catch((e) => { + messageError($q, e); + }) + .finally(() => { + loaderPage(false); }); - }) - .catch((e) => { - messageError($q, e); - }) - .finally(() => { - loaderPage(false); - }); + } }; const fetchPositionNumber = async (id: string) => { @@ -1691,34 +1695,36 @@ const clickSave = async () => { * บันทึกเพิ่มข้อมูล */ const saveData = async () => { - loaderPage(true); - await http - .post(config.API.profileSalaryEmployeeId(profileId.value), { - amount: amount.value, - date: dateToISO(date.value), - positionSalaryAmount: positionSalaryAmount.value, - mouthSalaryAmount: mouthSalaryAmount.value, - ocId: agencyId.value, - // posNoId: posNoId.value, - posNoEmployee: posNoEmployee.value, - positionEmployeeGroupId: employeeGroupId.value, - positionEmployeeLevelId: employeeLevelId.value, - positionEmployeePositionId: employeePositionId.value, - positionEmployeePositionSideId: employeePositionSideId.value, - salaryClass: salaryClass.value, - salaryRef: salaryRef.value, - refCommandNo: refCommandNo.value, - }) - .then((res) => { - success($q, "บันทึกข้อมูลสำเร็จ"); - modal.value = false; - }) - .catch((e) => { - messageError($q, e); - }) - .finally(async () => { - await fetchData(); - }); + if (profileId.value) { + loaderPage(true); + await http + .post(config.API.profileSalaryEmployeeId(profileId.value), { + amount: amount.value, + date: dateToISO(date.value), + positionSalaryAmount: positionSalaryAmount.value, + mouthSalaryAmount: mouthSalaryAmount.value, + ocId: agencyId.value, + // posNoId: posNoId.value, + posNoEmployee: posNoEmployee.value, + positionEmployeeGroupId: employeeGroupId.value, + positionEmployeeLevelId: employeeLevelId.value, + positionEmployeePositionId: employeePositionId.value, + positionEmployeePositionSideId: employeePositionSideId.value, + salaryClass: salaryClass.value, + salaryRef: salaryRef.value, + refCommandNo: refCommandNo.value, + }) + .then((res) => { + success($q, "บันทึกข้อมูลสำเร็จ"); + modal.value = false; + }) + .catch((e) => { + messageError($q, e); + }) + .finally(async () => { + await fetchData(); + }); + } }; /** diff --git a/src/modules/04_registry/components/SalaryEmployeeTemp.vue b/src/modules/04_registry/components/SalaryEmployeeTemp.vue index 64bc1f4de..f3cda3a29 100644 --- a/src/modules/04_registry/components/SalaryEmployeeTemp.vue +++ b/src/modules/04_registry/components/SalaryEmployeeTemp.vue @@ -1,197 +1,175 @@