123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- $(document).ready(function () {
- initRoleSelect();
- initUserTable();
- });
- function initRoleSelect() {
- $.ajax({
- url: "/Admin/GetAllRoles",
- method: "GET",
- headers: { "Content-Type": "application/json" },
- async: true,
- success: function (result) {
- if (result.code === 0) {
- for (var i = 0; i < result.data.length; i++) {
- var id = result.data[i].id;
- var value = result.data[i].name;
- $("#Role").append("<option value=" + id + ">" + value + "</option>");
- }
- } else if (result.code === 1) {
- alert(result.message);
- }
- }
- });
- }
- var userTable;
- var size;
- var number;
- function initUserTable() {
- var queryUrl = '/Admin/GetUsers';
- userTable = $("#user_table").bootstrapTable({
- url: queryUrl,
- columns: [
- { field: "id", title: "ID", visible: false },
- { field: "jobNo", title: "工号"},
- { field: "name", title: "名称" },
- { field: "roleId", title: "角色Id", visible: false },
- { field: "roleName", title: "角色名称" },
- { field: "createTime", title: "创建时间" },
- {
- title: '操作',
- field: "id",
- formatter: operation,
- width: 200
- }
- ],
- pagination: true,
- pageNumber: 1,
- pageSize: size,
- pageList: [10, 25, 50, 100],
- smartDisplay: false,
- sidePagination: "server",
- queryParams: function (params) {
- var temp = {
- pageNumber: (params.offset / params.limit) + 1,
- pageSize: params.limit,
- keyword: $("#keyword").val()
- };
- number = temp.pageNumber;
- return temp;
- }
- });
- }
- function operation(value, row, index) {
- var htm =
- "<a class='label' onclick='modelUpdateUser(\"" + value + "\")'> <i class='fa fa-edit'> 编辑</i></a >" +
- "<a class='label' onclick='deleteUser(\"" + value + "\")'> <i class='fa fa-trash-o'> 删除</i></a >";
- return htm;
- }
- function modelCreateUser() {
- $("#Id").val("");
- $("#FormJobNo")[0].disabled = false;
- $("#modal_user_add").modal("show");
- }
- function refreshUserTable() {
- userTable.bootstrapTable("refreshOptions", { pageNubmer: 1 });
- }
- function selectPageUserTable() {
- userTable.bootstrapTable("selectPage", number);
- }
- function saveUser() {
- var id = $("#Id").val();
- var url;
- if (id === null || id === "") {
- url = "/Admin/CreateUser";
- } else {
- url = "/Admin/UpdateUser/" + id;
- }
- $.ajax({
- url: url,
- method: "POST",
- headers: { "Content-Type": "application/json" },
- async: true,
- data: JSON.stringify({
- "jobNo": $("#FormJobNo").val(),
- "name": $("#Name").val(),
- "roleId": $("#Role").val(),
- }),
- success: function (result) {
- if (result.code === 0) {
- $("#modal_user_add").modal("hide");
- if (id === null || id === "") {
- refreshUserTable();
- } else {
- selectPageUserTable();
- }
- } else if (result.code === 1) {
- alert(result.message);
- }
- }
- });
- }
- function modelUpdateUser(id) {
- $("#Id").val(id);
- $("#FormJobNo")[0].disabled = true;
- $.ajax({
- url: "/Admin/User/" + id,
- method: "GET",
- headers: { "Content-Type": "application/json" },
- async: true,
- success: function (result) {
- if (result.code === 0) {
- $("#FormJobNo").val(result.data.jobNo);
- $("#Name").val(result.data.name);
- $("#Role").val(result.data.roleId);
- } else if (result.code === 1) {
- alert(result.message);
- }
- }
- });
- $("#modal_user_add").modal("show");
- }
- function deleteUser(id) {
- $.ajax({
- url: "/Admin/DeleteUser/" + id,
- method: "POST",
- headers: { "Content-Type": "application/json" },
- async: true,
- success: function (result) {
- if (result.code === 0) {
- if (id === null || id === "") {
- refreshUserTable();
- } else {
- selectPageUserTable();
- }
- } else if (result.code === 1) {
- alert(result.message);
- }
- }
- });
- }
|