diff --git a/Controllers/AuthApiController.cs b/Controllers/AuthApiController.cs index 98b8302b..26ab05e0 100644 --- a/Controllers/AuthApiController.cs +++ b/Controllers/AuthApiController.cs @@ -23,6 +23,38 @@ namespace QuotationMaker.Controllers this._httpContextAccessor = httpContextAccessor; } + [Route("authModalQuotationList")] + public ActionResult AuthModalQuotationList(IFormCollection obj) + { + modelQuotationListResult ret = new modelQuotationListResult(); + + authToken token = new authToken(this._httpContextAccessor); + if (token.user_isLogin == false) + { + HttpContext.Response.Cookies.Delete("token_key"); + ret.ret = "no"; + ret.err_code = "99999"; + ret.message = "非登入狀態!"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + if (token.user_perm != "system") + { + ret.ret = "no"; + ret.err_code = "90001"; + ret.message = "此帳號無此api使用權限!"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + string dept_uid = obj["dept_uid"].ToString(); + string modelProj_uid = obj["modelProj_uid"].ToString(); + + ret.modelQuotations = conn.Query("select * from modelQuotation where modelProj_uid = @modelProj_uid and dept_uid = @dept_uid", new { modelProj_uid = modelProj_uid, dept_uid = dept_uid }).ToList(); + ret.ret = "yes"; + + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + [Route("addEditDelGetModelProj")] public ActionResult AddEditDelGetModelProj(IFormCollection obj) { modelProjListResult ret = new modelProjListResult(); diff --git a/Modals/resultClass.cs b/Modals/resultClass.cs index 10d59969..825ae232 100644 --- a/Modals/resultClass.cs +++ b/Modals/resultClass.cs @@ -4,7 +4,13 @@ using Dapper; using static DbTableClass; public class resultClass { - + public class modelQuotationListResult + { + public string ret = "no"; + public string err_code = "0000"; + public string message = ""; + public List modelQuotations = new List(); + } public class modelProjListResult { public string ret = "no"; diff --git a/Views/Home/ModalList.cshtml b/Views/Home/ModalList.cshtml index 78ccc420..4d717178 100644 --- a/Views/Home/ModalList.cshtml +++ b/Views/Home/ModalList.cshtml @@ -112,3 +112,54 @@ + +
+ +
\ No newline at end of file diff --git a/wwwroot/assets/javascript/custom/modallist.js b/wwwroot/assets/javascript/custom/modallist.js index e6c51c2a..eeaf434c 100644 --- a/wwwroot/assets/javascript/custom/modallist.js +++ b/wwwroot/assets/javascript/custom/modallist.js @@ -1,8 +1,13 @@ var modelProjTable; var modelProjRowPos; var modelProjRowID; + +var modelQuotationTable; +var modelQuotationRowPos; +var modelQuotationRowID; $(document).ready(function () { deptList(); + loadModelQuotationDataTable(); $('#modelProjNewBtn').on('click', function () { $("#modelProj_method").val('add'); @@ -70,6 +75,139 @@ $(document).ready(function () { }); }); +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() { @@ -156,7 +294,7 @@ function loadDataTable() { render: function render(data, type, row, meta) { - return '' + row.modelProj_name + ''; + return '' + row.modelProj_name + ''; } }, @@ -262,29 +400,29 @@ function buttonClick(obj) { modelProjRowPos = modelProjTable.fnGetPosition($('#' + uid)[0]); if (type == "preview") { - var mainItem_name = obj.innerText.trim(); + var modelProj_name = obj.innerText.trim(); var formData = { dept_uid: dept_uid, - mainItem_uid: uid + modelProj_uid: uid } $.ajax({ - url: "/AuthApi/authSubItemList", + url: "/AuthApi/authModalQuotationList", type: "post", data: formData, success: function (data, textStatus, jqXHR) { if (data.ret == "yes") { - var obj = data.subItems; + var obj = data.modelQuotations; - $('#dt-responsive-subItem').dataTable().fnClearTable(); + $('#dt-responsive-modelQuotation').dataTable().fnClearTable(); if (obj.length > 0) { - $('#dt-responsive-subItem').dataTable().fnAddData(obj); + $('#dt-responsive-modelQuotation').dataTable().fnAddData(obj); } - $('#mainItemTitle').val(mainItem_name + ' 的子項目列表').trigger('change'); + $('#modelQuotationTitle').val(modelProj_name + ' 的範本列表').trigger('change'); - $('#subItemList_mainItem_uid').val(uid); - $('#clientSubItemListModal').modal('toggle'); + $('#parent_modelProj_uid').val(uid); + $('#clientModelQuotationListModal').modal('toggle'); } else { alert(data.message);