jjsp_web/bns/js/dutyTask/schedulingChild/addSchedulingFormStyle.js

221 lines
8.3 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

let weekDateArr = ['周一', '周二', '周三', '周四', '周五', '周六', '周日'];
let personTypeArr = ['省公司带班领导', '建设分公司值班主任', '值长', '副值长', '值班员1', '值班员2', '值班员3', '值班员4', '值班员5', '值班员6', '值班员7', '晚班值班员', '晚班(日报)'];
let personTypeArr2 = ['省公司带班领导', '建设分公司值班主任', '值长', '值班员'];
let trData = [7, 7, 1, 1, 7, 7, 7, 7, 7, 7, 7, 7, 7];
// 省公司带班领导、建设分公司值班主任、值长、副值长
let personList = [], dateRangeParam;
let objsArr = [];
// 表格赋值
function setTableData(dateRange) {
let html = '<thead><tr><td></td>';
let dateArr = dateRange.split('~');
let weekArr = getAllDate(dateArr[0], dateArr[1]);
$.each(weekArr, function (index, item) {
html += '<td><p>' + setDate(item) + '</p><p>' + weekDateArr[index] + '</p></td>'
})
html += '</tr></thead>'
html += '<tbody>'
$.each(personTypeArr, function (index, item) {
html += '<tr>' +
'<td>' + item + '</td>' +
setTd(index, trData[index], weekArr) +
'</tr>'
})
html += '</tbody>'
$('.classTable').empty().append(html)
setSelData();
}
// 省公司带班领导、建设分公司值班主任、值长、副值长赋值
function setPersonListData(data) {
$.each(personTypeArr2, function (index, item) {
let list = [];
list.push(data.filter(item2 => {
if (item2.post && item2.post.indexOf(item) != -1) {
return item2
}
}))
personList.push(list)
})
}
function setTd(index, value, date) {
let html = '';
if (value === 7) {
for (let i = 0; i < 7; i++) {
if (index === 0 || index === 1 || index === 2 || index === 3) {
html += '<td><div class="td-div" date="' + date[i] + '"><div class="select-div-' + (index + 1) + '" id="value' + ((index + 1) + '' + (i + 1) ) + '"></div></div></td>'
} else {
html += '<td><div class="td-div" date="' + date[i] + '"><div class="select-div-' + (index + 1) + '" id="value' + ((index + 1) + '' + (i + 1)) + '"></div><input style="margin-left:8px;" class="layui-input" maxlength="50" autocomplete="off" type="text" name="remark' + (index + 1) + '" placeholder="备注"></div></td>'
}
}
} else {
html += '<td colspan="7"><div class="td-div td-div2" style="padding: 0;" date="' + date[0] + '"><div class="select-div-' + (index + 1) + '" id="value' + (index + 1 + '1') + '"></div></div></td>'
}
return html;
}
// 下拉选赋值
function setSelData() {
let list = personList[0][0];
let list2 = personList[1][0];
let list3 = personList[2][0];
let list4 = personList[3][0];
setPerson(list, 1,7); // 省公司带班领导
setPerson(list2, 2,7); // 建设分公司值班主任
setPerson(list3, 3,1); // 值长
setPerson(list3, 4,1); // 副值长
for (let i = 5; i <= 13; i++) {
setPerson(list4, i,7); // 值班员
}
}
function setPerson(data, idx,num) {
let parseData = [];
$.each(data, function (index, item) {
parseData.push({value: parseInt(item.id), name: item.userName})
})
let color = '#BFBFBF';
/* let html = '<select style="color:' + color + ' " class="layui-select select' + idx + '" onchange="changeColor(this)" name="select' + idx + '">';
html += '<option value="">请选择</option>';
$.each(data, function (index, item) {
html += '<option value="' + item.id + '">' + item.userName + '</option>'
})
html += '</select>' */
let objArr = [];
for (let index = 1; index <= num; index++) {
let html = '<div class="layui-input-inline select' + idx + '" name="select' + idx + '" id="select'+ (idx + '' + index)+'"></div>';
$('#value' + idx + '' + index).empty().append(html);
let ins = selectInput.render({
elem: '#select'+ (idx + '' + index)+'',
data: parseData,
placeholder: '请输入/请选择',
name: 'select'+ (idx)+'',
initValue:null,
hasCut: true, // 是否允许剪贴
hasSelectIcon: true,
layVerType: 'tips',
layFilter: 'select'+ (idx)+'', //同layui form参数lay-filter
layVerify: 'required', //同layui form参数lay-verify
remoteSearch: false, // 是否启用远程搜索 默认是false和远程搜索回调保存同步
maxlength:'20', //最大输入
});
objArr.push(ins);
}
objsArr.push(objArr);
// layui.form.render();
}
// 下拉选选中
function changeColor(that) {
let value = $(that).val();
if (value) {
$(that).css('color', '#262626');
} else {
$(that).css('color', '#BFBFBF');
}
}
function getTableData() {
// 省公司领导、建设分公司值班主任、值长、副值长、值班员1-7、晚班值班员、晚班日报
let list = [];
for (let i = 1; i < 14; i++) {
let dataList = getSelectData(i);
list.push(dataList)
}
return list;
}
function getSelectData(index) {
let list = [];
let objArr = objsArr[index - 1];
$.each(objArr,function(idx,object){
// console.log(object);
let userId = object.getValue();
let userName = object.getNameByValue(userId);
if(!userId){
userId = -1;
userName = $('input[name="select' + index + '"]').eq(idx).val();
}
// console.log(userId);
// console.log(userName);
let date = $('input[name="select' + index + '"]').eq(idx).parents('.td-div').attr('date');
let obj = {
'userId': setValueData(userId),
'userName': setValueData(userName),
'date': setValueData(date),
'type': index + ''
};
if (index !== 1 || index !== 2 || index !== 3 || index !== 4) {
let remark = $('input[name="select' + index + '"]').eq(idx).parents('.select-div-' + index + '').next().val();
obj.remark = setValueData(remark, 1);
}
list.push(obj)
})
/* $('input[name="select' + index + '"]').each(function (index2) {
let userId = $(this).val();
let userName = $(this).find('option:selected').text();
// console.log('userId:'+userId);
// console.log('userName:'+userName);
let date = $(this).parents('.td-div').attr('date');
let obj = {
'userId': setValueData(userId),
'userName': setValueData(userName),
'date': setValueData(date),
'type': index + ''
};
if (index !== 1 || index !== 2 || index !== 3 || index !== 4) {
let remark = $(this).parents('.select-div-' + index + '').next().val();
obj.remark = setValueData(remark, 1);
}
list.push(obj)
}) */
return list;
}
function setValueData(value, type) {
if (!value || value === '请选择') {
return '';
}
return value;
}
function setFormData(list) {
// console.log(list);
// console.log(objsArr);
$.each(list, function (index, item) {
let objArr = objsArr[index];
index = index + 1
$.each(objArr,function(idx,object){
object.setValue(parseInt(item[idx].userId));
if (index !== 1 || index !== 2 || index !== 3 || index !== 4) {
$('input[name="select' + index + '"]').eq(idx).parents('.select-div-' + index + '').next().val(item[idx].remark);
}
})
/* $('select[name="select' + index + '"]').each(function (index2) {
if (item[index2].userId) {
$(this).css('color', '#262626')
} else {
$(this).css('color', '#BFBFBF')
}
let userId = $(this).val(item[index2].userId);
if (index !== 1 || index !== 2 || index !== 3 || index !== 4) {
$(this).parents('.select-div-' + index + '').next().val(item[index2].remark);
}
}) */
})
layui.form.render();
}
// 关闭页面
function closePage(type) {
let index = parent.layer.getFrameIndex(window.name); //先得到当前 iframe层的索引
parent.layer.close(index); //再执行关闭
if (type === 1) {
parent.reloadData()
}
}