$(document).ready(function () { let now = new Date(); let year = now.getFullYear(); let month = now.getMonth() + 1; let day = now.getDate(); if (day >= 20) { month++ } $("#selectYear").val(year); $("#selectMonth").val(month); initMonthModuleTable(); }); var monthModuleTable; $("#selectMark").change(function () { monthModuleTable.bootstrapTable("refreshOptions", { pageNubmer: 1 }); }); $("#selectYear").change(function () { monthModuleTable.bootstrapTable("refreshOptions", { pageNubmer: 1 }); }); $("#selectMonth").change(function () { monthModuleTable.bootstrapTable("refreshOptions", { pageNubmer: 1 }); }); function initMonthModuleTable() { var queryUrl = '/MonthModule/GetMonthModuleTypes'; monthModuleTable = $("#table").bootstrapTable({ url: queryUrl, showFooter: true, queryParams: function (params) { var param = { mark: $('#selectMark option:selected').val(), year: $('#selectYear option:selected').val(), month: $('#selectMonth option:selected').val() }; return param; }, columns: [ { field: "id", title: "ID", visible: false }, { field: "mark", title: "Mark", visible: false }, { field: "year", title: "年", visible: false }, { field: "month", title: "月", visible: false }, { field: "moduleType", title: "机种" }, { field: "planCapacity", title: "计划产能", footerFormatter: function (value) { var count = 0; for (var i in value) { count += value[i].planCapacity } $("#planTotal").text(count); return count; } }, { field: "lastModuleCapacity", title: "上月差异", footerFormatter: function (value) { var count = 0; for (var i in value) { count += value[i].lastModuleCapacity } $("#lastTotal").text(count); return count; } }, { field: "remark", title: "说明" }, { title: '操作', field: "id", formatter: operation, width: 200 } ] }); } function operation(value, row, index) { var htm = " 编辑" + " 删除"; return htm; } function refreshTable() { monthModuleTable.bootstrapTable("refreshOptions", { pageNubmer: 1 }); } function modelCreate() { $("#Id").val(""); $('#mark').val($('#selectMark option:selected').val()); $('#year').val($('#selectYear option:selected').val()); $('#month').val($('#selectMonth option:selected').val()); $("#modal_month_module_add").modal("show"); } function saveMonthModule() { var id = $("#Id").val(); var url; if (id === null || id === "") { url = "/MonthModule/CreateMonthModuleType"; } else { url = "/MonthModule/UpdateMonthModuleType"; } var ModuleType = $("#ModuleType").val(); var PlanCapacity = $("#PlanCapacity").val(); var LastModuleCapacity = $("#LastModuleCapacity").val(); var mark = $('#mark').val(); var year = $('#year').val(); var month = $('#month').val(); var remark = $('#remark').val(); $.ajax({ url: url, method: "POST", headers: { "Content-Type": "application/json" }, async: true, data: JSON.stringify({ "id": id, "moduleType": ModuleType, "planCapacity": parseInt(PlanCapacity), "lastModuleCapacity": parseInt(LastModuleCapacity), "mark": mark, "year": parseInt(year), "month": parseInt(month), "remark": remark }), success: function (result) { if (result.code === 0) { $("#modal_month_module_add").modal("hide"); refreshTable(); } else if (result.code === 1) { alert(result.message); } } }); } function modelUpdate(id) { $("#Id").val(id); $.ajax({ url: "/MonthModule/GetMonthModuleTypes/" + id, method: "GET", headers: { "Content-Type": "application/json" }, async: true, data: { "year": $('#selectYear').val(), "month": $('#selectMonth').val() }, success: function (result) { if (result.code === 0) { $("#ModuleType").val(result.data.moduleType); $("#PlanCapacity").val(result.data.planCapacity); $("#LastModuleCapacity").val(result.data.lastModuleCapacity); $('#mark').val(result.data.mark); $('#year').val(result.data.year); $('#month').val(result.data.month); $('#remark').val(result.data.remark); $("#modal_month_module_add").modal("show"); } else if (result.code === 1) { alert(result.message); } } }); } function deleted(id) { $.ajax({ url: "/MonthModule/DeleteMonthModuleType", method: "POST", headers: { "Content-Type": "application/json" }, async: true, data: JSON.stringify({ "id": id }), success: function (result) { if (result.code === 0) { refreshTable(); } else if (result.code === 1) { alert(result.message); } } }); }