var modelProjTable; var modelProjRowPos; var modelProjRowID; var modelQuotationTable; var modelQuotationRowPos; var modelQuotationRowID; $(document).ready(function () { deptList(); loadModelQuotationDataTable(); //新增報價單範本視窗 $('#modelQuotationListNewBtn').on('click', function () { $('#clientModelQuotationPreviewModal').modal('toggle'); }); $('#modelProjNewBtn').on('click', function () { $("#modelProj_method").val('add'); $("#dept_uid").val($("#dept_select").val()).trigger('change'); $('#modelProjModal').modal('toggle'); }); $('#search_btn').on('click', function () { $('#dt-responsive').DataTable().ajax.reload(); }); //專案類型對話框儲存鈕 $('#modelProjDialogSaveBtn').on('click', function () { var errmsg = ''; var method = $('#modelProj_method').val(); var modelProj_uid = $('#modelProj_uid').val(); var dept_uid = $('#dept_uid').val(); var modelProj_name = $('#modelProj_name').val(); if (modelProj_name == '') { alert('請輸入專案類型名稱!\n'); return; } var formData = { method: method, modelProj_uid: modelProj_uid, modelProj_name: modelProj_name, dept_uid: dept_uid } $.ajax({ url: "/AuthApi/addEditDelGetModelProj", type: "post", data: formData, success: function (data, textStatus, jqXHR) { if (data.ret == "yes") { var obj = data.modelProjs[0]; if (method == "add") { modelProjTable.fnAddData(obj); } if (method == "edit") { modelProjTable.fnUpdate(obj, modelProjRowPos); } $('#modelProjModal').modal('toggle'); } else { alert(data.message); if (data.err_code == "99999") { location.href = "/Root/Login"; } } }, error: function (jqXHR, textStatus, errorThrown) { alert('網路或伺服器發生錯誤,請稍後重試!'); } }); }); }); function loadModelQuotationDataTable() { 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: 'modelQuotation_uid', deferRender: true, initComplete: function () { modelQuotationTable = $('#dt-responsive-modelQuotation').dataTable(); $('#dt-responsive-modelQuotation').on('click', 'a', function () { buttonModelQuotationClick(this); }); $('#dt-responsive-modelQuotation').on('click', 'button', function () { buttonModelQuotationClick(this); }); }, order: [[0, 'desc']], info: true, search: "搜尋:", searching: true, columns: [ { data: 'modelQuotation_name', className: 'align-top text-left', orderable: true, searchable: true }, { data: 'modelQuotation_createdate', className: 'align-top text-right', orderable: true, searchable: true }, { data: 'modelQuotation_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.modelQuotation_name + ''; } }, { targets: 1, className: 'align-middle text-right', orderable: true, searchable: true, render: function render(data, type, row, meta) { return (new Date(row.modelQuotation_createdate)).format("yyyy/MM/dd hh:mm:ss"); } }, { targets: 2, 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/authModalProjList', type: 'POST', data: function (d) { Object.assign(d, { dept_uid: $('#dept_select').val() }); return d; }, dataSrc: 'modelProjs' }, rowId: 'modelProj_uid', deferRender: true, initComplete: function () { modelProjTable = $('#dt-responsive').dataTable(); $('#dt-responsive').on('click', 'a', function () { buttonClick(this); }); $('#dt-responsive').on('click', 'button', function () { buttonClick(this); }); }, order: [[1, 'desc']], info: true, search: "搜尋:", searching: true, columns: [ { data: 'modelProj_name', className: 'align-top text-left', orderable: true, searchable: true }, { data: 'modelProj_createdate', className: 'align-top text-left', orderable: true, searchable: true }, { data: 'modelProj_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.modelProj_name + ''; } }, { targets: 1, className: 'align-middle text-left', orderable: false, searchable: true, render: function render(data, type, row, meta) { return (new Date(row.modelProj_createdate)).format("yyyy/MM/dd hh:mm:ss"); } }, { 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($("