This commit is contained in:
july 2023-02-15 08:57:16 +00:00
parent 36e3da85e9
commit cb9e9569e5

235
temp.txt Normal file
View File

@ -0,0 +1,235 @@
function getUrl() {
let url = window.location.pathname;
let index = url.indexOf("/", 1);
return (url.substring(0, index));
}
//第几页
let indexPage
// 总共有多少页
let pageTotal
//这页有多少条
let sizePage
//总共有多少条
let recordTotal
function showTable(data) {
let pageCapacity = 0;
$(data.beanList).each(function () {
pageCapacity++;
let html = "<tbody>";
if (pageCapacity % 2 != 0) {
html += "<tr id='personnelId" + this.personnelId + "'" + "class='success'>";
} else {
html += "<tr id='personnelId" + this.personnelId + "'" + ">";
}
html += "<td>" + this.personnelName + "</td>";
html += "<td>" + this.personnelAge + "</td>";
html += "<td>" + this.personnelGender + "</td>";
html += "<td>" + this.personnelTelephone + "</td>";
html += "<td>" + this.personnelEmail + "</td>";
html += "<td>" + this.personnelBirthday + "</td>";
html += "<td>" + this.personnelEntrydate + "</td>";
html += "<td>" + this.position.positionName + "</td>";
html += "<td>" + this.state.stateName + "</td>";
html += "<td>" + "<a href='javascript:edit(" + this.personnelId + ")' class='btn btn-primary btn' id='userInfo'>详情</a>&nbsp;&nbsp;" +
"<a href='javascript:edit(" + this.personnelId + ")' class='btn btn-primary btn' id='updateInfo'>修改</a>&nbsp;&nbsp;" +
"<a href='javascript:deleteData(" + this.personnelId + ")' class='btn btn-primary btn'>删除</a> " + "</td>";
html += "</tr>";
html += "</tbody>";
$(html).appendTo($("#taCustomers"));
});
}
//显示页码
function showPage(data) {
let beginPage = eval("data.beginPage");
let endPage = eval("data.endPage");
let pageIndex = eval("data.pageIndex");
//第几页
indexPage = pageIndex;
// 总共有多少页
pageTotal = eval("data.totalPage") == 0 ? 1 : eval("data.totalPage");
//总共有多少条
recordTotal = eval("data.totalRecord");
//这页有多少条
sizePage = recordTotal != 0 ? (eval("data.pageSize")) : 0;
let pageInfo = "本页显示" + (indexPage != pageTotal ? sizePage : (recordTotal % sizePage == 0 ? 10 : recordTotal % sizePage)) + "条数据" + "/共" + recordTotal + "条数据,当前第" + indexPage + "页/共" + pageTotal + "页";
$("#spanId").html(pageInfo);
let html;
if (pageIndex > beginPage) {
html = "<li><a href='javascript:showData(" + (pageIndex - 1) + ")' aria-label='Previous'><span aria-hidden='true'>&laquo;</span></a></li>"
$(html).appendTo($("#page"));
}
let index;
for (index = beginPage; index <= endPage; index++) {
if (index === pageIndex) {
html = " <li class=\"active\"><a href='#'>" + index + "</a></li>"
} else {
html = "<li><a href='javascript:showData(" + index + ")' >" + index + "</a>"
}
$(html).appendTo($("#page"));
}
if (pageIndex < endPage) {
html = "<li><a href='javascript:showData(" + (pageIndex + 1) + ")' aria-label='Next'><span aria-hidden='true'>&raquo;</span></a></li>";
$(html).appendTo($("#page"));
}
}
function deleteData(personnelId) {
$.get(getUrl() + "/Boss/deletePersonnel.do",
{personnelId: personnelId},
function (data) {
if (confirm("确认删除" + personnelId)) {
if (data.code == 200) {
alert("删除成功");
recordTotal = recordTotal - 1;
let pageInfo = "本页显示" + (indexPage != pageTotal ? sizePage - 1 : (recordTotal % sizePage)) + "条数据" + "/共" + recordTotal + "条数据,当前第" + indexPage + "页/共" + pageTotal + "页";
$("#spanId").html(pageInfo);
$("#" + "personnelId" + personnelId).remove();
} else {
alert(data.msg);
}
}
},
"json"
);
}
function getQueryVariable(variable) {
let query = window.location.search.substring(1);
let vars = query.split("&");
for (let i = 0; i < vars.length; i++) {
let pair = vars[i].split("=");
if (pair[0] == variable) {
return pair[1];
}
}
return (false);
}
function showData(pageIndex = 1) {
$("#pageIndex").val(pageIndex);
$.get(getUrl() + "/Boss/getAllPersonnel.do", $("#fmCustomers").serialize(),
function (data) {
$("#taCustomers").children(":gt(0)").remove();
$("#page").children().remove()
showTable(data.data);
showPage(data.data);
},
"json"
);
}
function showPositions(data) {
if (data.code == 200) {
let html = '';
$(data.data).each(function () {
let html = "<option value='" + this.positionId + "' >" + this.positionName + "</option>";
$(html).appendTo($("#roleId"));
/*$(html).appendTo($("#roleId1"));*/
$("#addButton").click(function () {
$(html).appendTo($("#roleId1"));
});
$("#updateInfo").click(function () {
alert("hello");
$(html).appendTo($("#roleId1"));
});
});
} else {
alert(data.msg);
}
}
function showStates(data) {
if (data.code == 200) {
$(data.data).each(function () {
let html = "<option value='" + this.stateId + "' >" + this.stateName + "</option>";
$(html).appendTo($("#status"));
//$(html).appendTo($("#status1"));
$("#addButton").click(function () {
$(html).appendTo($("#status1"))
});
$("#updateInfo").click(function () {
alert("hello");
$(html).appendTo($("#status1"));
});
});
} else {
alert(data.msg);
}
}
function showPosition() {
$.get(getUrl() + "/getPositions.do",
function (data) {
showPositions(data);
},
"json"
);
}
function showState() {
$.get(getUrl() + "/getAllStates.do",
function (data) {
showStates(data);
},
"json"
);
}
//修改
function edit(personnelId) {
$('#myform')[0].reset();
let but = " <button type='button' class='btn btn-default' data-dismiss='modal'>关闭</button>" +
"<button type='button' class='btn btn-primary' id='button2' onclick='modify(" + personnelId + ")'>提交</button>";
$("#modalFooter").html(but);
$.get(getUrl() + "/Boss/selectPersonnelById.do",
{personnelId: personnelId},
function (data) {
if (data.code == 200) {
$("#account").val(data.data.personnelName);
$("#realName").val(data.data.personnelAccount);
$("#test1").val(data.data.personnelBirthday);
$("#age").val(data.data.personnelAge);
$("input:radio[value=" + data.data.personnelGender + "]").attr("checked", "checked");
$("#email").val(data.data.personnelEmail);
$("#mobile").val(data.data.personnelTelephone);
$("#identity").val(data.data.personnelIdcard);
$("#roleId option[value=" + data.data.position.positionId + "]").prop("selected", true);
$("#status option[value=" + data.data.state.stateId + "]").prop("selected", true);
$("#test2").val(data.data.personnelEntrydate);
} else {
alert(data.msg);
}
}, "json"
);
$('#addUserModal').modal('show');
}
//提交数据
function modify(personnelId) {
$.get(getUrl() + "/Boss/modifyPersonnelInfo.do", $("#myform").serialize() + "&personnelId=" + personnelId, function (data) {
if (confirm("确认修改信息吗?")) {
if (data.code == 200) {
alert("修改成功");
showData(personnelId);
} else {
alert("修改失败");
}
}
}, "json");
}
function addperson() {
$.get(getUrl() + "/Boss/addPersonnel.do", $("#myform").serialize(),
function (data) {
if (data.code == 200) {
showData(indexPage);
alert("添加成功");
} else {
alert("添加失败");
}
}, "json");
}