优化代码

This commit is contained in:
wuxw 2022-09-09 00:04:08 +08:00
parent 11463fd329
commit 9963e1667e
3 changed files with 100 additions and 38 deletions

View File

@ -15,13 +15,17 @@
conditions: {
classesName: '',
departmentName: '',
date: vc.dateFormat(new Date())
date: ''
}
}
},
_initMethod: function () {
vc.component._listMonthAttendances(DEFAULT_PAGE, DEFAULT_ROWS);
vc.component._initDate();
let _date = new Date(new Date());
$that.monthAttendanceManageInfo.conditions.date = _date.getFullYear()+"-"+(_date.getMonth() + 1);
vc.initDateMonth('queryDate',function(_value){
$that.monthAttendanceManageInfo.conditions.date = _value;
})
},
_initEvent: function () {
vc.on('monthAttendanceManage', 'listMonthAttendance', function (_param) {
@ -32,35 +36,15 @@
});
},
methods: {
_initDate: function () {
$(".queryDate").datetimepicker({
language: 'zh-CN',
fontAwesome: 'fa',
format: 'yyyy-mm-dd',
minView: "month",
initialDate: new Date(),
autoClose: 1,
todayBtn: true
});
$('.queryDate').datetimepicker()
.on('changeDate', function (ev) {
var value = $(".queryDate").val();
vc.component.monthAttendanceManageInfo.conditions.date = value;
});
//防止多次点击时间插件失去焦点
document.getElementsByClassName(' form-control queryDate')[0].addEventListener('click', myfunc)
function myfunc(e) {
e.currentTarget.blur();
}
},
_listMonthAttendances: function (_page, _rows) {
vc.component.monthAttendanceManageInfo.conditions.page = _page;
vc.component.monthAttendanceManageInfo.conditions.row = _rows;
var param = {
let param = {
params: vc.component.monthAttendanceManageInfo.conditions
};
param.params.classesName = param.params.classesName.trim();
param.params.date = param.params.date+"-01";
param.params.departmentName = param.params.departmentName.trim();
//发送get请求
vc.http.apiGet('/attendanceClass/getMonthAttendance',

View File

@ -4,13 +4,13 @@
<div class="margin-xs-r bg-white padding">
<input type="text" :placeholder="vc.i18n('请选择月份','monthAttendanceManage')" v-model="staffAttendanceManageInfo.curDate" class=" form-control queryDate">
</div>
<div class="margin-xs-r bg-white padding">
<div class="margin-xs-r bg-white padding-bottom padding-lr">
<input v-model="staffAttendanceManageInfo.orgName" readonly @focus="_staffAttendanceChangeOrg()" type="text" :placeholder="vc.i18n('必填,请填写组织','staffAttendanceManage')" class="form-control">
</div>
<div class="margin-xs-r bg-white treeview">
<ul class="list-group text-center border-radius">
<!-- :class="{'vc-node-selected':newOaWorkflowInfo.switchValue=='newOaWorkflowPool'}" -->
<li class="list-group-item node-orgTree " v-for="(item,index) in staffAttendanceManageInfo.staffs" @click="swatch(item)">
<!-- -->
<li class="list-group-item node-orgTree " v-for="(item,index) in staffAttendanceManageInfo.staffs" @click="swatchStaff(item)" :class="{'vc-node-selected':staffAttendanceManageInfo.curStaffId==item.userId}">
{{item.name}}
</li>
</ul>
@ -18,11 +18,11 @@
</div>
<div class="col-md-10 ">
<div class="row bg-white border-radius padding">
<div class="col-md-1 text-center border padding-lg" v-for="index in staffAttendanceManageInfo.maxDay" :key="index" :style="{'background-color': _getBgColor(index)}" style="border-radius: 5px;cursor:pointer">
<div class="col-md-2 text-center border padding-lg" v-for="index in staffAttendanceManageInfo.maxDay" :key="index" :style="{'background-color': _getBgColor(index)}" style="border-radius: 5px;cursor:pointer">
<div>{{staffAttendanceManageInfo.curYear}}-{{staffAttendanceManageInfo.curMonth}}-{{index}}</div>
<div>考勤状态:{{_getAttendanceState(index)}}</div>
<div>考勤时间:</div>
<div>考勤时间:</div>
<div>状态:
<span v-html="_getAttendanceState(index)"></span></div>
<div v-for="(item,detailIndex) in _getAttendanceDetail(index)">{{item.specName}}{{item.stateName}}{{item.checkTime}}</div>
</div>
</div>
</div>

View File

@ -8,12 +8,14 @@
data: {
staffAttendanceManageInfo: {
staffs: [],
attendances:[],
classesId: '',
orgId: '',
orgName: '',
curDate: vc.dateFormat(new Date()),
curDate: '',
curYear: '',
curMonth: '',
curStaffId:'',
maxDay: '',
}
},
@ -22,12 +24,17 @@
$that.initStaffDate();
},
_initEvent: function() {
vc.on('monthAttendanceManage', 'listMonthAttendance', function(_param) {
vc.on('staffAttendanceManage', 'listMonthAttendance', function(_param) {
vc.component._listMonthAttendances(DEFAULT_PAGE, DEFAULT_ROWS);
});
vc.on('pagination', 'page_event', function(_currentPage) {
vc.component._listMonthAttendances(_currentPage, DEFAULT_ROWS);
});
vc.on('staffAttendanceManage', 'switchOrg', function(_org) {
$that.staffAttendanceManageInfo.orgId = _org.orgId;
$that.staffAttendanceManageInfo.orgName = _org.allOrgName;
$that._loadStaffs();
});
},
methods: {
_loadStaffs: function() {
@ -46,6 +53,11 @@
let staffList = _staffInfo.staffs;
$that.staffAttendanceManageInfo.staffs = staffList;
if(staffList && staffList.length>0){
$that.staffAttendanceManageInfo.curStaffId = staffList[0].userId;
$that._loadStaffAttendances();
}
},
function() {
console.log('请求失败处理');
@ -53,13 +65,48 @@
);
},
initStaffDate: function() {
let _date = new Date($that.staffAttendanceManageInfo.curDate);
let _date = new Date(new Date());
$that.staffAttendanceManageInfo.curMonth = _date.getMonth() + 1
$that.staffAttendanceManageInfo.curYear = _date.getFullYear();
$that.staffAttendanceManageInfo.curDate = _date.getFullYear()+"-"+(_date.getMonth() + 1);
$that.staffAttendanceManageInfo.maxDay = new Date(_date.getFullYear(), _date.getMonth() + 1, 0).getDate();
},
_getAttendanceState: function() {
vc.initDateMonth('queryDate',function(_value){
$that.staffAttendanceManageInfo.curDate = _value;
$that._loadStaffAttendances();
})
},
_getAttendanceState: function(_day) {
let _attendance = $that._getDayAttendance(_day);
if(!_attendance){
return "<span style='color:rgb(220, 53, 69)'>未考勤</span>";
}
return "<span style='color:rgb(18, 150, 219)'>"+_attendance.stateName+"</span>";
},
_getAttendanceDetail:function(_day){
let _attendance = $that._getDayAttendance(_day);
if(!_attendance){
return [];
}
return _attendance.attendanceClassesTaskDetails;
},
_getDayAttendance:function(_day){
let _attendance = null;
if(!$that.staffAttendanceManageInfo.attendances){
return _attendance;
}
$that.staffAttendanceManageInfo.attendances.forEach(item => {
if(item.taskDay == _day){
_attendance = item;
}
});
return _attendance;
},
_getBgColor: function(_curDay) {
@ -67,7 +114,38 @@
},
_staffAttendanceChangeOrg: function() {
vc.emit('chooseOrgTree', 'openOrgModal', {});
},
swatchStaff:function(_staff){
$that.staffAttendanceManageInfo.curStaffId = _staff.userId;
$that._loadStaffAttendances();
},
_loadStaffAttendances:function(){
if( !$that.staffAttendanceManageInfo.curStaffId){
return ;
}
if( !$that.staffAttendanceManageInfo.curDate){
return ;
}
let param = {
params:{
page:1,
row:1000,
date:$that.staffAttendanceManageInfo.curDate,
staffId: $that.staffAttendanceManageInfo.curStaffId
}
};
//发送get请求
vc.http.apiGet('/attendanceClass/queryAttendanceClassesTask',
param,
function(json, res) {
var _todayAttendanceManageInfo = JSON.parse(json);
vc.component.staffAttendanceManageInfo.attendances = _todayAttendanceManageInfo.data;
},
function(errInfo, error) {
console.log('请求失败处理');
}
);
}
}
});