allocatr/public/assets/js/backend/oa/custom_schedule.js
2025-06-27 10:33:49 +08:00

179 lines
6.9 KiB
JavaScript
Raw 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.

define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'editable'], function ($, undefined, Backend, Table, Form) {
var Controller = {
index: function () {
// 初始化表格参数配置
Table.api.init({
extend: {
index_url: 'oa/custom_schedule/index' + location.search,
add_url: 'oa/custom_schedule/add',
editable: 'oa/custom_schedule/editable',
// del_url: 'oa/schedule/del',
// multi_url: 'oa/schedule/multi',
// import_url: 'oa/schedule/import',
table: 'schedule',
}
});
var table = $("#table");
var defaultColumnArr = [];
defaultColumnArr.push({
"title":"用户名",
"field":"name",
},{
"title":"用户id",
"field":"admin_id",
"visible":false
});
const startDate = new Date();
startDate.setDate(1);
startDate.setHours(0, 0, 0, 0);
const endDate = new Date(startDate.getFullYear(), startDate.getMonth() + 1, 0);
endDate.setHours(0, 0, 0, 0);
for (let d = new Date(startDate); d <= endDate; ) {
const current = new Date(d); // 深拷贝
const tmpDate = current.toLocaleDateString('sv-SE');
console.log('Current Date:', tmpDate);
defaultColumnArr.push({
"title": tmpDate,
"field": tmpDate,
"editable" :{
type: 'select',
emptytext: '_',
pk: 1,
source: [
{value: '', text: ''},
{value: '1', text: '早班'},
{value: '2', text: '中班'},
{value: '3', text: '晚班'},
{value: '4', text: '行政班'},
],
noeditFormatter: function (value, row, index) {
if (row.editable === 1) {
return false;
} else {
const map = {
'': '',
'1': '早班',
'2': '中班',
'3': '晚班',
'4': '行政班'
};
return map[value] ?? value;
}
},
}
});
d.setDate(d.getDate() + 1); // 最后再改 d 的值
}
// 初始化表格
table.bootstrapTable({
url: $.fn.bootstrapTable.defaults.extend.index_url,
columns: defaultColumnArr,
searchFormVisible: true,
searchFormTemplate: 'customformtpl',
});
// 为表格绑定事件
Table.api.bindevent(table);
$(document).on("click", ".btn-block", function () {
let selectedValue = $('#c-flag').val();
let changeColumn = [];
if (selectedValue == 2) {
changeColumn = [{
"title":"用户名",
"field":"name",
},{
"title":"用户id",
"field":"admin_id",
"visible":false
}];
const today = new Date();
const startDate = new Date(today.setDate(today.getDate() - today.getDay() + 1)); // 星期一
const endDate = new Date(today.setDate(today.getDate() - today.getDay() + 7)); // 星期天
for (let d = new Date(startDate); d <= endDate; d.setDate(d.getDate() + 1)) {
let tmpDate = d.toISOString().split('T')[0]; // 使用 d而不是 date
changeColumn.push({
"title": tmpDate,
"field": tmpDate,
"editable" :{
type: 'select',
emptytext: '_',
pk: 1,
source: [
{value: '', text: ''},
{value: '1', text: '早班'},
{value: '2', text: '中班'},
{value: '3', text: '晚班'},
{value: '4', text: '行政班'},
],
noeditFormatter: function (value, row, index) {
if (row.editable === 1) {
return false;
} else {
const map = {
'': '',
'1': '早班',
'2': '中班',
'3': '晚班',
'4': '行政班'
};
return map[value] ?? value;
}
},
}
});
}
} else {
changeColumn = defaultColumnArr;
}
var options = table.bootstrapTable('getOptions');
var queryParams = options.queryParams;
options.queryParams = function (params) {
//这一行必须要存在,否则在点击下一页时会丢失搜索栏数据
params = queryParams(params);
var filter = params.filter ? JSON.parse(params.filter) : {};
filter.timetype = selectedValue;
params.filter = JSON.stringify(filter);
return params;
};
table.bootstrapTable('refreshOptions', {
columns: changeColumn,
});
$('#c-flag').val(selectedValue).change();
return false;
});
},
add: function () {
Controller.api.bindevent();
},
edit: function () {
Controller.api.bindevent();
},
api: {
bindevent: function () {
Form.api.bindevent($("form[role=form]"));
}
}
};
return Controller;
});