提交1
This commit is contained in:
parent
cb9a8de242
commit
1d1d8c795c
@ -91,7 +91,7 @@ function confirm(e: any) {
|
||||
newValue.value = dayjs(value).format("YYYY-MM");
|
||||
}
|
||||
if (attrs.componentProps.ok && typeof attrs.componentProps.ok == "function") {
|
||||
attrs.componentProps.ok(e);
|
||||
attrs.componentProps.ok(e, attrs);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
@ -5,12 +5,14 @@
|
||||
<template v-for="(item, index) in education.xl" :key="index">
|
||||
<view class="po-re mb-15">
|
||||
<BasicForm
|
||||
:index="index"
|
||||
v-model="item.value"
|
||||
:schema="schema"
|
||||
:key="`form-${index}-${forceUpdateKey}`"
|
||||
:formsProps="{ labelWidth: 100 }"
|
||||
/>
|
||||
<view
|
||||
@click="deleteMemberFamily(index as number, item.value)"
|
||||
@click="deleteMemberFamily(index, item.value)"
|
||||
class="delete-icon"
|
||||
>
|
||||
<BasicIcon type="clear" size="30" />
|
||||
@ -29,6 +31,12 @@
|
||||
</view>
|
||||
<template #bottom>
|
||||
<view class="flex-row items-center pb-10 pt-5">
|
||||
<u-button
|
||||
text="测试计算"
|
||||
class="ml-15 mr-7"
|
||||
:plain="true"
|
||||
@click="calculateAllPositionYears"
|
||||
/>
|
||||
<u-button
|
||||
text="上一步"
|
||||
class="ml-15 mr-7"
|
||||
@ -47,10 +55,34 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import {dicApi} from "@/api/system/dic";
|
||||
import {useDataStore} from "@/store/modules/data";
|
||||
import {navigateBack, navigateTo} from "@/utils/uniapp";
|
||||
import {cloneDeep, map} from "lodash";
|
||||
import { dicApi } from "@/api/system/dic";
|
||||
import { useDataStore } from "@/store/modules/data";
|
||||
import { navigateBack, navigateTo } from "@/utils/uniapp";
|
||||
import { cloneDeep, map } from "lodash";
|
||||
import dayjs from "dayjs";
|
||||
|
||||
// 计算任岗年限
|
||||
const calculatePositionYears = (startDate: string, endDate?: string) => {
|
||||
if (!startDate) return "";
|
||||
const start = dayjs(startDate);
|
||||
const end = endDate ? dayjs(endDate) : dayjs();
|
||||
const years = end.diff(start, "year");
|
||||
console.log("计算任岗年限:", { startDate, endDate, years });
|
||||
// 确保0值也能显示,转换为字符串
|
||||
return years.toString();
|
||||
};
|
||||
|
||||
// 强制重新渲染的键
|
||||
const forceUpdateKey = ref(0);
|
||||
|
||||
// 更新指定项的任岗年限
|
||||
const updatePositionYears = (itemValue: any) => {
|
||||
const { gwrztime, gwpyjssj } = itemValue;
|
||||
if (gwrztime) {
|
||||
const years = calculatePositionYears(gwrztime, gwpyjssj);
|
||||
itemValue.gwrznx = years;
|
||||
}
|
||||
};
|
||||
|
||||
const schema = reactive<FormsSchema[]>([
|
||||
// {
|
||||
@ -81,25 +113,58 @@ const schema = reactive<FormsSchema[]>([
|
||||
component: "BasicDateTime",
|
||||
componentProps: {
|
||||
mode: "year-month",
|
||||
ok: (e: any, attrs: any) => {
|
||||
console.log("岗位聘用开始时间选择:", e, attrs);
|
||||
const formIndex = attrs.index;
|
||||
if (formIndex !== undefined && education.xl[formIndex]) {
|
||||
// 获取当前表单项的结束时间
|
||||
const endTime = education.xl[formIndex].value.gwpyjssj;
|
||||
console.log("当前表单项数据:", education.xl[formIndex].value);
|
||||
// 计算任岗年限
|
||||
const years = calculatePositionYears(e.value, endTime);
|
||||
// 更新任岗年限
|
||||
education.xl[formIndex].value.gwrznx = years;
|
||||
console.log("更新后的任岗年限:", education.xl[formIndex].value.gwrznx);
|
||||
// 强制重新渲染
|
||||
forceUpdateKey.value++;
|
||||
}
|
||||
},
|
||||
},
|
||||
}, {
|
||||
},
|
||||
{
|
||||
field: "gwpyjssj",
|
||||
label: "岗位聘用结束时间",
|
||||
component: "BasicDateTime",
|
||||
componentProps: {
|
||||
mode: "year-month",
|
||||
ok: (e: any, attrs: any) => {
|
||||
console.log("岗位聘用结束时间选择:", e, attrs);
|
||||
const formIndex = attrs.index;
|
||||
if (formIndex !== undefined && education.xl[formIndex]) {
|
||||
// 获取当前表单项的开始时间
|
||||
const startTime = education.xl[formIndex].value.gwrztime;
|
||||
console.log("当前表单项数据:", education.xl[formIndex].value);
|
||||
if (startTime) {
|
||||
// 计算任岗年限
|
||||
const years = calculatePositionYears(startTime, e.value);
|
||||
// 更新任岗年限
|
||||
education.xl[formIndex].value.gwrznx = years;
|
||||
console.log("更新后的任岗年限:", education.xl[formIndex].value.gwrznx);
|
||||
// 强制重新渲染
|
||||
forceUpdateKey.value++;
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
}, {
|
||||
field: "gwpyjssj",
|
||||
label: "当时时间-岗位聘用开始时间",
|
||||
component: "BasicDateTimes",
|
||||
componentProps: {},
|
||||
},
|
||||
{
|
||||
field: "gwrznx",
|
||||
label: "岗位任职年限",
|
||||
component: "BasicInput",
|
||||
componentProps: {},
|
||||
componentProps: {
|
||||
disabled: true,
|
||||
placeholder: "请选择岗位聘用时间",
|
||||
},
|
||||
},
|
||||
// {
|
||||
// field: "zrxk",
|
||||
@ -145,16 +210,67 @@ if (getFile.rgqkList && getFile.rgqkList.length > 0) {
|
||||
education.xl = map(getFile.rgqkList, (item) => {
|
||||
return { value: item };
|
||||
});
|
||||
|
||||
// 回显数据后,重新计算所有任岗年限
|
||||
nextTick(() => {
|
||||
education.xl.forEach((item: any, index: number) => {
|
||||
if (item.value.gwrztime) {
|
||||
const years = calculatePositionYears(
|
||||
item.value.gwrztime,
|
||||
item.value.gwpyjssj
|
||||
);
|
||||
item.value.gwrznx = years;
|
||||
console.log(`回显数据-表单项${index}计算结果:`, {
|
||||
gwrztime: item.value.gwrztime,
|
||||
gwpyjssj: item.value.gwpyjssj,
|
||||
gwrznx: years,
|
||||
是否为0: years === "0"
|
||||
});
|
||||
} else {
|
||||
// 没有开始时间时,清空任岗年限
|
||||
item.value.gwrznx = "";
|
||||
}
|
||||
});
|
||||
// 强制重新渲染确保界面更新
|
||||
forceUpdateKey.value++;
|
||||
});
|
||||
}
|
||||
|
||||
// 手动触发计算所有项目的任岗年限
|
||||
const calculateAllPositionYears = () => {
|
||||
education.xl.forEach((item: any, index: number) => {
|
||||
if (item.value.gwrztime) {
|
||||
const years = calculatePositionYears(
|
||||
item.value.gwrztime,
|
||||
item.value.gwpyjssj
|
||||
);
|
||||
item.value.gwrznx = years;
|
||||
console.log(`表单项${index}计算结果:`, {
|
||||
gwrztime: item.value.gwrztime,
|
||||
gwpyjssj: item.value.gwpyjssj,
|
||||
gwrznx: years,
|
||||
是否为0: years === "0"
|
||||
});
|
||||
} else {
|
||||
// 没有开始时间时,清空任岗年限
|
||||
item.value.gwrznx = "";
|
||||
}
|
||||
});
|
||||
forceUpdateKey.value++;
|
||||
};
|
||||
|
||||
function addEducation() {
|
||||
education.xl.push({ value: {} });
|
||||
// 强制重新渲染
|
||||
forceUpdateKey.value++;
|
||||
}
|
||||
|
||||
function deleteMemberFamily(index: number, item: any) {
|
||||
const list = cloneDeep(education.xl);
|
||||
list.splice(index, 1);
|
||||
education.xl = list;
|
||||
// 强制重新渲染
|
||||
forceUpdateKey.value++;
|
||||
}
|
||||
|
||||
function submit() {
|
||||
@ -165,8 +281,18 @@ function submit() {
|
||||
}),
|
||||
});
|
||||
navigateTo("/pages/view/hr/teacherProfile/ExperienceInfo");
|
||||
|
||||
}
|
||||
|
||||
// 组件挂载完成后处理回显数据
|
||||
onMounted(() => {
|
||||
// 如果有回显数据,再次确保计算正确
|
||||
if (getFile.rgqkList && getFile.rgqkList.length > 0) {
|
||||
nextTick(() => {
|
||||
console.log("组件挂载后处理回显数据");
|
||||
calculateAllPositionYears();
|
||||
});
|
||||
}
|
||||
});
|
||||
</script>
|
||||
<style>
|
||||
.delete-icon {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user