/**
* 排班管理
* */
var nowDate = helper.DateFormat.getNowDate();
var selectedDays = []; //选中的日期
// var selectedDays = []; //选中的日期
var myCalendar = null; //日历对象
//日历配置信息
var options = {
width: '100%',
height: '450px',
language: 'CH', //语言
showLunarCalendar: true, //阴历
showHoliday: true, //休假
showFestival: true, //节日
showLunarFestival: true, //农历节日
showSolarTerm: true, //节气
showMark: true, //标记
mark: {
// '2018-12-20': '班',
// '2018-12-22': '班'
},
timeRange: {
startYear: 1900,
endYear: 2049
},
theme: {
changeAble: false,
weeks: {
backgroundColor: '#FBEC9C',
fontColor: '#4A4A4A',
fontSize: '20px',
},
days: {
backgroundColor: '#ffffff',
fontColor: '#565555',
fontSize: '24px'
},
todaycolor: 'orange',
activeSelectColor: 'orange',
},
//获取点击的日期
onSelect: function(day) {
// console.log('onSelect..........................');
var selectDay = helper.DateFormat.timestampToTime(Number(day)).substring(0, 10);
selectedDays.push(selectDay);
selectedDays = helper.methods.unique(selectedDays); //去重
initTable();
},
unSelect: function(day) {
// console.log('unSelect..........................');
var unSelectDay = helper.DateFormat.timestampToTime(Number(day)).substring(0, 10);
if (selectedDays && selectedDays.length > 0) {
for (var i = 0; i < selectedDays.length; i++) {
if (selectedDays[i] === unSelectDay) {
selectedDays.splice(i, 1);
break;
}
}
}
initTable();
},
}
$(function() {
$('.tool_bars').authorizeButton();
myCalendar = new SimpleCalendar('#calendar', options);
//项目下拉
helper.getDropList.getProlistDrop($('#sc_pro')).then(function() {
$('#sc_pro').on('change', function() {
init();
});
});
init();
$('#HY_save').on('click', btn_save);
// //搜索
// $("#sc_btns").click(function() {
// init();
// });
});
function init() {
// console.log(selectedDays)
selectedDays = [nowDate];
getMarks().then(function(){
$('#calendar').find('.sc-today').addClass('sc-selected');
initTable(); //获取人员列表
}); //获取排班
}
//获取排班标记
function getMarks() {
var dtd = $.Deferred(); //在函数内部,新建一个Deferred对象
$.ajax({
type: "get",
url: huayi.config.callcenter_url + "signtokenapi/api/ClassGroupUser/getusergroupmarker",
dataType: 'json',
async: true,
data: {
projectid: $('#sc_pro').val(), // 否 string 项目id
},
success: function(data) {
var res = data.data;
if(res) {
addSchedulingMarks(res.dateList_normal);
addSchedulingMarks(res.dateList_rest);
addSchedulingMarks(res.dateList_eave);
}
dtd.resolve(res); // 改变Deferred对象的执行状态
}
});
return dtd.promise(); // 返回promise对象
};
//添加标记
function addSchedulingMarks(res){
if(res && res.length > 0){
for (var i = 0; i < res.length; i++) {
if(res[i]){
myCalendar.addMark(res[i], '已排班');
}
}
}
}
//初始化人员列表
function initTable() {
var select_listday = selectedDays;
if(select_listday && select_listday.length){
select_listday = select_listday[select_listday.length-1];
}else{
select_listday = '';
}
$.ajax({
url: huayi.config.callcenter_url + 'signtokenapi/api/ClassGroupUser/getusergrouplist',
type: 'get',
data: {
projectid: $('#sc_pro').val(), // 否 string 项目id
// usercode: $('#sc_key').val(), // 否 string 用户账号
// listday: selectedDays ? selectedDays.join(',') : '', //否 string 选中的日期
listday: select_listday, //否 string 选中的日期
},
dataType: "json",
async: true,
success: function(res) {
if (res.state.toLowerCase() === 'success') {
//异步获取数据
var resultData = res.data;
$('#table_all').bootstrapTable('load', resultData);
} else {
layer.confirm(res.message, {
icon: 7,
btn: ['确定'] //按钮
});
}
}
});
$('#table_all').bootstrapTable('destroy').bootstrapTable({
striped: true
});
}
//格式化编号
function setCode(val, row, index) {
return index + 1;
}
//格式化姓名
function formatterName(val, row) {
return '' + val + '(' + row.usercode + ')';
}
//格式化出勤状态
function formatterIsstatusList(val, row) {
var str = '';
var isCheck = '';
var spanClass = '';
if (val) {
str += '
';
for (var i = 0; i < val.length; i++) {
if (val[i].EnumValue === 1) {
spanClass = 'text_normal';
} else if (val[i].EnumValue === 2) {
spanClass = 'text_rest';
} else {
spanClass = 'text_leave';
}
isCheck = row.isstatus_class === val[i].EnumValue ? 'checked' : '';
str += '
';
}
str += '
';
}
return str;
}
//出勤状态 切换事件函数
function statusChange(val, rid) {
//1正常 2休息 3请假
if (val === 1) {
$('#classBan_' + rid).show(); //班别
if($('#planList_' + rid).find('input[type="checkbox"]')[0].checked) {
$('#planList_' + rid).show(); //计划
}
} else {
$('#classBan_' + rid).hide(); //班别
$('#classBan_' + rid).find('input[type="checkbox"]').prop('checked', false);
$('#planList_' + rid).hide(); //计划
$('#planList_' + rid).find('input[type="checkbox"]').prop('checked', false);
$('#isJoin_' + rid).prop('checked', false); //是否参与计划
}
}
//格式化班别
function formatterClassBan(val, row) {
var str = '';
var isCheck = '';
var isRadioCheck = '';
var isShow = row.isstatus_class === 1 ? '' : 'isShow';
str += '';
if (val) {
$.each(val, function(i, v) {
var cobj = {
"code": v.code, //班次编号
"name": v.name, //班次名称
"roleList": [],
}
if (v.roleList) {
$.each(v.roleList, function(j, n) {
cobj.roleList.push({
"roleid": n.roleid, //角色id
"rolecode": n.rolecode, //角色code
"rolename": n.rolename, //角色名称
"ischeck": n.ischeck // 是否选中
});
});
}
isCheck = v.ischeck ? 'checked' : '';
str += '- ' +
'';
if (v.roleList) {
str += '
';
$.each(v.roleList, function(j, n) {
// debugger
var roleItem = {
"roleid": n.roleid, //角色id
"rolecode": n.rolecode, //角色code
"rolename": n.rolename, //角色名称
"ischeck": n.ischeck //是否选中
};
// str += '
' + n.rolename + '
';
isRadioCheck = n.ischeck === true ? 'checked' : '';
str += '
';
});
str += '
';
}
str += ' ';
});
str += '
';
}
return str;
}
//班次下角色改变
function roleChange(index, cIndex, rid){
var dataBan = $('#dataBan_' + index + '_' + rid).attr('data-ban');
var radioVal = $('#roleItem_' + index + '_' + cIndex + '_' + rid).find('input[type="radio"]:checked').val();
dataBan = JSON.parse(dataBan);
radioVal = JSON.parse(radioVal);
if(dataBan.roleList && dataBan.roleList.length > 0){
for(var i = 0; i < dataBan.roleList.length; i++){
if(radioVal.roleid === dataBan.roleList[i].roleid){
dataBan.roleList[i].ischeck = true;
}else{
dataBan.roleList[i].ischeck = false;
}
}
// console.log(JSON.stringify(dataBan));
$('#dataBan_' + index + '_' + rid).attr('data-ban', JSON.stringify(dataBan));
}
}
//格式化是否参与计划
function formatterIsJoin(val, row) {
var isCheck = '';
isCheck = val ? 'checked' : '';
return '';
}
//是否参与计划 切换事件函数
function joinChange(rid) {
//选中代表参与
if (event.target.checked) {
$('#planList_' + rid).show(); //计划
} else {
$('#planList_' + rid).hide(); //计划
$('#planList_' + rid).find('input[type="checkbox"]').prop('checked', false);
}
}
//格式化计划名称
function formatterPlan(val, row) {
var str = '';
var isCheck = '';
var isShow = row.isjoin_class ? '' : 'isShow';
if (val) {
str += ''
$.each(val, function(i, v) {
isCheck = v.ischeck ? 'checked' : '';
var planData = {
"planid": v.id,
"planname": v.planname
}
str += '
' +
'' +
'
';
});
str += '
';
}
return str;
}
//保存
function btn_save() {
var loadIndex;
if (!$.trim($('#sc_pro').val())) {
layer.confirm('请先选择项目名称!', {
icon: 2,
btn: ['确定'] //按钮
});
return;
}
if (!selectedDays) {
layer.confirm('请选择要设置的日期!', {
icon: 2,
btn: ['确定'] //按钮
});
return;
}
var classUserLists = getRowList();
if(classUserLists.valid){
classUserList = classUserLists.data;
}else{
layer.confirm(classUserLists.text, {
icon: 2,
btn: ['确定'] //按钮
});
return;
}
$.ajax({
type: 'post',
url: huayi.config.callcenter_url + 'signtokenapi/api/ClassGroupUser/saveclassuser',
dataType: 'json',
async: true,
beforeSend: function() { //触发ajax请求开始时执行
$('#HY_save').attr("disabled", true);
$('#HY_save').text('保存中...');
loadIndex = layer.load();
},
data: {
projectid: $('#sc_pro').val(), // 是 string 项目名称id
Listday: selectedDays ? selectedDays.join(',') : '', // 是 list 选中日期列表(可能不是连续的日期)
listuserinfo: classUserList, // 是 list 正常值班信息列表 - 每行用户
},
success: function(data) {
layer.close(loadIndex);
if (data.state === "success") {
selectedDays = [];
init();
layer.msg("保存成功");
} else {
$('#HY_save').attr("disabled", false);
$('#HY_save').text('保存');
}
},
error: function(textStatus) {
layer.close(loadIndex);
layer.confirm('网络繁忙,请稍后再试...', {
icon: 7,
closeBtn: 0,
btn: ['确定'] //按钮
});
$('#HY_save').attr("disabled", false);
$('#HY_save').text('保存');
},
complete: function(XMLHttpRequest, textStatus) {
layer.close(loadIndex);
if (textStatus == 'timeout') {
var xmlhttp = window.XMLHttpRequest ? new window.XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHttp");
xmlhttp.abort();
layer.confirm('网络超时,请稍后再试...', {
icon: 7,
closeBtn: 0,
btn: ['确定'] //按钮
});
}
$('#HY_save').attr("disabled", false);
$('#HY_save').text('保存');
},
});
}
//选择日历获取人员列表信息
function getRowList() {
var ids = $.map($('#table_all').bootstrapTable('getSelections'),
function(row) {
return row.id;
});
if (ids && ids.length > 0) {
var classUserList = [];
var valid = true;//验证消息
var text = null;//提示信息
for(var i = 0; i < ids.length; i++){
var usercode = $('#usercode_' + ids[i]).attr('data-code'); //用户账号(AA001)
var isstatus = $('#statusList_' + ids[i]).find('input[type="radio"]:checked').val(); //出勤状态(1正常 2休息 3请假)
var classgroupList = []; //班别数据
if(isstatus === '1'){
var classgroupListEl = $('#classBan_' + ids[i]).find('input[type="checkbox"]:checked'); //班别元素
if(classgroupListEl && classgroupListEl.length > 0){
for(var j = 0; j < classgroupListEl.length; j++){
// console.log($(classgroupListEl[j]).parent().parent().find('input[type="radio"]:checked').length)
if($(classgroupListEl[j]).parent().parent().find('input[type="radio"]:checked').length === 0){
valid = false;
text = '请选择用户:'+ $('#usercode_' + ids[i]).text() + ' '+ $(classgroupListEl[j]).parent().find('.scheduling_check').text() +'的岗位';
break;
}
classgroupList.push(JSON.parse($(classgroupListEl[j]).attr('data-ban')));
}
}else{
valid = false;
text = '请选择用户:'+ $('#usercode_' + ids[i]).text() +'的班别';
break;
}
}
var isjoin = $('#isJoin_' + ids[i])[0].checked; //是 bool 是否参与计划
var distri_planList = []; //计划数据
if(isjoin){
var distri_planListEl = $('#planList_' + ids[i]).find('input[type="checkbox"]:checked');// 是 List List 计划名称
if(distri_planListEl && distri_planListEl.length > 0){
$.each(distri_planListEl, function(j, n){
distri_planList.push(JSON.parse($(n).attr('data-plan')));
});
}else{
valid = false;
text = '请选择用户:'+ $('#usercode_' + ids[i]).text() +'要参与的计划';
break;
}
}
classUserList.push({
usercode: usercode, // 是 string 用户账号(AA001)
isstatus: isstatus, // 是 string 出勤状态(1正常 2休息 3请假)
classgroupList: classgroupList, // 是 List List 绑定班别
isjoin: isjoin, // 是 bool 是否参与计划
distri_planList: distri_planList
});
};
return {
valid: valid,
text: text,
data: classUserList
};
}else{
return {
valid: false,
text: '请选择要排班的用户!',
};
}
}
//设置默认地址
function btn_default(aid) {
layer.confirm('您确定要将当前地址设置为默认地址吗?', {
icon: 7,
btn: ['是', '否'] //按钮
}, function() {
$.ajax({
type: "post",
url: huayi.config.callcenter_url + "distributionapi/api/DistriAddress/UpdateDefault",
dataType: 'json',
data: {
id: aid, //是 string id标识
},
async: true,
success: function(data) {
layer.msg("设置成功!");
$('#table_all').bootstrapTable('refresh');
}
});
});
}
//添加
function btn_add() {
layer.open({
type: 2,
content: "template/addOrEditAddress.html", //iframe的url,no代表不显示滚动条
title: '添加地址',
resize: false,
area: ['60%', '90%'], //宽高
});
}
//编辑
function btn_edit(edit_id) {
layer.open({
type: 2,
content: "template/addOrEditAddress.html?edit_id=" + edit_id, //iframe的url,no代表不显示滚动条
title: '编辑地址',
resize: false,
area: ['60%', '90%'], //宽高
});
}
//批量删除
function btn_deletes() {
var ids = $.map($('#table_all').bootstrapTable('getSelections'),
function(row) {
return row.id;
});
/*判断长度*/
if (ids.length <= 0) {
layer.confirm('请选择要删除的选项', {
icon: 7,
btn: ['确定'] //按钮
});
return;
}
btn_delete(ids);
}
//删除
function btn_delete(del_id) {
/*发送请求*/
layer.confirm('您确定要删除当前地址吗?', {
icon: 7,
btn: ['确定', '取消'],
yes: function(index, layero) {
$.post(huayi.config.callcenter_url + "distributionapi/api/DistriAddress/delete", {
ids: del_id,
}, function(result) {
result = JSON.parse(result);
if (result.state.toLowerCase() == "success") {
layer.msg("删除成功");
$('#table_all').bootstrapTable('refresh');
}
})
},
});
}