$(document).ready(function () { initLineSelect(); initRecipeTable(); }); var recipeTable; var size; var number; function initRecipeTable() { var queryUrl = '/Recipe/GetRecipes'; recipeTable = $("#recipe_table").bootstrapTable({ url: queryUrl, columns: [ { field: "id", title: "ID", visible: false }, { field: "productionLineId", title: "线别ID", visible: false }, { field: "productionLineName", title: "线别" }, { field: "moduleType", title: "机种" }, { field: "theoryCapacity", title: "理论产能(pcs)" }, { field: "theoryTT", title: "理论节拍(s)" }, { field: "theoryRefueledTime", title: "换料标准(min)" }, { 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 initLineSelect() { $.ajax({ url: "/ProductionLine/GetProductionLines", 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; $("#Line").append(""); } } else if (result.code === 1) { alert(result.message); } } }); } function operation(value, row, index) { var htm = " 编辑" + " 删除"; return htm; } function refreshRecipeTable() { recipeTable.bootstrapTable("refreshOptions", { pageNubmer: 1 }); } function selectPageRecipeTable() { recipeTable.bootstrapTable("selectPage", number); } function modelCreateRecipe() { $("#Id").val(""); $("#modal_recipe_add").modal("show"); } function saveRecipe() { var id = $("#Id").val(); var url; if (id === null || id === "") { url = "/Recipe/CreateRecipe"; } else { url = "/Recipe/UpdateRecipe/" + id; } var ModuleType = $("#ModuleType").val(); var TheoryCapacity = $("#TheoryCapacity").val(); var TheoryTT = $("#TheoryTT").val(); var ProductionLineId = $("#Line").val(); var TheoryRefueledTime = $("#TheoryRefueledTime").val(); $.ajax({ url: url, method: "POST", headers: { "Content-Type": "application/json" }, async: true, data: JSON.stringify({ "moduleType": ModuleType, "productionLineId": ProductionLineId, "theoryCapacity": parseInt(TheoryCapacity), "theoryTT": parseFloat(TheoryTT), "theoryRefueledTime": parseFloat(TheoryRefueledTime) }), success: function (result) { if (result.code === 0) { $("#modal_recipe_add").modal("hide"); if (id === null || id === "") { refreshRecipeTable(); } else { selectPageRecipeTable(); } } else if (result.code === 1) { alert(result.message); } } }); } function modelUpdateRecipe(id) { $("#Id").val(id); $.ajax({ url: "/Recipe/" + id, method: "GET", headers: { "Content-Type": "application/json" }, async: true, success: function (result) { if (result.code === 0) { $("#ModuleType").val(result.data.moduleType); $("#TheoryCapacity").val(result.data.theoryCapacity); $("#TheoryTT").val(result.data.theoryTT); $("#Line").val(result.data.productionLineId); $("#TheoryRefueledTime").val(result.data.theoryRefueledTime) } else if (result.code === 1) { alert(result.message); } } }); $("#modal_recipe_add").modal("show"); } function deleteRecipe(id) { $.ajax({ url: "/Recipe/DeleteRecipe/" + id, method: "POST", headers: { "Content-Type": "application/json" }, async: true, success: function (result) { if (result.code === 0) { if (id === null || id === "") { refreshRecipeTable(); } else { selectPageRecipeTable(); } } else if (result.code === 1) { alert(result.message); } } }); }