完成廠商crud

This commit is contained in:
dev02 2022-12-01 09:17:55 +08:00
parent 0aea9d189a
commit 2c1c677902
8 changed files with 111 additions and 42 deletions

View File

@ -354,7 +354,7 @@
ytAjax = new YourTeam.Ajax(url, objSendData, function (rel) { ytAjax = new YourTeam.Ajax(url, objSendData, function (rel) {
if (rel.code == "0000") if (rel.code == "0000")
location.href = baseApiUrl + "/api/df?fileName=" + rel.data + "&token=" + localStorage.getItem("JWT-Authorization"); location.href = baseApiUrl + "/api/df?path=" + rel.data.split('/')[0] + "&fileName=" + rel.data.split('/')[1] + "&token=" + localStorage.getItem("JWT-Authorization");
}, null, "POST").send(); }, null, "POST").send();
} }
</script> </script>

View File

@ -141,7 +141,7 @@
</div> </div>
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">關閉</button> <button type="button" class="btn btn-secondary" id="OpeFirmCanBtn" data-dismiss="modal">關閉</button>
<button type="button" class="btn btn-primary" id="OpeFirmSendBtn" e-prevent>儲存</button> <button type="button" class="btn btn-primary" id="OpeFirmSendBtn" e-prevent>儲存</button>
</div> </div>
</form> </form>
@ -217,6 +217,25 @@
</div> </div>
</div> </div>
<div class="modal fade" id="delModal" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">
確定刪除這一筆嗎?
</h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true"><i class="fal fa-times"></i></span>
</button>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" id="confirmDelCanBtn" data-dismiss="modal">關閉</button>
<button type="button" class="btn btn-primary" id="confirmDelBtn" e-prevent>儲存</button>
</div>
</div>
</div>
</div>
<script> <script>
$(function () { $(function () {
pageAct.sub_system_tag = null; pageAct.sub_system_tag = null;
@ -324,9 +343,10 @@
{ {
"title": "功能", "title": "功能",
"data": "id", "data": "id",
"render": function () { "render": function (data) {
let btnDiv = creDiv(["row", "m-0", "justify-content-center"], { "style": "gap:10px" }); let btnDiv = creDiv(["row", "m-0", "justify-content-center"], { "style": "gap:10px" }, null, null, {id: data});
btnDiv.append(creBtnHtml("刪除", "rolAuthDelBtn", null, ["btn", "btn-danger"])); btnDiv.append(creBtnHtml("修改", "opeFirmEdiBtn", null, ["btn", "btn-info"], { "toggle": "modal", "target": "#opeFirmModal"}));
btnDiv.append(creBtnHtml("刪除", "opeFirmDelBtn", null, ["btn", "btn-danger"], { "toggle": "modal", "target": "#delModal" }));
return btnDiv.outerHtml(); return btnDiv.outerHtml();
} }
}, },
@ -419,9 +439,9 @@
{ {
"title": "功能", "title": "功能",
"data": "id", "data": "id",
"render": function () { "render": function (data) {
let btnDiv = creDiv(["row", "m-0", "justify-content-center"], { "style": "gap:10px" }); let btnDiv = creDiv(["row", "m-0", "justify-content-center"], { "style": "gap:10px" });
btnDiv.append(creBtnHtml("刪除", "rolAuthDelBtn", null, ["btn", "btn-danger"])); btnDiv.append(creBtnHtml("刪除", "opeRecDelBtn", null, ["btn", "btn-danger"], { "id": data }));
return btnDiv.outerHtml(); return btnDiv.outerHtml();
} }
}, },
@ -539,11 +559,11 @@
ytAjax = new YourTeam.Ajax(url, objSendData, function (rel) { ytAjax = new YourTeam.Ajax(url, objSendData, function (rel) {
if (rel.code == "0000") if (rel.code == "0000")
location.href = baseApiUrl + "/api/df?fileName=" + rel.data + "&token=" + localStorage.getItem("JWT-Authorization"); location.href = baseApiUrl + "/api/df?path=" + rel.data.split('/')[0] + "&fileName=" + rel.data.split('/')[1] + "&token=" + localStorage.getItem("JWT-Authorization");
}, null, "POST").send(); }, null, "POST").send();
} }
function selSysMain() { function selSysMain(tag = null) {
let url = baseApiUrl + "/operation/MaiSysList"; let url = baseApiUrl + "/operation/MaiSysList";
ytAjax = new YourTeam.Ajax(url, null, function (res) { ytAjax = new YourTeam.Ajax(url, null, function (res) {
@ -557,7 +577,7 @@
strHtml += `<option value='${roleObj.system_value}'>${roleObj.system_key}</option>`; strHtml += `<option value='${roleObj.system_value}'>${roleObj.system_key}</option>`;
if (index == 0) if (index == 0)
pageAct.selSysMain = roleObj.system_value pageAct.selSysMain = tag ?? roleObj.system_value
}) })
$("#selSysMain").html(strHtml); $("#selSysMain").html(strHtml);
selSysSub(); selSysSub();
@ -582,6 +602,8 @@
function event() { function event() {
onEvent('click', '#newForm', function () { onEvent('click', '#newForm', function () {
pageAct.opeFirmAct = 'add';
$('#opeFirmModal input').map(function (i, v) { $(v).val('') });
selSysMain(); selSysMain();
}); });
@ -590,40 +612,87 @@
selSysSub(); selSysSub();
}); });
onEvent('click', '#opeFirmEdiBtn', function () {
let url = baseApiUrl + "/operation/OpeFirRead";
pageAct.opeFirmId = $(this).parent().data('id')
objSendData.Data = { id: pageAct.opeFirmId };
ytAjax = new YourTeam.Ajax(url, objSendData, function (res) {
if (!res || res.code != "0000" || !res.data) {
} else {
pageAct.opeFirmAct = 'edit';
selSysMain(res.data.device_system_category_layer2);
$('#opeFirmForm select[id=selSysMain]').val(res.data.device_system_category_layer2).change();
$('#opeFirmForm select[id=selSysSub]').val(res.data.device_system_category_layer3).change();
$('#opeFirmForm input[id=inpName]').val(res.data.name);
$('#opeFirmForm input[id=inpConPer]').val(res.data.contact_person);
$('#opeFirmForm input[id=inpPhone]').val(res.data.phone);
$('#opeFirmForm input[id=inpEmail]').val(res.data.email);
$('#opeFirmForm input[id=inpTaxIdNum]').val(res.data.tax_id_number);
$('#opeFirmForm input[id=inpRemark]').val(res.data.remark);
}
}, null, "POST").send()
});
onEvent("click", "#OpeFirmSendBtn", function () { onEvent("click", "#OpeFirmSendBtn", function () {
let form = $("#opeFirmForm"); let form = $("#opeFirmForm");
console.log(form);
$(form).validate({ $(form).validate({
rules: { rules: {
selSysMain: { required: true }, selSysMain: { required: true },
selSysSub: { required: true }, selSysSub: { required: true },
name: { required: true, maxlength: 50 } inpName: { required: true, maxlength: 50 }
} }
}); });
//if ($(form).valid()) { if ($(form).valid()) {
// console.log($('#selSysMain').val()); let url = baseApiUrl + "/operation/" + (pageAct.opeFirmAct == "add" ? 'SaveOpeFirm' : 'EdtOneOpeFirm');
// let url = baseApiUrl + "/operation/SaveOpeFirm"; let sendData = {
// let sendData = { device_system_category_layer2: $('#selSysMain').val(),
// device_system_category_layer2: $('#selSysMain').val(), device_system_category_layer3: $('#selSysSub').val(),
// device_system_category_layer3: $('#selSysSub').val(), name: $("#inpName").val() || null,
// name: $("#inpName").val(), contact_person: $("#inpConPer").val() || null,
// contact_person: $("#inpConPer").val(), phone: $("#inpPhone").val() || null,
// phone: $("#inpPhone").val(), email: $("#inpEmail").val() || null,
// email: $("#inpEmail").val(), tax_id_number: $("#inpTaxIdNum").val() || null,
// tax_id_number: $("#inpTaxIdNum").val(), remark: $("#inpRemark").val() || null
// remark: $("#inpRemark").val() };
// };
// objSendData.Data = sendData;
// //$("#opeFirmModal").modal("hide");
// //ytAjax = new YourTeam.Ajax(url, objSendData, function (res) {
// // if (!res || res.code != "0000" || !res.data) {
// // } else { if (pageAct.opeFirmAct == "edit")
// // toast_ok(common.AddSuc); sendData.id = pageAct.opeFirmId;
// // $("#opeFirmModal").modal("hide");
// // } objSendData.Data = sendData;
// //}, null, "POST").send();
//} ytAjax = new YourTeam.Ajax(url, objSendData, function (res) {
if (!res || res.code != "0000" || !res.data) {
} else {
//toast_ok(common.AddSuc);
//$("#opeFirmModal").modal("hide");
$("#OpeFirmCanBtn").click();
refTable();
}
}, null, "POST").send();
}
});
onEvent("click", "#opeFirmDelBtn", function () {
pageAct.opeFirmId = $(this).parent().data('id');
});
onEvent("click", "#confirmDelBtn", function () {
objSendData.Data = { id: pageAct.opeFirmId };
let url = baseApiUrl + "/operation/" + (pageAct.work_type == null ? "DelOpeFirm" : "DelOpeRecord");
ytAjax = new YourTeam.Ajax(url, objSendData, function (res) {
if (!res || res.code != "0000" || !res.data) {
} else {
//toast_ok(common.AddSuc);
//$("#delModal").modal("hide");
$("#confirmDelCanBtn").click();
refTable();
}
}, null, "DELETE").send();
}); });
} }
</script> </script>

