QC2135695 沃格考勤后端源码改造pc4backstage/hrmAttendance
This commit is contained in:
parent
f1eee8f0d4
commit
1f271494e6
|
|
@ -11,6 +11,7 @@ import {DialogStore,SearchStore} from '../public/valhalla/stores/index.js';
|
|||
import isEmpty from 'lodash/isEmpty';
|
||||
import cloneDeep from 'lodash/cloneDeep';
|
||||
import {addContentPath} from '../util/index.js'
|
||||
import uuid from 'uuid';
|
||||
const getLabel = WeaLocaleProvider.getLabel;
|
||||
|
||||
const { TableStore } = WeaTableNew;
|
||||
|
|
@ -23,6 +24,7 @@ export class HrmShiftManager extends HrmBaseStore {
|
|||
rightMenus = [];
|
||||
worktimeError = false;//message.error(i18n.label["388878"]());
|
||||
resttimeError = false;//message.error(i18n.label["388878"]());
|
||||
resttimeRangeError = false;
|
||||
sTime = ["09:00", "13:00", "19:00"];
|
||||
eTime = ["12:00", "18:00", "23:00"];
|
||||
ruleOptions = [];
|
||||
|
|
@ -145,7 +147,7 @@ export class HrmShiftManager extends HrmBaseStore {
|
|||
punchsettings: (field, textAreaProps, form, formParams) => null,
|
||||
isresttimeopen: (field, textAreaProps, form, formParams) => {
|
||||
const { fieldMap } = form;//mins_next
|
||||
if (formParams.shiftonoffworkcount === "1") {
|
||||
if (true/*formParams.shiftonoffworkcount === "1"*/) {
|
||||
return (
|
||||
<div className="cust">
|
||||
<WeaSwitch ecId={`${this && this.props && this.props.ecId || ''}_WeaSwitch@bhw6l0`}
|
||||
|
|
@ -154,7 +156,7 @@ export class HrmShiftManager extends HrmBaseStore {
|
|||
formParams={formParams}
|
||||
onChange={v => this.calculateWorkTime()}
|
||||
/>
|
||||
{formParams.isresttimeopen === "1" && (
|
||||
{/* {formParams.isresttimeopen === "1" && (
|
||||
<div className="child">
|
||||
<div className="lbl">{fieldMap["restbeigin"].label}</div>
|
||||
<div className="restTime">
|
||||
|
|
@ -198,7 +200,7 @@ export class HrmShiftManager extends HrmBaseStore {
|
|||
<div className="restTimeInfo">{i18n.label["388785"]()}</div>
|
||||
}
|
||||
</div>
|
||||
)}
|
||||
)} */}
|
||||
</div>
|
||||
);
|
||||
} else {
|
||||
|
|
@ -956,13 +958,13 @@ export class HrmShiftManager extends HrmBaseStore {
|
|||
childrenComponents = {
|
||||
shiftonoffworkcount: () => {
|
||||
const formParams = this.formTarget.baseForm.getFormParams();
|
||||
if (formParams.shiftonoffworkcount != "1") {
|
||||
/*if (formParams.shiftonoffworkcount != "1") {
|
||||
this.formTarget.baseForm.updateFields({
|
||||
isresttimeopen: {
|
||||
value: "0"
|
||||
}
|
||||
});
|
||||
}
|
||||
}*/
|
||||
let coms = [], worktimes = this.toJS(this.worktimes);
|
||||
if (worktimes.length === 0) return [];
|
||||
for (let i = 1; i <= Number(formParams.shiftonoffworkcount); i++) {
|
||||
|
|
@ -1104,6 +1106,90 @@ export class HrmShiftManager extends HrmBaseStore {
|
|||
}
|
||||
];
|
||||
},
|
||||
isresttimeopen: () => {
|
||||
const formParams = this.formTarget.baseForm.getFormParams();
|
||||
const { fieldMap } = this.formTarget.baseForm;
|
||||
if (formParams.isresttimeopen != "1") {
|
||||
return [];
|
||||
}
|
||||
const coms = [];
|
||||
this.toJS(this.restTimeCollection).forEach((d, index) => {
|
||||
console.debug(d)
|
||||
const {record, start, end} = d;
|
||||
const {time: sTime = '12:00', accross: sAccross} = start || {};
|
||||
const {time: eTime, accross: eAccross} = end || {};
|
||||
coms.push(
|
||||
<WeaFormItem
|
||||
label={`${fieldMap['isresttimeopen'].label}${index + 1}`}
|
||||
labelCol={{ span: this.custLabelCol }}
|
||||
wrapperCol={{ span: 24 - this.custLabelCol }}
|
||||
>
|
||||
<div className="cust">
|
||||
<div className="child">
|
||||
<div className="lbl">{fieldMap["restbeigin"].label}</div>
|
||||
<div className="restTime">
|
||||
<WeaError tipPosition='bottom'
|
||||
ref={d => this.errRefs[`restbeigin${index}`] = d}
|
||||
error={`"${fieldMap["restbeigin"].label}" ${i18n.message.dataEmpty()}`}>
|
||||
<WeaTimePicker
|
||||
value={sTime}
|
||||
onChange={v => {
|
||||
this.restTimeCollection[index].start.time = v;
|
||||
this.calculateWorkTime();
|
||||
}
|
||||
}
|
||||
/>
|
||||
</WeaError>
|
||||
</div>
|
||||
{
|
||||
sAccross == '1' &&
|
||||
<div className="restTimeInfo">{i18n.label["388785"]()}</div>
|
||||
}
|
||||
</div>
|
||||
<div className="child">
|
||||
<div className="lbl">{fieldMap["restend"].label}</div>
|
||||
<div className="restTime">
|
||||
<WeaError tipPosition='bottom'
|
||||
ref={d => this.errRefs[`restend${index}`] = d}
|
||||
error={`"${fieldMap["restend"].label}" ${i18n.message.dataEmpty()}`}>
|
||||
<WeaTimePicker
|
||||
value={eTime}
|
||||
onChange={v =>{
|
||||
this.restTimeCollection[index].end.time = v;
|
||||
this.calculateWorkTime();
|
||||
}
|
||||
}
|
||||
/>
|
||||
</WeaError>
|
||||
</div>
|
||||
{
|
||||
eAccross == '1' &&
|
||||
<div className="restTimeInfo">{i18n.label["388785"]()}</div>
|
||||
}
|
||||
</div>
|
||||
<div className="child">
|
||||
<a onClick={() => this.deleteRest(index)}>
|
||||
{i18n.label.delete()}
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</WeaFormItem>
|
||||
);
|
||||
})
|
||||
coms.push(
|
||||
(
|
||||
<div className="addRule">
|
||||
<a onClick={() => this.onAddrest()}>{i18n.label["388877"]()}</a>
|
||||
</div>
|
||||
)
|
||||
)
|
||||
return [
|
||||
{
|
||||
com: <div>{coms}</div>,
|
||||
col: 1
|
||||
}
|
||||
];
|
||||
},
|
||||
earlyinearlyout: () => {
|
||||
const formParams = this.formTarget.settingForm.getFormParams();
|
||||
let coms = [];
|
||||
|
|
@ -1530,6 +1616,8 @@ export class HrmShiftManager extends HrmBaseStore {
|
|||
};
|
||||
|
||||
@observable timeErrorType = 1;
|
||||
|
||||
@observable restTimeCollection = [];
|
||||
/********************* observable list *********************/
|
||||
|
||||
/********************* computed list *********************/
|
||||
|
|
@ -1544,6 +1632,21 @@ export class HrmShiftManager extends HrmBaseStore {
|
|||
/********************* computed list *********************/
|
||||
|
||||
/********************* action list *********************/
|
||||
@action onAddrest = () => {
|
||||
this.restTimeCollection.push({
|
||||
record: uuid(),
|
||||
start: {time: '', accross: '0'},
|
||||
end: {time: '', accross: '0'}
|
||||
});
|
||||
|
||||
this.calculateWorkTime();
|
||||
}
|
||||
|
||||
@action deleteRest = index => {
|
||||
this.restTimeCollection.splice(index, 1);
|
||||
this.calculateWorkTime();
|
||||
}
|
||||
|
||||
setRuleOptions = () => {
|
||||
this.ruleOptions.length = 0;
|
||||
for (let i = 0; i < 10; i++) {
|
||||
|
|
@ -1663,6 +1766,7 @@ export class HrmShiftManager extends HrmBaseStore {
|
|||
this.processCondition(data);
|
||||
this.canAdd = data.canAdd;
|
||||
this.shift_24 = data.shift_24 || 0;
|
||||
this.restTimeCollection = data.restTimeSections;
|
||||
this.setFormData("baseForm", data.condition);
|
||||
if (this.formTarget.baseForm.isFormInit) {
|
||||
callback && callback();
|
||||
|
|
@ -1865,6 +1969,30 @@ export class HrmShiftManager extends HrmBaseStore {
|
|||
return this.restTimeSections[1].across == '1';
|
||||
}
|
||||
|
||||
checkRestTimeCollection = (times) => {
|
||||
this.resttimeRangeError = false;
|
||||
if(times.length <= 1)
|
||||
return this.resttimeRangeError;
|
||||
const obj = times.reduce((current, next) => {
|
||||
const {s, e} = next;
|
||||
current.start.push(s.format('YYYY-MM-DD HH:mm:ss'));
|
||||
current.end.push(e.format('YYYY-MM-DD HH:mm:ss'));
|
||||
return current;
|
||||
}, {start: [], end: []});
|
||||
let {start, end} = obj;
|
||||
start = start.sort();
|
||||
end = end.sort();
|
||||
|
||||
for(let i = 1; i < start.length; i++){
|
||||
if (start[i] <= end[i - 1]){
|
||||
message.error(getLabel('523624','休息时间不能重叠'));
|
||||
this.resttimeRangeError = true;
|
||||
}
|
||||
}
|
||||
|
||||
return this.resttimeRangeError;
|
||||
}
|
||||
|
||||
calculateWorkTime = () => {
|
||||
this.resttimeError = false;
|
||||
this.timeRange = 0;
|
||||
|
|
@ -1873,81 +2001,96 @@ export class HrmShiftManager extends HrmBaseStore {
|
|||
minute = 0;
|
||||
try {
|
||||
const d = this.toJS(this.worktimes);
|
||||
if (d.length === 1) {
|
||||
let record = d[0];
|
||||
let firstS;
|
||||
let lastE;
|
||||
d.map((record, i) => {
|
||||
let s = this.convertTimeToMoment(record.start.times),
|
||||
e = this.convertTimeToMoment(record.end.times);
|
||||
if (record.start.across === '1' && record.end.across === '1') {
|
||||
} else if (record.end.across === '1') {
|
||||
i == 0 && (firstS = s);
|
||||
if (record.start.across === "1" && record.end.across === "1") {
|
||||
} else if (record.end.across === "1") {
|
||||
e.add(1, "d");
|
||||
}
|
||||
minute = Math.abs(s.diff(e, "m"));
|
||||
if (formParams.isresttimeopen === "1") {
|
||||
i == d.length - 1 && (lastE = e);
|
||||
minute += Math.abs(s.diff(e, "m"));
|
||||
});
|
||||
if (formParams.isresttimeopen === "1") {
|
||||
const times = [];
|
||||
const wst = this.convertTimeToMoment(this.worktimes[0].start.times),
|
||||
wet = this.convertTimeToMoment(this.worktimes[this.worktimes.length - 1].end.times);
|
||||
if(this.worktimes[this.worktimes.length - 1].end.across == '1')
|
||||
wet.add(1, 'd');
|
||||
|
||||
this.restTimeCollection = this.toJS(this.restTimeCollection).map((d, index) => {
|
||||
const {start, end} = d;
|
||||
const {time: restbeigin = ''} = start || {};
|
||||
const {time: restend = ''} = end || {};
|
||||
let sAcross = '0', eAcross = '0';
|
||||
const { restbeigin, restend } = formParams;
|
||||
if (restbeigin != "" && restend != "") {
|
||||
const rst = this.convertTimeToMoment(restbeigin),
|
||||
ret = this.convertTimeToMoment(restend),
|
||||
wst = this.convertTimeToMoment(this.worktimes[0].start.times),
|
||||
wet = this.convertTimeToMoment(this.worktimes[0].end.times);
|
||||
this.worktimes[0].end.across === '1' && wet.add(1, "d");
|
||||
if(rst.isBefore(wst)){
|
||||
sAcross = '1';
|
||||
rst.add(1, 'd');
|
||||
ret.add(1, 'd');
|
||||
}
|
||||
if(ret.isBefore(rst)){
|
||||
eAcross = '1';
|
||||
ret.add(1, 'd');
|
||||
ret = this.convertTimeToMoment(restend);
|
||||
|
||||
if(index != 0){
|
||||
let lastRecord = this.restTimeCollection[index - 1];
|
||||
let le = this.convertTimeToMoment(lastRecord.end.time);
|
||||
d.start.accross = rst.isBefore(le) ? '1' : lastRecord.end.across;
|
||||
}else{
|
||||
d.start.accross = rst.isBefore(wst) ? '1' : '0';
|
||||
}
|
||||
d.end.accross = ret.isBefore(rst) ? '1' : d.start.accross;
|
||||
|
||||
console.debug(d)
|
||||
|
||||
d.start.accross == '1' && rst.add(1, 'd');
|
||||
d.end.accross == '1' && ret.add(1, 'd');
|
||||
|
||||
times.push({s: rst, e: ret});
|
||||
|
||||
if (
|
||||
rst.isBefore(wst) ||
|
||||
rst.isAfter(wet) ||
|
||||
ret.isBefore(wst) ||
|
||||
ret.isAfter(wet) ||
|
||||
rst.isSame(ret)
|
||||
) {
|
||||
){
|
||||
this.resttimeError = true;
|
||||
} else {
|
||||
if (ret.isBefore(rst)) ret.add(1, "d");
|
||||
message.error('休息时间不在工作时段内');
|
||||
|
||||
if(!rst.isSame(ret)) {
|
||||
this.toJS(this.worktimes).forEach((worktime) => {
|
||||
const s = this.convertTimeToMoment(worktime.start.times);
|
||||
worktime.start.across == '1' && s.add(1, 'd');
|
||||
|
||||
const e = this.convertTimeToMoment(worktime.end.times);
|
||||
worktime.end.across == '1' && e.add(1, 'd');
|
||||
|
||||
let ts = rst, te = ret;
|
||||
if(ts.isBefore(s))
|
||||
ts = s;
|
||||
else if(ts.isAfter(e)){
|
||||
ts = e;
|
||||
}
|
||||
if(te.isAfter(e))
|
||||
te = e;
|
||||
|
||||
minute -= Math.abs(ts.diff(te, "m"));
|
||||
})
|
||||
}
|
||||
}else{
|
||||
minute -= Math.abs(rst.diff(ret, "m"));
|
||||
}
|
||||
this.restTimeSections = [
|
||||
{
|
||||
resttype: "start",
|
||||
time: restbeigin,
|
||||
across: sAcross
|
||||
},
|
||||
{
|
||||
resttype: "end",
|
||||
time: restend,
|
||||
across: (sAcross == '1' ? '1' : eAcross)
|
||||
}
|
||||
];
|
||||
}
|
||||
}
|
||||
this.hour = Math.floor(minute / 60);
|
||||
this.minute = minute % 60;
|
||||
} else {
|
||||
let firstS;
|
||||
let lastE;
|
||||
d.map((record, i) => {
|
||||
let s = this.convertTimeToMoment(record.start.times),
|
||||
e = this.convertTimeToMoment(record.end.times);
|
||||
i == 0 && (firstS = s);
|
||||
if (record.start.across === '1' && record.end.across === '1') {
|
||||
} else if (record.end.across === '1') {
|
||||
e.add(1, "d");
|
||||
}
|
||||
i == (d.length - 1) && (lastE = e);
|
||||
minute += Math.abs(s.diff(e, "m"));
|
||||
return d;
|
||||
});
|
||||
this.hour = Math.floor(minute / 60);
|
||||
this.minute = minute % 60;
|
||||
this.timeRange = Math.abs(firstS.diff(lastE, "m"));
|
||||
this.checkRestTimeCollection(times);
|
||||
}
|
||||
|
||||
this.worktime = minute;
|
||||
} catch (ex) {}
|
||||
this.hour = Math.floor(minute / 60);
|
||||
this.minute = minute % 60;
|
||||
} catch (ex) {
|
||||
console.error(ex)
|
||||
}
|
||||
let result = i18n.label["388788"]().replace("{hour}", hour);
|
||||
result = result.replace("{minute}", minute);
|
||||
return result;
|
||||
|
|
@ -2179,15 +2322,15 @@ export class HrmShiftManager extends HrmBaseStore {
|
|||
const formParams = this.formTarget.baseForm.getFormParams();
|
||||
window.e9HideFormFieldKeys = [];
|
||||
const{shiftonoffworkcount, isresttimeopen, cardRemind,cardRemOfSignIn,cardRemOfSignOut, halfcalrule}=formParams;
|
||||
if (
|
||||
/*if (
|
||||
shiftonoffworkcount != null &&
|
||||
(shiftonoffworkcount != "1" ||
|
||||
(shiftonoffworkcount === "1" &&
|
||||
isresttimeopen &&
|
||||
isresttimeopen != "1"))
|
||||
) {
|
||||
) {*/
|
||||
window.e9HideFormFieldKeys.push(...["restbeigin", "restend"]);
|
||||
}
|
||||
//}
|
||||
if(halfcalrule == '0'){
|
||||
['halfcalpoint','halfcalpoint2cross'].forEach(key=>{
|
||||
window.e9HideFormFieldKeys.push(key);
|
||||
|
|
@ -2237,10 +2380,45 @@ export class HrmShiftManager extends HrmBaseStore {
|
|||
this.spinning = false;
|
||||
return;
|
||||
}
|
||||
if(this.resttimeError){
|
||||
message.error(i18n.label["390303"]());
|
||||
this.spinning = false;
|
||||
return;
|
||||
if(/*shiftonoffworkcount == "1" &&*/ isresttimeopen == '1'){
|
||||
if(this.resttimeError){
|
||||
message.error('休息时间不在工作时段内');
|
||||
this.spinning = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if(this.resttimeRangeError){
|
||||
message.error(getLabel('523624','休息时间不能重叠'));
|
||||
this.spinning = false;
|
||||
return;
|
||||
}
|
||||
// if(this.resttimeError){
|
||||
// message.error(i18n.label["390303"]());
|
||||
// this.spinning = false;
|
||||
// return;
|
||||
// }
|
||||
|
||||
const arr = this.toJS(this.restTimeCollection);
|
||||
if(arr.length == 0){
|
||||
message.error(getLabel('523634','请设置休息时间'));
|
||||
this.spinning = false;
|
||||
return;
|
||||
}
|
||||
|
||||
const rIndex = [];
|
||||
arr.map((d, i) => {
|
||||
const {start, end} = d;
|
||||
const {time: restbeigin = ''} = start || {};
|
||||
const {time: restend = ''} = end || {};
|
||||
const flag = (restbeigin == '' || restend == '');
|
||||
flag && rIndex.push(i);
|
||||
restbeigin == '' && this.errRefs[`restbeigin${i}`] && this.errRefs[`restbeigin${i}`].showError();
|
||||
restend == '' && this.errRefs[`restend${i}`] && this.errRefs[`restend${i}`].showError();
|
||||
})
|
||||
if(rIndex.length > 0){
|
||||
this.spinning = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
if(halfcalrule == '1'){
|
||||
const {halfcalpoint, halfcalpoint2cross} = data;
|
||||
|
|
@ -2256,7 +2434,10 @@ export class HrmShiftManager extends HrmBaseStore {
|
|||
}
|
||||
}
|
||||
|
||||
data.restTimeSections = this.toJS(this.restTimeSections);
|
||||
// data.restTimeSections = this.toJS(this.restTimeSections);
|
||||
data.restTimeSections = this.toJS(this.restTimeCollection).map((d, i) => {
|
||||
return {...d, orderId: i}
|
||||
});
|
||||
|
||||
const params = { data: JSON.stringify(data) };
|
||||
api.saveShiftManagementBaseForm(params).then(
|
||||
|
|
@ -2313,7 +2494,8 @@ export class HrmShiftManager extends HrmBaseStore {
|
|||
this.canAdd = data.canAdd;
|
||||
this.shift_24 = data.shift_24 || 0;
|
||||
this.setFormData("baseForm", data.condition);
|
||||
workSections = data.workSections;
|
||||
workSections = data.workSections || [];
|
||||
this.restTimeCollection = data.restTimeSections
|
||||
break;
|
||||
case 1:
|
||||
data.condition[0].items.map(item => (item.colSpan = 2));
|
||||
|
|
|
|||
Loading…
Reference in New Issue