通过公式限制请假天数
本案例来自三方开发者「Jing」
1. 使用场景
很多用户都会使用宜搭做考勤管理,特别是请假管理,需要校验每个员工的年假时长,请年假不能超过公司规定的年假时长,但是若是请病假或事假或其他假期类别的时候则无需限制。
2. 实现功能
2.1 配置页面
(1)员工假期时长表
用于记录员工不同类型假期的假期时长。
(2)请假申请
2.2 配置页面功能
注意根据实际需求修改组件标识。
(1)数据联动
配置数据联动以联动出剩余的假期天数。
(2)公式编辑
配置公式编辑以计算请假时长。
{"text":"DAYS(DATE(请假结束时间),DATE(请假开始时间))","marks":[{"from":{"line":0,"ch":10,"sticky":null},"to":{"line":0,"ch":18,"sticky":null},"value":"dateField_ksudx6ym","invalid":false},{"from":{"line":0,"ch":25,"sticky":null},"to":{"line":0,"ch":33,"sticky":null},"value":"dateField_ksudx6yk","invalid":false}],"isCmData":true}
(3)配置页面提交前事件
配置页面提交前事件以实现提交前实时查询剩余请假天数,避免因多次提交造成的数据错误。
参考文档:根据条件搜索表单实例详情列表
接口配置如图:
绑定下述事件:
export function beforeSubmit({ formDataMap }) {
// 注意:目前不支持在这里修改提交数据
return new Promise(resolve => {
this.dataSourceMap.getData.load({
formUuid: 'FORM-8Y866XB1QYR69Z5I684BVBUI6MBZ2H0BC84CL7',
searchFieldJson: JSON.stringify({
employeeField_ksu8iqm5: [this.$('employeeField_ksudx6yc').getValue()[0].value],
dateField_lc48ia6n: [this.$('dateField_lc48iwz8').getValue() - 1, this.$('dateField_lc48iwz8').getValue() + 1],
radioField_lc73huhr: this.$('radioField_ksudx6yi').getValue()
})
}).then(res => {
const { totalCount, data } = res;
if (!totalCount) {
this.utils.toast({
title: '该类型假期定额不足',
type: 'error',
});
resolve(false);
} else {
const { formData } = data[0];
const days = this.$('numberField_ksudx6yo').getValue(); // 请假时长
if (days > formData.numberField_ksu8iqm9) {
this.utils.toast({
title: '该类型假期定额不足,请重新提交',
type: 'error',
});
resolve(false);
} else {
resolve(true);
};
};
}).catch(error => {
this.utils.toast({
title: error.message,
type: 'error',
});
resolve(false);
});
});
}
(4)流程配置业务关联规则
当员工发起请假时即对假期余额进行扣除,若审批拒绝或者发起人撤销,则释放扣除的额度,当对应类型假期额度不足则阻断其提交。
{"text":"UPDATE(员工假期时长表,AND(EQ(员工假期时长表.员工姓名,请假人),EQ(员工假期时长表.年份,年份),EQ(员工假期时长表.假期类型,请假类型)),\"\",员工假期时长表.假期时长,员工假期时长表.假期时长-请假时长)","marks":[{"from":{"line":0,"ch":7,"sticky":null},"to":{"line":0,"ch":16,"sticky":null},"value":"FORM-8Y866XB1QYR69Z5I684BVBUI6MBZ2H0BC84CL7/","invalid":false},{"from":{"line":0,"ch":24,"sticky":null},"to":{"line":0,"ch":38,"sticky":null},"value":"FORM-8Y866XB1QYR69Z5I684BVBUI6MBZ2H0BC84CL7/employeeField_ksu8iqm5","invalid":false},{"from":{"line":0,"ch":39,"sticky":null},"to":{"line":0,"ch":44,"sticky":null},"value":"employeeField_ksudx6yc","invalid":false},{"from":{"line":0,"ch":49,"sticky":null},"to":{"line":0,"ch":61,"sticky":null},"value":"FORM-8Y866XB1QYR69Z5I684BVBUI6MBZ2H0BC84CL7/dateField_lc48ia6n","invalid":false},{"from":{"line":0,"ch":62,"sticky":null},"to":{"line":0,"ch":66,"sticky":null},"value":"dateField_lc48iwz8","invalid":false},{"from":{"line":0,"ch":71,"sticky":null},"to":{"line":0,"ch":85,"sticky":null},"value":"FORM-8Y866XB1QYR69Z5I684BVBUI6MBZ2H0BC84CL7/radioField_lc73huhr","invalid":false},{"from":{"line":0,"ch":86,"sticky":null},"to":{"line":0,"ch":92,"sticky":null},"value":"radioField_ksudx6yi","invalid":false},{"from":{"line":0,"ch":98,"sticky":null},"to":{"line":0,"ch":112,"sticky":null},"value":"FORM-8Y866XB1QYR69Z5I684BVBUI6MBZ2H0BC84CL7/numberField_ksu8iqm9","invalid":false},{"from":{"line":0,"ch":113,"sticky":null},"to":{"line":0,"ch":127,"sticky":null},"value":"FORM-8Y866XB1QYR69Z5I684BVBUI6MBZ2H0BC84CL7/numberField_ksu8iqm9","invalid":false},{"from":{"line":0,"ch":128,"sticky":null},"to":{"line":0,"ch":134,"sticky":null},"value":"numberField_ksudx6yo","invalid":false}],"isCmData":true}
{"text":"UPDATE(员工假期时长表,AND(EQ(员工假期时长表.员工姓名,请假人),EQ(员工假期时长表.年份,年份),EQ(员工假期时长表.假期类型,请假类型)),\"\",员工假期时长表.假期时长,员工假期时长表.假期时长+请假时长)","marks":[{"from":{"line":0,"ch":7,"sticky":null},"to":{"line":0,"ch":16,"sticky":null},"value":"FORM-8Y866XB1QYR69Z5I684BVBUI6MBZ2H0BC84CL7/","invalid":false},{"from":{"line":0,"ch":24,"sticky":null},"to":{"line":0,"ch":38,"sticky":null},"value":"FORM-8Y866XB1QYR69Z5I684BVBUI6MBZ2H0BC84CL7/employeeField_ksu8iqm5","invalid":false},{"from":{"line":0,"ch":39,"sticky":null},"to":{"line":0,"ch":44,"sticky":null},"value":"employeeField_ksudx6yc","invalid":false},{"from":{"line":0,"ch":49,"sticky":null},"to":{"line":0,"ch":61,"sticky":null},"value":"FORM-8Y866XB1QYR69Z5I684BVBUI6MBZ2H0BC84CL7/dateField_lc48ia6n","invalid":false},{"from":{"line":0,"ch":62,"sticky":null},"to":{"line":0,"ch":66,"sticky":null},"value":"dateField_lc48iwz8","invalid":false},{"from":{"line":0,"ch":71,"sticky":null},"to":{"line":0,"ch":85,"sticky":null},"value":"FORM-8Y866XB1QYR69Z5I684BVBUI6MBZ2H0BC84CL7/radioField_lc73huhr","invalid":false},{"from":{"line":0,"ch":86,"sticky":null},"to":{"line":0,"ch":92,"sticky":null},"value":"radioField_ksudx6yi","invalid":false},{"from":{"line":0,"ch":98,"sticky":null},"to":{"line":0,"ch":112,"sticky":null},"value":"FORM-8Y866XB1QYR69Z5I684BVBUI6MBZ2H0BC84CL7/numberField_ksu8iqm9","invalid":false},{"from":{"line":0,"ch":113,"sticky":null},"to":{"line":0,"ch":127,"sticky":null},"value":"FORM-8Y866XB1QYR69Z5I684BVBUI6MBZ2H0BC84CL7/numberField_ksu8iqm9","invalid":false},{"from":{"line":0,"ch":128,"sticky":null},"to":{"line":0,"ch":134,"sticky":null},"value":"numberField_ksudx6yo","invalid":false}],"isCmData":true}
{"text":"OR(ISEMPTY(剩余假期天数),GT(请假时长,剩余假期天数))","marks":[{"from":{"line":0,"ch":11,"sticky":null},"to":{"line":0,"ch":19,"sticky":null},"value":"numberField_ksudx6yg","invalid":false},{"from":{"line":0,"ch":24,"sticky":null},"to":{"line":0,"ch":30,"sticky":null},"value":"numberField_ksudx6yo","invalid":false},{"from":{"line":0,"ch":31,"sticky":null},"to":{"line":0,"ch":39,"sticky":null},"value":"numberField_ksudx6yg","invalid":false}],"isCmData":true}
3. 实现效果
4. 在线试玩
本文档对您是否有帮助?