View File

@ -2586,6 +2586,9 @@ License: You must have a valid license purchased only from wrapbootstrap.com (li
"n4js/historybaja", "n4js/historybaja",
"lib/statistics/flot/flot.bundle", "lib/statistics/flot/flot.bundle",
"lib/statistics/peity/peity.bundle", "lib/statistics/peity/peity.bundle",
"lib/jquery-validation/dist/jquery.validate",
"lib/jquery-validation/dist/additional-methods.min",
"lib/jquery-validation/dist/localization/messages_zh_TW",
], loadedMasterPack); ], loadedMasterPack);
} }
/** /**

View File

@ -104,9 +104,6 @@
[ [
"lib/app.bundle", "lib/app.bundle",
"lib/app.menu", "lib/app.menu",
"lib/jquery-validation/dist/jquery.validate",
"lib/jquery-validation/dist/additional-methods.min",
"lib/jquery-validation/dist/localization/messages_zh_TW",
/*"lib/notifications/sweetalert2/sweetalert2.bundle",*/ /*"lib/notifications/sweetalert2/sweetalert2.bundle",*/
], loadedMasterPack); ], loadedMasterPack);
} }

View File

@ -160,7 +160,7 @@ namespace FrontendWebApi.ApiControllers
} }
apiResult.Code = "0000"; apiResult.Code = "0000";
apiResult.Data = fileName; apiResult.Data = "history/" + fileName;
} }
catch (Exception exception) catch (Exception exception)
{ {

View File

@ -139,7 +139,7 @@ namespace FrontendWebApi.ApiControllers
[HttpGet] [HttpGet]
[Route("api/df")] [Route("api/df")]
public ActionResult DownloadFile(string fileName, string token) public ActionResult DownloadFile(string path, string fileName, string token)
{ {
var jwt = new JwtSecurityTokenHandler().ReadJwtToken(token); var jwt = new JwtSecurityTokenHandler().ReadJwtToken(token);
if (jwt == null) if (jwt == null)
@ -147,7 +147,7 @@ namespace FrontendWebApi.ApiControllers
else if (fileName == null) else if (fileName == null)
return NotFound("找不到文件"); return NotFound("找不到文件");
var filePath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "excel", "history"); var filePath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "excel", path);
return File(System.IO.File.ReadAllBytes(Path.Combine(filePath, fileName)), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", fileName); return File(System.IO.File.ReadAllBytes(Path.Combine(filePath, fileName)), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", fileName);
} }
} }

View File

@ -733,7 +733,7 @@ namespace FrontendWebApi.ApiControllers
} }
apiResult.Code = "0000"; apiResult.Code = "0000";
apiResult.Data = fileName; apiResult.Data = "operation/" + fileName;
} }
catch(Exception ex) catch(Exception ex)
{ {