You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

452 lines
22 KiB
Plaintext

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<script>
/**
*
* @param pleavetype 出差方式0全天出差1按时间区间出差2半天3按时间长度出差
*/
function resetAttr(pleavetype) {
switch (pleavetype){
case '1'://按时间区间出差
WfForm.changeFieldValue(WfForm.convertFieldNameToId("scdw"),{ value: '1' });//出差时长单位为小时
//出差开始时间可编辑
WfForm.changeFieldAttr(WfForm.convertFieldNameToId("kssj"), 3);
//出差结束时间可编辑
WfForm.changeFieldAttr(WfForm.convertFieldNameToId("jssj"), 3);
//出差时间长度不可编辑
WfForm.changeFieldAttr(WfForm.convertFieldNameToId("ccsc"), 1);
break;
case '3'://按时间区间出差
WfForm.changeFieldValue(WfForm.convertFieldNameToId("scdw"),{ value: '1' });//出差时长单位为小时
//隐藏出差开始时间所在行(结束时间在同一行,不需要额外设置)
WfForm.changeFieldAttr(WfForm.convertFieldNameToId("kssj"), 5);
//出差时间长度可编辑
WfForm.changeFieldAttr(WfForm.convertFieldNameToId("ccsc"), 3);
//每天出差时长默认为1小时
WfForm.changeFieldValue(WfForm.convertFieldNameToId("ccsc"),{ value: '1' });
break;
default:
WfForm.changeFieldValue(WfForm.convertFieldNameToId("scdw"),{ value: '0' });//出差时长单位为小时
//隐藏出差开始时间所在行(结束时间在同一行,不需要额外设置)
WfForm.changeFieldAttr(WfForm.convertFieldNameToId("kssj"), 5);
//出差时间长度不可编辑
WfForm.changeFieldAttr(WfForm.convertFieldNameToId("ccsc"), 1);
break;
}
}
jQuery().ready(function(){
WfForm.registerCheckEvent(WfForm.OPER_ADDROW+"1", function(callback){
callback(); //允许继续添加行调用callback不调用代表阻断添加
});
});
WfForm.registerAction(WfForm.ACTION_ADDROW+"1", function(index){
//adddetail()
});
/**
* 自动添加出差明细
*/
function adddetail() {
//首先进行必填校验,不通过直接退出
if(!WfForm.verifyFormRequired(false, true)){ return; }
//获取出差时段类型0全天1指定时间区间2半天3指定时长长度
let ccsd = WfForm.getFieldValue(WfForm.convertFieldNameToId("ccsd"));
//每天同时段出差1:是0
let mttsdcc = WfForm.getFieldValue(WfForm.convertFieldNameToId("mttsdcc"));
//开始日期
var ksrq = new Date(WfForm.getFieldValue(WfForm.convertFieldNameToId("ksrq")));
//结束日期
var jsrq = new Date(WfForm.getFieldValue(WfForm.convertFieldNameToId("jsrq")));
//开始时间
var kssj = WfForm.getFieldValue(WfForm.convertFieldNameToId("kssj"));
//结束时间
let jssj = WfForm.getFieldValue(WfForm.convertFieldNameToId("jssj"));
//出差时长
var ccsc = WfForm.getFieldValue(WfForm.convertFieldNameToId("ccsc"));
//出差类型
var arr_cclx= mobx.toJS(wfform.getFieldValueObj(WfForm.convertFieldNameToId("cclx")).specialobj);
var cclx = arr_cclx[0].id;
debugger
var ccr = WfForm.getFieldValue(WfForm.convertFieldNameToId("ccr"));
debugger;
let param = {
itemId:cclx,
userId:ccr.split(',')[0],
startDate:ksrq,
endDate:jsrq
}
let dateList=undefined;
$.ajax({
url:"/api/attendance/askforleave/getRestDayInterval",
type:"GET",
data:param,
dataType:"json",
async:false,
success:function(res){
console.log(res)
if (res.api_status){
dateList = res.data.data;
}
}
})
//清空第一明细所有记录
WfForm.delDetailRow("detail_1", "all");
//判断出差是否跨天
let v_overzero = jssj < kssj ? true : false;
//出差人ID数组
var arr_ids = (WfForm.getFieldValue(WfForm.convertFieldNameToId("ccr"))).split(',');
//出差人名字数组
var arr_names = (WfForm.getBrowserShowName(WfForm.convertFieldNameToId("ccr"))).split(',');
for (let index = 0; index < arr_ids.length; index++) {
//预置明细记录开始日期
var v_tmpbdate = new Date(ksrq);
//预置明细记录结束日期
var v_tmpedate = new Date(v_tmpbdate);
if (mttsdcc == '1') {
//首次循环时,明细开始与结束日期均等于主表开始日期,而主表结束日期一定大于等于开始日期,所以至少添加一笔明细
//当出差为跨天差时,每笔明细的结束日期会加一天
while(v_tmpedate <= jsrq && v_tmpedate <= jsrq){
let beginDate = v_tmpbdate.toString();
let rqlx = "";
if (dateList != undefined){
dateList.filter(item => {
if (item.rq == beginDate){
rqlx = item.rqlx;
}
});
}
if (rqlx == "1" || rqlx=="2" || rqlx=="3"){
//明细开始日期加一天
v_tmpbdate = v_tmpbdate.setDate(v_tmpbdate.getDate() + 1);
v_tmpbdate = new Date(v_tmpbdate);
//明细结束日期加一天
v_tmpedate = v_tmpedate.setDate(v_tmpedate.getDate() + 1);
v_tmpedate = new Date(v_tmpedate);
continue;
}
//初始化明细记录
var addObj = {};
//添加出差人信息
addObj[WfForm.convertFieldNameToId("ccr", "detail_1")] = {value:arr_ids[index],specialobj:[{id:arr_ids[index],name:arr_names[index]}]};
//添加出差类型
addObj[WfForm.convertFieldNameToId("cclx", "detail_1")] = {value:arr_cclx[0].id,specialobj:[{id:arr_cclx[0].id,name:arr_cclx[0].mc}]};
//添加开始日期字段信息
addObj[WfForm.convertFieldNameToId("ksrq", "detail_1")] = {value:v_tmpbdate};
if (ccsd === '1'){
//按时间区间出差逻辑
if (v_overzero){
//跨天时,明细记录的结束日期等于开始日期加一天
v_tmpedate = v_tmpedate.setDate(v_tmpbdate.getDate() + 1);
v_tmpedate = new Date(v_tmpedate);
}
//添加结束日期字段信息
addObj[WfForm.convertFieldNameToId("jsrq", "detail_1")] = {value:v_tmpedate};
//添加开始时间字段信息
addObj[WfForm.convertFieldNameToId("kssj", "detail_1")] = {value:kssj};
//添加结束时间字段信息
addObj[WfForm.convertFieldNameToId("jssj", "detail_1")] = {value:jssj};
//todo 调用接口计算开始结束时间区间内的工作时长;
//暂时先不调用接口,直接使用开始结束时间区间间隔小时数
var v_hours = (new Date(v_tmpedate+" "+jssj).getTime() - new Date(v_tmpbdate+" "+kssj).getTime())/(1000 * 60 * 60);
//超过8小时以8小时计
v_hours = Number(v_hours) > 8 ? 8 : Number(v_hours)
addObj[WfForm.convertFieldNameToId("ccsc", "detail_1")] = {value:v_hours};
}else{
//按时间长度出差或者全天、半天出差逻辑,
//此三种情况系统只需要知道员工当天班次上是希望出差的小数数或者是全天还是半天出差即可,与结束日期,开始及结束时间没有关系,所以相应的值均设置为空
//添加结束日期字段信息
addObj[WfForm.convertFieldNameToId("jsrq", "detail_1")] = {value:''};
//添加开始时间字段信息
addObj[WfForm.convertFieldNameToId("kssj", "detail_1")] = {value:''};
//添加结束时间字段信息
addObj[WfForm.convertFieldNameToId("jssj", "detail_1")] = {value:''};
if (ccsd == '0'){
//全天出差时,全天的标记打开
addObj[WfForm.convertFieldNameToId("qtcc", "detail_1")] = {value:'1'};
}else if (ccsd == '2') {
//半天出差时,半天的标记打开
addObj[WfForm.convertFieldNameToId("btcc", "detail_1")] = {value:'1'};
}else if (ccsd == '3'){
//按小数数出差时,将主表上的总出差时长当成每天出差时长进行赋值
addObj[WfForm.convertFieldNameToId("ccsc", "detail_1")] = {value:ccsc};
}
}
//追加明细记录
WfForm.addDetailRow("detail_1", addObj);
//明细开始日期加一天
v_tmpbdate = v_tmpbdate.setDate(v_tmpbdate.getDate() + 1);
v_tmpbdate = new Date(v_tmpbdate);
//明细结束日期加一天
v_tmpedate = v_tmpedate.setDate(v_tmpedate.getDate() + 1);
v_tmpedate = new Date(v_tmpedate);
}
}else{
//非每天同时段出差方式出差
//设置第一笔明细结束日期为出差开始日期加一天
v_tmpedate = v_tmpedate.setDate(v_tmpedate.getDate() + 1);
v_tmpedate = new Date(v_tmpedate);
while (v_tmpedate <= jsrq) {
var addObj = {};
addObj[WfForm.convertFieldNameToId("ccr", "detail_1")] = {value:arr_ids[index],specialobj:[{id:arr_ids[index],name:arr_names[index]}]};
addObj[WfForm.convertFieldNameToId("ksrq", "detail_1")] = {value:v_tmpbdate};
if (ccsd === '1'){
addObj[WfForm.convertFieldNameToId("jsrq", "detail_1")] = {value:v_tmpedate};
addObj[WfForm.convertFieldNameToId("kssj", "detail_1")] = {value:kssj};
addObj[WfForm.convertFieldNameToId("jssj", "detail_1")] = {value:"00:00"};
}else{
addObj[WfForm.convertFieldNameToId("jsrq", "detail_1")] = {value:''};
addObj[WfForm.convertFieldNameToId("kssj", "detail_1")] = {value:''};
addObj[WfForm.convertFieldNameToId("jssj", "detail_1")] = {value:''};
if (ccsd == '0'){
addObj[WfForm.convertFieldNameToId("qtcc", "detail_1")] = {value:'1'};
addObj[WfForm.convertFieldNameToId("btcc", "detail_1")] = {value:'0'};
}else{
addObj[WfForm.convertFieldNameToId("qtcc", "detail_1")] = {value:'0'};
addObj[WfForm.convertFieldNameToId("btcc", "detail_1")] = {value:'1'};
}
}
//追加明细记录
WfForm.addDetailRow("detail_1", addObj);
v_tmpbdate = new Date(v_tmpedate);
kssj = '00:00';
//明细结束日期加一天
v_tmpedate = v_tmpedate.setDate(v_tmpedate.getDate() + 1);
v_tmpedate = new Date(v_tmpedate);
}
var addObj = {};
addObj[WfForm.convertFieldNameToId("ksrq", "detail_1")] = {value:v_tmpbdate};
if (ccsd === '1'){
addObj[WfForm.convertFieldNameToId("jsrq", "detail_1")] = {value:jsrq};
addObj[WfForm.convertFieldNameToId("kssj", "detail_1")] = {value:kssj};
addObj[WfForm.convertFieldNameToId("jssj", "detail_1")] = {value:jssj};
}else{
addObj[WfForm.convertFieldNameToId("jsrq", "detail_1")] = {value:''};
addObj[WfForm.convertFieldNameToId("kssj", "detail_1")] = {value:''};
addObj[WfForm.convertFieldNameToId("jssj", "detail_1")] = {value:''};
if (ccsd == '0')
addObj[WfForm.convertFieldNameToId("qtcc", "detail_1")] = {value:'1'};
else
addObj[WfForm.convertFieldNameToId("btcc", "detail_1")] = {value:'1'};
}
//追加明细记录
WfForm.addDetailRow("detail_1", addObj);
}
//});
};
//添加完明细后,更新主表的总出差时长栏位信息
var totalsc = getTotalsc();
WfForm.changeFieldValue(WfForm.convertFieldNameToId("ccsc"), {value:totalsc});
//控制明细显示属性
var rowArr = WfForm.getDetailAllRowIndexStr("detail_1").split(",");
for(var i=0; i<rowArr.length; i++){
var rowIndex = rowArr[i];
if(rowIndex !== ""){
switch(ccsd){
case '1'://按时间区间出差
WfForm.changeFieldAttr(WfForm.convertFieldNameToId("ccsc","detail_1")+"_"+rowIndex, 1);//出差时长栏位设置只读
WfForm.changeFieldAttr(WfForm.convertFieldNameToId("qtcc","detail_1")+"_"+rowIndex, 1);//全天差栏位设置只读
WfForm.changeFieldAttr(WfForm.convertFieldNameToId("btcc","detail_1")+"_"+rowIndex, 1);//半天差栏位设置只读
break;
case '3'://按时间长度出差
WfForm.changeFieldAttr(WfForm.convertFieldNameToId("ccsc","detail_1")+"_"+rowIndex, 3);//出差时长栏位设置必填
WfForm.changeFieldAttr(WfForm.convertFieldNameToId("qtcc","detail_1")+"_"+rowIndex, 1);//全天差栏位设置只读
WfForm.changeFieldAttr(WfForm.convertFieldNameToId("btcc","detail_1")+"_"+rowIndex, 1);//半天差栏位设置只读
break;
default://其他全天或者半天出差
WfForm.changeFieldAttr(WfForm.convertFieldNameToId("ccsc","detail_1")+"_"+rowIndex, 1);//出差时长栏位设置只读
WfForm.changeFieldAttr(WfForm.convertFieldNameToId("qtcc","detail_1")+"_"+rowIndex, 2);//全天差栏位设置可编辑
WfForm.changeFieldAttr(WfForm.convertFieldNameToId("btcc","detail_1")+"_"+rowIndex, 2);//半天差栏位设置可编辑
break;
}
}
}
}
/**
* 计算明细总出差长度
*/
function getTotalsc(){
var ccsd = WfForm.getFieldValue(WfForm.convertFieldNameToId("ccsd"));
var totalsc = 0;
var rowArr = WfForm.getDetailAllRowIndexStr("detail_1").split(",");
for(var i=0; i<rowArr.length; i++){
var rowIndex = rowArr[i];
if(rowIndex !== ""){
if (ccsd == '3' || ccsd == '1')//累计小时时长
totalsc = Number(totalsc) + Number(WfForm.getFieldValue(WfForm.convertFieldNameToId("ccsc", "detail_1")+"_"+rowIndex));
else{
//累计天数时长
totalsc = Number(totalsc) +
Number(WfForm.getFieldValue(WfForm.convertFieldNameToId("qtcc", "detail_1")+"_"+rowIndex)) +
Number(WfForm.getFieldValue(WfForm.convertFieldNameToId("btcc", "detail_1")+"_"+rowIndex)) * 0.5;
}
}
}
return totalsc;
}
//依据当前出差方式,对页面上的控件显示属性进行调整
resetAttr(WfForm.getFieldValue(WfForm.convertFieldNameToId("ccsd")));
//是否自动产生明细记录标记
//考虑到影响明细记录的栏位如开始结束日期时间等发生变更时,需要重新生成明细,而出差方式变更时又需要对相应栏位的值做修改,所以添加这个开关,防止重复生成明细记录
var autodetail = true;
//差期类别值变更时,自动生成明细
WfForm.bindFieldChangeEvent(WfForm.convertFieldNameToId("cclx"),function(obj,id,value){
//关掉自动生成明细记录功能
autodetail = false;
//自动添加出差明细数据
adddetail();
//打开自动生成明细记录功能
autodetail = true;
});
//出差人员值变更时,自动生成明细
WfForm.bindFieldChangeEvent(WfForm.convertFieldNameToId("ccr"),function(obj,id,value){
//关掉自动生成明细记录功能
autodetail = false;
//自动添加出差明细数据
adddetail();
//打开自动生成明细记录功能
autodetail = true;
});
//出差方式变更时,同样进行页面显示属性的调整
WfForm.bindFieldChangeEvent(WfForm.convertFieldNameToId("ccsd"),function(obj,id,value){
//关掉自动生成明细记录功能
autodetail = false;
//出差方式变更后,修改页面上的控件显示属性
resetAttr(value);
//自动添加出差明细数据
adddetail();
//打开自动生成明细记录功能
autodetail = true;
});
//是否每日重复时间段值变更时,自动生成明细
WfForm.bindFieldChangeEvent(WfForm.convertFieldNameToId("mttsdcc"),function(obj,id,value){
//关掉自动生成明细记录功能
autodetail = false;
//自动添加出差明细数据
adddetail();
//打开自动生成明细记录功能
autodetail = true;
});
//开始日期变更后,自动重新生成明细
WfForm.bindFieldChangeEvent(WfForm.convertFieldNameToId("ksrq"),function(obj,id,value){
if (autodetail){
autodetail = false;
adddetail();
autodetail = true;
}
});
//结束日期变更后,自动重新生成明细
WfForm.bindFieldChangeEvent(WfForm.convertFieldNameToId("jsrq"),function(obj,id,value){
if (autodetail){
autodetail = false;
adddetail();
autodetail = true;
}
});
//开始时间变更后,自动重新生成明细
WfForm.bindFieldChangeEvent(WfForm.convertFieldNameToId("kssj"),function(obj,id,value){
if (autodetail){
autodetail = false;
adddetail();
autodetail = true;
}
});
//结束时间变更后,自动重新生成明细
WfForm.bindFieldChangeEvent(WfForm.convertFieldNameToId("jssj"),function(obj,id,value){
if (autodetail){
autodetail = false;
adddetail();
autodetail = true;
}
});
//出差时长发生变更后,自动重新生成明细
WfForm.bindFieldChangeEvent(WfForm.convertFieldNameToId("ccsc"),function(obj,id,value){
if (autodetail){
autodetail = false;
adddetail();
autodetail = true;
}
});
//绑定全天差栏位值变更事件
jQuery(document).ready(function(){
WfForm.bindDetailFieldChangeEvent(WfForm.convertFieldNameToId("qtcc", "detail_1"),function(id,rowIndex,value){
if (autodetail){
autodetail = false;
if (value === '0')
WfForm.changeFieldValue(WfForm.convertFieldNameToId("btcc", "detail_1")+"_"+rowIndex, {value:"1"});
else
WfForm.changeFieldValue(WfForm.convertFieldNameToId("btcc", "detail_1")+"_"+rowIndex, {value:"0"});
var totalsc = getTotalsc();
WfForm.changeFieldValue(WfForm.convertFieldNameToId("ccsc"), {value:totalsc});
autodetail = true;
}
});
});
//绑定半天差值变更事件
jQuery(document).ready(function(){
WfForm.bindDetailFieldChangeEvent(WfForm.convertFieldNameToId("btcc", "detail_1"),function(id,rowIndex,value){
if (autodetail){
autodetail = false;
if (value === '0')
WfForm.changeFieldValue(WfForm.convertFieldNameToId("qtcc", "detail_1")+"_"+rowIndex, {value:"1"});
else
WfForm.changeFieldValue(WfForm.convertFieldNameToId("qtcc", "detail_1")+"_"+rowIndex, {value:"0"});
var totalsc = getTotalsc();
WfForm.changeFieldValue(WfForm.convertFieldNameToId("ccsc"), {value:totalsc});
autodetail = true;
}
});
});
//绑定出差时长栏位值变更事件
jQuery(document).ready(function(){
WfForm.bindDetailFieldChangeEvent(WfForm.convertFieldNameToId("qjsc", "detail_1"),function(id,rowIndex,value){
if (autodetail){
autodetail = false;
var totalsc = getTotalsc();
WfForm.changeFieldValue(WfForm.convertFieldNameToId("qjsc"), {value:totalsc});
autodetail = true;
}
});
});
WfForm.registerCheckEvent(WfForm.OPER_SAVE+","+WfForm.OPER_SUBMIT,function(callback){
var d_count = WfForm.getDetailRowCount("detail_1");
if (Number(d_count) === 0){
alert("没有出差明细,不能继续!")
}else{
callback();
}
});
</script>