From c0944ad1809d7e236625270b2fb577356a2b1152 Mon Sep 17 00:00:00 2001 From: "277151821@qq.com" <277151821@qq.com> Date: Fri, 8 Mar 2024 08:39:12 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B9=B4=E6=A3=80=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/assets/js/utils.js | 57 +++++++++++++++++++ .../mechanical_files/inspect_annually/add.vue | 37 +++++++++++- .../inspect_annually/edit.vue | 37 +++++++++++- 3 files changed, 125 insertions(+), 6 deletions(-) diff --git a/src/assets/js/utils.js b/src/assets/js/utils.js index 2b8c5fc..474d84b 100644 --- a/src/assets/js/utils.js +++ b/src/assets/js/utils.js @@ -360,3 +360,60 @@ export function idCardGetDateAndGender(idCard) { } return { sex, date }; } + +/** + * 截止时间为 用户选择的月数(或者是年数)累加起始时间 + * 要解决的问题 : + * 1.如在2020年2月29号签约,签约时间为1年,那么截止时间就只能返回2021年2月28号; + * 2.如在2020年1月31号签约,签约时间为1个月,那么截止时间就只能返回2020年2月29号; + * @param {*} date 要累加的时间 + * @param {*} num 累加多少个月 1年就是12个月 + */ +export function timeTransformation(date,num) { + date = new Date(date) + let day = date.getDate(); + let month = date.getMonth(); + let year = date.getFullYear(); + year = year + parseInt((month + num) / 12); + month = (month + num) % 12; + // 0-11 转变为 1-12 + month += 1; + + const maxDayCount = new Date(year,month,0).getDate(); + if(day > maxDayCount)day = maxDayCount + if(month < 10 )(month = '0' + month) + if(day < 10)(day = '0' + day) + return year + '-' + month + '-' + day +} + +/** + * 提醒日期计算 + * @param {*} date 到期日期 + * @param {*} daysToSubtract 提醒天数 + */ +export function subtractDaysFromDate(date, daysToSubtract) { + let newDate = new Date(); // 创建当前时间对象 + if (typeof date === 'string') { + // 将字符串类型的日期转换成 Date 对象 + newDate.setTime(new Date(date).getTime()); + } else if (Object.prototype.toString.call(date) === "[object Date]") { + // 直接传入了 Date 对象 + newDate = date; + } else { + console.log("无效的输入参数") + } + newDate.setDate(newDate.getDate() - daysToSubtract); // 在原有基础上减去指定天数 + const formatDateToString = (dateObj) => { + const year = dateObj.getFullYear().toString(); + let month = (dateObj.getMonth() + 1).toString(); + let day = dateObj.getDate().toString(); + if (month.length < 2) { + month = "0" + month; + } + if (day.length < 2) { + day = "0" + day; + } + return [year, month, day].join("-"); + } + return formatDateToString(newDate); // 返回新日期的字符串表示形式 +} diff --git a/src/views/mechanical_files/inspect_annually/add.vue b/src/views/mechanical_files/inspect_annually/add.vue index 6b4be37..a16a517 100644 --- a/src/views/mechanical_files/inspect_annually/add.vue +++ b/src/views/mechanical_files/inspect_annually/add.vue @@ -114,12 +114,13 @@ value-format="YYYY-MM-DD" format="YYYY-MM-DD" type="date" + @change="getDueDate" /> - + @@ -156,7 +158,7 @@ - + @@ -166,6 +168,7 @@ value-format="YYYY-MM-DD" format="YYYY-MM-DD" type="date" + disabled /> @@ -221,7 +224,7 @@ import { ElMessage } from "element-plus"; import { useRoute, useRouter, } from "vue-router"; import useFormValidate from "@/assets/js/useFormValidate.js"; - import { addingPrefixToFile } from "@/assets/js/utils.js"; + import { addingPrefixToFile ,timeTransformation,subtractDaysFromDate} from "@/assets/js/utils.js"; const route = useRoute(); const router = useRouter(); const INSPECTANNUALLY_ID = route.query.INSPECTANNUALLY_ID @@ -278,6 +281,34 @@ REMINDER_DAYS: [{ required: true, message: "请输入", trigger: "blur" }], REMINDER_DATE: [{ required: true, message: "请输入", trigger: "blur" }], } + const getDueDate = ()=>{ + if(form.value.PROCESSING_DATE&&form.value.ANNUAL_INSPECTION_CYCLE){ + const list = annualInspectionCycleList._rawValue + let num = 0 + for(let i=0;i{ + if(val){ + if(form.value.DUE_DATE){ + form.value.REMINDER_DATE = subtractDaysFromDate(form.value.DUE_DATE,val) + } + }else { + form.value.REMINDER_DATE = '' + } + } const getVehicle = async (event) =>{ const resData = await getTrailerList({TRAFFIC_TYPE:event}) data.vehicleList = resData.list diff --git a/src/views/mechanical_files/inspect_annually/edit.vue b/src/views/mechanical_files/inspect_annually/edit.vue index 6b4be37..a16a517 100644 --- a/src/views/mechanical_files/inspect_annually/edit.vue +++ b/src/views/mechanical_files/inspect_annually/edit.vue @@ -114,12 +114,13 @@ value-format="YYYY-MM-DD" format="YYYY-MM-DD" type="date" + @change="getDueDate" /> - + @@ -156,7 +158,7 @@ - + @@ -166,6 +168,7 @@ value-format="YYYY-MM-DD" format="YYYY-MM-DD" type="date" + disabled /> @@ -221,7 +224,7 @@ import { ElMessage } from "element-plus"; import { useRoute, useRouter, } from "vue-router"; import useFormValidate from "@/assets/js/useFormValidate.js"; - import { addingPrefixToFile } from "@/assets/js/utils.js"; + import { addingPrefixToFile ,timeTransformation,subtractDaysFromDate} from "@/assets/js/utils.js"; const route = useRoute(); const router = useRouter(); const INSPECTANNUALLY_ID = route.query.INSPECTANNUALLY_ID @@ -278,6 +281,34 @@ REMINDER_DAYS: [{ required: true, message: "请输入", trigger: "blur" }], REMINDER_DATE: [{ required: true, message: "请输入", trigger: "blur" }], } + const getDueDate = ()=>{ + if(form.value.PROCESSING_DATE&&form.value.ANNUAL_INSPECTION_CYCLE){ + const list = annualInspectionCycleList._rawValue + let num = 0 + for(let i=0;i{ + if(val){ + if(form.value.DUE_DATE){ + form.value.REMINDER_DATE = subtractDaysFromDate(form.value.DUE_DATE,val) + } + }else { + form.value.REMINDER_DATE = '' + } + } const getVehicle = async (event) =>{ const resData = await getTrailerList({TRAFFIC_TYPE:event}) data.vehicleList = resData.list