182 lines
7.2 KiB
JavaScript
182 lines
7.2 KiB
JavaScript
define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'editable'], function ($, undefined, Backend, Table, Form) {
|
||
|
||
var Controller = {
|
||
index: function () {
|
||
// 初始化表格参数配置
|
||
Table.api.init({
|
||
extend: {
|
||
index_url: 'oa/schedule/index' + location.search,
|
||
add_url: 'oa/schedule/add',
|
||
edit_url: 'oa/schedule/edit',
|
||
del_url: 'oa/schedule/del',
|
||
multi_url: 'oa/schedule/multi',
|
||
import_url: 'oa/schedule/import',
|
||
table: 'schedule',
|
||
}
|
||
});
|
||
|
||
var table = $("#table");
|
||
|
||
// 初始化表格
|
||
table.bootstrapTable({
|
||
url: $.fn.bootstrapTable.defaults.extend.index_url,
|
||
pk: 'id',
|
||
sortName: 'id',
|
||
columns: [
|
||
[
|
||
{checkbox: true},
|
||
{field: 'id', title: __('Id')},
|
||
{field: 'admin.nickname', title: __('Admin.nickname'), operate: 'LIKE'},
|
||
{field: 'type', title: __('Type'), searchList: {"1":__('Type 1'),"2":__('Type 2'),"3":__('Type 3')}, formatter: Table.api.formatter.normal},
|
||
{field: 'date', title: __('Date'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
|
||
{field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
|
||
{field: 'update_time', title: __('Update_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
|
||
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
|
||
]
|
||
]
|
||
});
|
||
|
||
// 为表格绑定事件
|
||
Table.api.bindevent(table);
|
||
},
|
||
custom_index: function () {
|
||
// 初始化表格参数配置
|
||
Table.api.init({
|
||
extend: {
|
||
index_url: 'oa/schedule/custom_index' + location.search,
|
||
// add_url: 'oa/schedule/add',
|
||
editable: 'oa/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(new Date().setDate(1));
|
||
const endDate = new Date(new Date().getFullYear(), new Date().getMonth() + 1, 0);
|
||
|
||
console.log('Start Date:', startDate);
|
||
console.log('End Date:', endDate);
|
||
|
||
for (let d = new Date(startDate); d <= endDate; d.setDate(d.getDate() + 1)) {
|
||
let tmpDate = d.toISOString().split('T')[0];
|
||
console.log('Current Date:', tmpDate);
|
||
defaultColumnArr.push({
|
||
"title": tmpDate,
|
||
"field": tmpDate,
|
||
"editable" :{
|
||
type: 'select',
|
||
pk: 1,
|
||
source: [
|
||
{value: '无', text: '无'},
|
||
{value: '早班', text: '早班'},
|
||
{value: '中班', text: '中班'},
|
||
{value: '晚班', text: '晚班'},
|
||
{value: '行政班', text: '行政班'},
|
||
]
|
||
}
|
||
});
|
||
}
|
||
|
||
// 初始化表格
|
||
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',
|
||
pk: 1,
|
||
source: [
|
||
{value: '无', text: '无'},
|
||
{value: '早班', text: '早班'},
|
||
{value: '中班', text: '中班'},
|
||
{value: '晚班', text: '晚班'},
|
||
{value: '行政班', text: '行政班'},
|
||
]
|
||
}
|
||
});
|
||
}
|
||
|
||
} 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;
|
||
});
|