var mainItemTable;
var mainItemRowID;
var mainItemRowPos;
var subItemTable;
var subItemRowID;
var subItemRowPos;
$(document).ready(function () {
deptList();
$('#subItemListNewBtn').on('click', function () {
$("#clientSubItem_method").val('add');
$('#clientSubItemModal').modal('toggle');
});
$('#maintItemNewModal').on('click', function () {
$("#mainItem_method").val('add');
$("#dept_uid").val($("#dept_select").val()).trigger('change');
$('#mainItemModal').modal('toggle');
});
$('#mainItemDialogSaveBtn').on('click', function () {
var method = $('#mainItem_method').val();
var dept_uid = $("#dept_uid").val();
var mainItem_uid = $('#mainItem_uid').val();
var mainItem_name = $('#modal_mainItem_name').val();
var mainItem_order = $('#modal_mainItem_order').val();
if (mainItem_name == "") {
alert('請輸入主項目名稱');
return;
}
if (mainItem_order == "") {
alert('請輸入順序,數字越小越上面!');
return;
}
if (mainItem_order.isNumber == false) {
alert('請輸入順序數字,數字越小越上面!');
return;
}
var formData = {
method: method,
dept_uid: dept_uid,
mainItem_uid: mainItem_uid,
mainItem_name: mainItem_name,
mainItem_order: mainItem_order
}
$.ajax({
url: "/AuthApi/addEditDelGetMainItem",
type: "post",
data: formData,
success: function (data, textStatus, jqXHR) {
if (data.ret == "yes") {
var obj = data.mainItems[0];
if (method == "add") {
mainItemTable.fnAddData(obj);
}
if (method == "edit") {
mainItemTable.fnUpdate(obj, mainItemRowPos);
}
$('#mainItemModal').modal('toggle');
} else {
alert(data.message);
if (data.err_code == "99999") {
location.href = "/Root/Login";
}
}
},
error: function (jqXHR, textStatus, errorThrown) {
alert('網路或伺服器發生錯誤,請稍後重試!');
}
});
});
$('#clientSubItemSaveBtn').on('click', function () {
var mainItem_uid = $('#subItemList_mainItem_uid').val();
var subItem_uid = $('#clientSubItem_subItem_uid').val();
var method = $('#clientSubItem_method').val();
var subItem_name = $('#modal_subItem_name').val();
var subItem_descript = $('#modal_subItem_descript').val();
var subItem_price = $('#modal_subItem_price').val();
var subItem_unitType = $('#modal_subItem_unitType').val();
var dept_uid = $("#dept_select").val();
var msg = '';
if (subItem_name == '') {
msg += '請輸入次項目名稱!\n';
}
if (subItem_price == '') {
msg += '請輸入單價!\n';
} else {
if (subItem_price.isNumber() == false) {
msg += '單價必須為數字!\n';
}
}
if (subItem_unitType == '') {
msg += '請輸入次項目的單位!\n';
}
if (msg != '') {
alert(msg);
return;
}
var formData = {
mainItem_uid: mainItem_uid,
subItem_uid: subItem_uid,
method: method,
subItem_name: subItem_name,
subItem_descript: subItem_descript,
subItem_price: subItem_price,
subItem_unitType: subItem_unitType,
dept_uid: dept_uid
}
$.ajax({
url: "/AuthApi/addEditDelGetSubItem",
type: "post",
data: formData,
success: function (data, textStatus, jqXHR) {
if (data.ret == "yes") {
var obj = data.subItems[0];
if (method == "add") {
subItemTable.fnAddData(obj);
}
if (method == "edit") {
subItemTable.fnUpdate(obj, subItemRowPos);
}
$('#clientSubItemModal').modal('toggle');
} else {
alert(data.message);
if (data.err_code == "99999") {
location.href = "/Root/Login";
}
}
},
error: function (jqXHR, textStatus, errorThrown) {
alert('網路或伺服器發生錯誤,請稍後重試!');
}
});
});
$('#search_btn').on('click', function () {
$('#dt-responsive').DataTable().ajax.reload();
});
});
function loadSubItemDataTable() {
var dataTables = {
init: function init() {
this.bindUIActions();
},
bindUIActions: function bindUIActions() {
// event handlers
this.table = this.handleDataTables();
// add buttons
//this.table.buttons().container().appendTo('#dt-buttons').unwrap();
},
handleDataTables: function handleDataTables() {
//$('#myTable').append("
| | | | | | |
");
return $('#dt-responsive-subItem').DataTable({
dom: '<\'text-muted\'Bif>\n <\'table-responsive\'trl>\n <\'mt-4\'p>',
lengthChange: true,
lengthMenu: [[25, 50, 100, -1], [25, 50, 100, "All"]],
pageLength: 25,
buttons: [
//{
// text: '休假設定',
// action: function (e, dt, node, config) {
// vacationBtnFun();
// }
//},
//'excelHtml5'
],
language: {
paginate: {
previous: '',
next: ''
},
buttons: {
copyTitle: 'Data copied',
copyKeys: 'Use your keyboard or menu to select the copy command'
}
},
autoWidth: false,
rowId: 'subItem_uid',
deferRender: true,
initComplete: function () {
subItemTable = $('#dt-responsive-subItem').dataTable();
$('#dt-responsive-subItem').on('click', 'a', function () {
buttonSubItemClick(this);
});
$('#dt-responsive-subItem').on('click', 'button', function () {
buttonSubItemClick(this);
});
},
order: [[0, 'desc']],
info: true,
search: "搜尋:",
searching: true,
columns: [
{ data: 'subItem_name', className: 'align-top text-left', orderable: true, searchable: true },
{ data: 'subItem_price', className: 'align-top text-right', orderable: true, searchable: true },
{ data: 'subItem_unitType', className: 'align-top text-right', orderable: true, searchable: true },
{ data: 'subItem_uid', className: 'align-top text-center', orderable: false, searchable: false }
],
columnDefs: [
{
targets: 0,
className: 'align-middle text-left',
orderable: false,
searchable: true,
render: function render(data, type, row, meta) {
return row.subItem_name;
//return '' + row.subItem_name + '';
}
},
{
targets: 1,
className: 'align-middle text-right',
orderable: true,
searchable: true,
render: function render(data, type, row, meta) {
return thousands(row.subItem_price);
//return '' + row.subItem_name + '';
}
},
{
targets: 3,
className: 'align-middle text-center',
orderable: false,
searchable: false,
render: function render(data, type, row, meta) {
var ret = '';
ret += '';
ret += '';
return ret;
}
}
],
responsive: {
details: {
display: $.fn.dataTable.Responsive.display.childRowImmediate,
type: ''
}
}
});
},
handleSearchRecords: function handleSearchRecords() {
var self = this;
$('#table-search, #filterBy').on('keyup change focus', function (e) {
var filterBy = $('#filterBy').val();
var hasFilter = filterBy !== '';
var value = $('#table-search').val();
self.table.search('').columns().search('').draw();
if (hasFilter) {
self.table.columns(filterBy).search(value).draw();
} else {
self.table.search(value).draw();
}
});
}
}
dataTables.init();
}
function loadDataTable() {
var dataTables = {
init: function init() {
this.bindUIActions();
},
bindUIActions: function bindUIActions() {
// event handlers
this.table = this.handleDataTables();
// add buttons
//this.table.buttons().container().appendTo('#dt-buttons').unwrap();
},
handleDataTables: function handleDataTables() {
//$('#myTable').append(" | | | | | | |
");
return $('#dt-responsive').DataTable({
dom: '<\'text-muted\'Bif>\n <\'table-responsive\'trl>\n <\'mt-4\'p>',
lengthChange: true,
lengthMenu: [[25, 50, 100, -1], [25, 50, 100, "All"]],
pageLength: 50,
buttons: [
//{
// text: '休假設定',
// action: function (e, dt, node, config) {
// vacationBtnFun();
// }
//},
//'excelHtml5'
],
language: {
paginate: {
previous: '',
next: ''
},
buttons: {
copyTitle: 'Data copied',
copyKeys: 'Use your keyboard or menu to select the copy command'
}
},
autoWidth: false,
ajax: {
url: '/authApi/authMainItemList',
type: 'POST',
data: function (d) {
Object.assign(d, {
dept_uid: $('#dept_select').val()
});
return d;
},
dataSrc: 'mainItems'
},
rowId: 'mainItem_uid',
deferRender: true,
initComplete: function () {
mainItemTable = $('#dt-responsive').dataTable();
$('#dt-responsive').on('click', 'a', function () {
buttonClick(this);
});
$('#dt-responsive').on('click', 'button', function () {
buttonClick(this);
});
},
order: [[1, 'asc']],
info: true,
search: "搜尋:",
searching: true,
columns: [
{ data: 'mainItem_name', className: 'align-top text-left', orderable: true, searchable: true },
{ data: 'mainItem_order', className: 'align-top text-right', orderable: true, searchable: false },
{ data: 'mainItem_uid', className: 'align-top text-center', orderable: false, searchable: false }
],
columnDefs: [
{
targets: 0,
className: 'align-middle text-left',
orderable: false,
searchable: true,
render: function render(data, type, row, meta) {
return '' + row.mainItem_name + '';
}
},
{
targets: 2,
orderable: false,
searchable: false,
render: function render(data, type, row, meta) {
var ret = '';
ret += '';
ret += '';
return ret;
}
}
],
responsive: {
details: {
display: $.fn.dataTable.Responsive.display.childRowImmediate,
type: ''
}
}
});
},
handleSearchRecords: function handleSearchRecords() {
var self = this;
$('#table-search, #filterBy').on('keyup change focus', function (e) {
var filterBy = $('#filterBy').val();
var hasFilter = filterBy !== '';
var value = $('#table-search').val();
self.table.search('').columns().search('').draw();
if (hasFilter) {
self.table.columns(filterBy).search(value).draw();
} else {
self.table.search(value).draw();
}
});
}
}
dataTables.init();
}
function deptList() {
$.ajax({
url: "/AuthApi/authDeptList",
type: "post",
data: null,
success: function (data, textStatus, jqXHR) {
if (data.ret == "yes") {
var obj = data.depts;
var items = "";
$.each(obj, function (i, item) {
$("#dept_select").append($("