361 lines
13 KiB
JavaScript
361 lines
13 KiB
JavaScript
$(".addColor").click(function () {
|
||
$(".addColor").removeAttr("style");
|
||
$(this).css("background-color", "#FFFAF0");
|
||
});
|
||
|
||
if ($(document).width() > 764) {
|
||
$("select").css("width", "200px");
|
||
$("b").css("font-size", "16px");
|
||
} else {
|
||
$("select").css("font-size", "13px");
|
||
}
|
||
|
||
function gotoDetailPartialNew(id) {
|
||
$("#pPlanInterBox_Content").empty();
|
||
removePPInfo();
|
||
// Ajax提交数据
|
||
$.ajax({
|
||
url: "/APP/PPlan/PPlanInternalDetailsNew",//"@Url.Action("PPlanInternalDetailsNew", "PPlan")",//"APP/login/login", // 提交到controller的url路径
|
||
type: "post", // 提交方式
|
||
data: { "id": id }, // data为String类型,必须为 Key/Value 格式。
|
||
dataType: "json", // 服务器端返回的数据类型
|
||
success: function (res) { // 请求成功后的回调函数,其中的参数data为controller返回的map,也就是说,然后通过data这个参数取JSON数据中的值
|
||
|
||
if (res.Status == 200) {
|
||
|
||
setPPInfo(res);
|
||
if (res.Data.rows) {
|
||
//正则
|
||
var n = /^[0-9]*$/;
|
||
var re = new RegExp(n);
|
||
//填充数据
|
||
var jsonArray = res.Data.rows;
|
||
var headArray = [];
|
||
var exist = false;
|
||
//console.log(res.Data.rows);
|
||
//循环取字段名
|
||
for (var i in jsonArray[0]) {
|
||
headArray[headArray.length] = i;
|
||
//console.log("字段名?" + headArray[headArray.length] + ",i的值" + i);
|
||
}
|
||
|
||
var div = document.getElementById("pPlanInterBox_Content");
|
||
var table = document.createElement("table");
|
||
table.id = "new_table";
|
||
//table.setAttribute("class", "table table-striped table-bordered table-hover dataTables-example");
|
||
|
||
|
||
var theadH = document.createElement("thead");
|
||
var thead = document.createElement("tr");
|
||
|
||
for (var count = 1; count < headArray.length; count++) {
|
||
var td = document.createElement("th");
|
||
td.setAttribute("style", "width:90px")
|
||
td.innerHTML = headArray[count];
|
||
thead.appendChild(td);
|
||
}
|
||
theadH.appendChild(thead);
|
||
table.appendChild(theadH);
|
||
|
||
var theadY = document.createElement("tbody");
|
||
var trColor = "background-color:#FFFAF0";
|
||
var num = 0;
|
||
for (var tableRowNo = 0; tableRowNo < jsonArray.length; tableRowNo++) {
|
||
|
||
var tr = document.createElement("tr");
|
||
if (tableRowNo % 2 == 0) {
|
||
num++;
|
||
|
||
if (num % 2 == 0) {
|
||
trColor = "background-color:#F5F5F5";
|
||
} else {
|
||
trColor = "background-color:#FFFAF0";
|
||
}
|
||
|
||
}
|
||
tr.setAttribute("style", trColor);
|
||
|
||
var number = 99999;
|
||
for (var headCount = 1; headCount < headArray.length; headCount++) {
|
||
var cell = document.createElement("td");
|
||
|
||
cell.setAttribute("class", jsonArray[tableRowNo][headArray[0]] + " " + headArray[headCount]);
|
||
cell.innerHTML = jsonArray[tableRowNo][headArray[headCount]];
|
||
//判断数量是否正常
|
||
if (re.test(jsonArray[tableRowNo][headArray[headCount]])) {
|
||
//console.log(number);
|
||
//console.log(jsonArray[tableRowNo][headArray[headCount]]);
|
||
|
||
if (number< parseInt(jsonArray[tableRowNo][headArray[headCount]])) {
|
||
cell.setAttribute("class", jsonArray[tableRowNo][headArray[0]] + " " + headArray[headCount] + " tdColor");
|
||
//console.log(jsonArray[tableRowNo][headArray[headCount]]); console.log(number);
|
||
exist = true;
|
||
}
|
||
number = parseInt(jsonArray[tableRowNo][headArray[headCount]] == "" ? 0 : jsonArray[tableRowNo][headArray[headCount]]);
|
||
}
|
||
//cell.data("station", headArray[headCount]);
|
||
cell.dataset.station = headArray[headCount];
|
||
cell.dataset.datetime = jsonArray[tableRowNo][headArray[1]];
|
||
tr.appendChild(cell);
|
||
}
|
||
theadY.appendChild(tr);
|
||
table.appendChild(theadY);
|
||
|
||
}
|
||
div.appendChild(table);
|
||
if (exist) {
|
||
$("#pPlanInterBox_Content").append("<p style='color:red'>*红色字体数据可能违规,请重新检查</p>");
|
||
}
|
||
|
||
newTable(table.id);
|
||
|
||
$('.ToDay.Date').css({ 'border-bottom': '1px solid #FFF' });
|
||
$('.Total').css({ 'border-bottom': '1px solid #333' });
|
||
$('.Total:not(.Date)').css({ 'color': '#1C1C1C', 'font-size': '12px' });
|
||
$('.ToDay:not(.Date)').css({ 'font-size': '16px' });
|
||
//$("#pPlanInterBox_Content").focus();
|
||
//location.href = "#ppInfo";
|
||
//$('html, body').animate({ scrollTop: $('#ppInfo').offset().top }, 1000);
|
||
//for (var tableRowNo = 1; tableRowNo <= (jsonArray.length / 2); tableRowNo++) {
|
||
|
||
// mergeCell('new_table', tableRowNo * 2 - 1, tableRowNo * 2, 0);
|
||
//}
|
||
}
|
||
else {
|
||
$("#pPlanInterBox_Content").html("<small><strong> 暂无生产计划</strong ></small >");
|
||
}
|
||
}
|
||
|
||
|
||
},
|
||
});
|
||
|
||
};
|
||
|
||
function mergeCell(table1, startRow, endRow, col) {
|
||
var tb = document.getElementById(table1);
|
||
if (!tb || !tb.rows || tb.rows.length <= 0) {
|
||
return;
|
||
}
|
||
if (col >= tb.rows[0].cells.length || (startRow >= endRow && endRow != 0)) {
|
||
return;
|
||
}
|
||
if (endRow == 0) {
|
||
endRow = tb.rows.length - 1;
|
||
}
|
||
for (var i = startRow; i < endRow; i++) {
|
||
if (tb.rows[startRow].cells[col].innerHTML == tb.rows[i + 1].cells[col].innerHTML) { //如果相等就合并单元格,合并之后跳过下一行
|
||
tb.rows[i + 1].removeChild(tb.rows[i + 1].cells[col]);
|
||
tb.rows[startRow].cells[col].rowSpan = (tb.rows[startRow].cells[col].rowSpan) + 1;
|
||
} else {
|
||
mergeCell(table1, i + 1, endRow, col);
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
|
||
var oTable;
|
||
function newTable(tbid) {
|
||
oTable = $('#' + tbid).DataTable({
|
||
"bFilter": false, //过滤功能
|
||
"info": false,
|
||
"ordering": false,
|
||
"lengthChange": false,
|
||
"bAutoWidth": false,//自动宽度
|
||
"bPaginate": false, //翻页功能
|
||
|
||
//表头固定
|
||
//"fixedHeader": true,
|
||
//"scrollX": "500px",
|
||
//"scrollY": "400px",
|
||
//"scrollCollapse": true,
|
||
////固定首列,需要引入相应 dataTables.fixedColumns.min.js
|
||
//"fixedColumns": {
|
||
// "leftColumns": 2
|
||
//},
|
||
//"columnDefs": [{
|
||
// targets: 0, //第1列
|
||
// createdCell: function (td, cellData, rowData, row, col) {
|
||
|
||
// var rowspan = (row+1)%2;
|
||
// if (rowspan == 0) {
|
||
// $(td).remove();
|
||
// }
|
||
// else {
|
||
// $(td).attr('rowspan', 2);
|
||
// }
|
||
// }
|
||
//}],
|
||
});
|
||
|
||
//即时编辑
|
||
oTable.$('td:not(.Date,.Total,.DataType)').editable(function (value, settings) {
|
||
var station = this.dataset.station;//站
|
||
var datetime = this.dataset.datetime;//日期
|
||
var oiID = $("#oiID").val();//内部单号
|
||
var projectID = $("#projectID").val();//机型
|
||
SetPPCount(projectID, oiID, station, datetime, value);//修改数量
|
||
return (value);
|
||
|
||
},
|
||
{
|
||
"indicator": '保存中...',//提交处理过程中显示的提示文字
|
||
"tooltip": '单击编辑...',//鼠标悬停时的提示信息
|
||
//"cssclass": 'form-control',
|
||
"width": "60px",
|
||
"height": "100%",
|
||
"placeholder": "0",
|
||
//"style": 'input:{width:60px;}',
|
||
//"onblur": 'ignore',//方便调试样式
|
||
});
|
||
|
||
$.editable.addInputType('birthday', {
|
||
element: function (settings, original) {
|
||
var input = $('<input type="text" size="8" readonly>').datetimepicker({
|
||
language: 'zh-CN',
|
||
//locale: moment.locale('zh-CN'),
|
||
format: 'yyyy/mm/dd',
|
||
autoclose: 1,
|
||
startView: 2,
|
||
minView: 2,
|
||
});
|
||
$(this).append(input);
|
||
return (input);
|
||
}
|
||
});
|
||
|
||
//即时编辑
|
||
oTable.$('.Date:not(.Total)').editable(function (value, settings) {
|
||
var datetime = this.dataset.datetime;//日期
|
||
var oiID = $("#oiID").val();//内部单号
|
||
var projectID = $("#projectID").val();//机型
|
||
SetPPDate(projectID, oiID, datetime, value);
|
||
return (value);
|
||
},
|
||
{
|
||
"cancel": '取消',//取消编辑按钮的文字
|
||
"submit": '确定',//确认提交按钮的文字
|
||
|
||
"indicator": '保存中...',//提交处理过程中显示的提示文字
|
||
"tooltip": '单击编辑...',//鼠标悬停时的提示信息
|
||
//"cssclass": 'form-control',
|
||
"width": "60px",
|
||
"height": "100%",
|
||
"placeholder": "0",
|
||
"type": 'birthday',
|
||
//"style": 'input:{width:60px;}',
|
||
"onblur": 'ignore',//方便调试样式
|
||
});
|
||
|
||
}
|
||
|
||
//设置计划信息
|
||
function setPPInfo(res) {
|
||
$("#customerAbbr").html(res.Data.CustomerAbbr);
|
||
$("#projectName").html(res.Data.ProjectName);
|
||
$("#orderNo").html(res.Data.OrderNo);
|
||
$("#internalNo").html(res.Data.InternalNo);
|
||
$("#deliveryTime").html(res.Data.DeliveryTimeStr);
|
||
$("#stationText").html(res.Data.StationText);
|
||
$("#OrderCount").html(res.Data.OrderCount);
|
||
$("#oiID").val(res.Data.ID);
|
||
$("#projectID").val(res.Data.ProjectID);
|
||
|
||
$("#ppInfo").attr("style", "display:block;");
|
||
}
|
||
|
||
//清除计划信息
|
||
function removePPInfo() {
|
||
$("#customerAbbr").html("");
|
||
$("#projectName").html("");
|
||
$("#orderNo").html("");
|
||
$("#internalNo").html("");
|
||
$("#deliveryTime").html("");
|
||
$("#stationText").html("");
|
||
$("#oiID").val("");
|
||
$("#projectID").val("");
|
||
|
||
$("#ppInfo").attr("style", "display:none;");
|
||
};
|
||
|
||
//新增行
|
||
function fnClickAddRow() {
|
||
var oiID = $("#oiID").val();//内部单号
|
||
var projectID = $("#projectID").val();//机型
|
||
$.ajax({
|
||
url: "/APP/PPlan/AddPPlanForTB", //"@Url.Action("AddPPlanForTB", "PPlan")",
|
||
type: "post",
|
||
data: { "projectID": projectID, "oiID": oiID },
|
||
dataType: "json",
|
||
success: function (res) {
|
||
if (res.Status == 200) {
|
||
$.toastr.success('提交成功',
|
||
{
|
||
position: 'top-center',
|
||
time: 550,
|
||
});
|
||
gotoDetailPartialNew(oiID);
|
||
}
|
||
else {
|
||
$.toastr.error('提交失败! <br />' + res.Message, {
|
||
time: 3000,
|
||
position: 'top-center'
|
||
});
|
||
}
|
||
|
||
}
|
||
});
|
||
};
|
||
|
||
function SetPPCount(projectID, oiID, station, datetime, value) {
|
||
$.ajax({
|
||
url: "/APP/PPlan/EditPPlanForTB",//"@Url.Action("EditPPlanForTB", "PPlan")",
|
||
type: "post",
|
||
data: { "projectID": projectID, "oiID": oiID, "stationName": station, "datetime": datetime, "count": value },
|
||
dataType: "json",
|
||
success: function (res) {
|
||
if (res.Status == 200) {
|
||
$.toastr.success('提交成功',
|
||
{
|
||
position: 'top-center',
|
||
time: 550,
|
||
});
|
||
gotoDetailPartialNew(oiID);
|
||
}
|
||
else {
|
||
$.toastr.error('提交失败! <br />' + res.Message, {
|
||
time: 3000,
|
||
position: 'top-center'
|
||
});
|
||
}
|
||
|
||
}
|
||
});
|
||
};
|
||
|
||
function SetPPDate(projectID, oiID, datetime, value) {
|
||
$.ajax({
|
||
url: "/APP/PPlan/EditPPlanDate",//"@Url.Action("EditPPlanDate", "PPlan")",
|
||
type: "post",
|
||
data: { "projectID": projectID, "oiID": oiID, "datetime": datetime, "upDate": value },
|
||
dataType: "json",
|
||
success: function (res) {
|
||
if (res.Status == 200) {
|
||
$.toastr.success('提交成功',
|
||
{
|
||
position: 'top-center',
|
||
time: 550,
|
||
});
|
||
gotoDetailPartialNew(oiID);
|
||
}
|
||
else {
|
||
$.toastr.error('提交失败! <br />' + res.Message, {
|
||
time: 3000,
|
||
position: 'top-center'
|
||
});
|
||
}
|
||
|
||
}
|
||
});
|
||
};
|