zrg
2025-02-25 44edbbae5dcec2e084461e6b80af3972f893af06
Merge branch 'master' of http://101.37.171.70:10101/r/MES-WEB-LayUI
1个文件已修改
904 ■■■■■ 已修改文件
WebTM/views/生产管理/生产计划平台/JIT_DayPlanPlatForm_TK.html 904 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
WebTM/views/Éú²ú¹ÜÀí/Éú²ú¼Æ»®Æ½Ì¨/JIT_DayPlanPlatForm_TK.html
@@ -36,6 +36,7 @@
                            <button class="layui-btn layui-btn-normal" style="margin-left: 0px" type="button" lay-submit="" lay-filter="btnUnlockOrder" id="btnUnlockOrder">解锁工单</button>
                            <button class="layui-btn layui-btn-normal" style="margin-left: 0px" type="button" lay-submit="" lay-filter="btnGetCompletionDate" id="btnGetCompletionDate">获取完工日期</button>
                            <button class="layui-btn layui-btn-normal" style="margin-left: 0px" type="button" lay-submit="" lay-filter="btnGetEarlyDate" id="btnGetEarlyDate">获取最早开工日期</button>
                            <button class="layui-btn layui-btn-normal" style="margin-left: 0px" type="button" lay-submit="" lay-filter="btnProHJPC" id="btnProHJPC">焊接排产</button>
                        </div>
                        <div class="layui-collapse resizable-container">
                            <div class="layui-colla-item">
@@ -784,6 +785,29 @@
            }
        })
        //焊接排产
        form.on('submit(btnProHJPC)', function (data) {
            var HWorkShopID = $("#HWorkShopID").val();//生产车间
            if (HWorkShopID == 0) {
                return layer.msg("生产车间不能为空!");
            } else {
                var index = layer.open({
                    type: 1, // page å±‚类型
                    area: ['20%', '20%'],
                    shade: 0.6, // é®ç½©é€æ˜Žåº¦
                    shadeClose: false, // ç‚¹å‡»é®ç½©åŒºåŸŸï¼Œä¸å…³é—­å¼¹å±‚
                    maxmin: false, // ä¸å…è®¸å…¨å±æœ€å°åŒ–
                    anim: 0, // 0-6 çš„动画形式,-1 ä¸å¼€å¯
                    content: '<div style="padding: 12px;">正在运算,请耐心等待!!!</div>'
                });
                setTimeout(function () {
                    get_btnProHJPC(HWorkShopID);
                    layer.close(index);
                }, 1000)
            }
        })
        //工艺路线编辑
        form.on('submit(btnRoutEdit)', function (data) {
            get_btnRoutEdit();
@@ -1162,6 +1186,8 @@
            columns.push({ field: '计划结束日期', title: '计划结束日期', width: 150, templet: "<div>{{d.计划结束日期 ==null ?'':layui.util.toDateString(d.计划结束日期, 'yyyy-MM-dd')}}</div>", event: "HPlanEndDate", sort: true, filter: { type: 'date[yyyy-MM-dd HH:mm:ss]' } });
            columns.push({ field: '销售订单审核日期', title: '销售订单审核日期', width: 150, templet: "<div>{{d.销售订单审核日期 ==null ?'':layui.util.toDateString(d.销售订单审核日期, 'yyyy-MM-dd')}}</div>",sort: true, filter: { type: 'date[yyyy-MM-dd HH:mm:ss]' } });
            columns.push({ field: '操作工', title: '操作工', width: 150, edit: 'text', event: "HEmpID" });
            columns.push({ field: 'HMouldID', title: 'HMouldID', width: 150, hide: true });
            columns.push({ field: 'HMouldPCTime', title: 'HMouldPCTime', width: 150, hide: true });
            columns.push({ fixed: 'right', title: '操作', toolbar: '#barDemo' });
            option_columns = columns;
            option = {
@@ -2071,359 +2097,6 @@
            }
        }
        //排产
        function get_btnProPC(HWorkShopID) {
            var JDTLen = 0;
            var lMainID = 0;
            var sICMOBillNo = "";
            var dEndDate = "";
            var sProdTimes = 0;
            var sPlanQty = 0;
            var lHGroupID = 0;
            var sGroupName = "";
            var lMaterID = 0;
            var sMaterNumber = "";
            var sMaterName = "";
            var sMaterModel = "";
            var sWorkQty = 0;
            var sYX = 0;
            var iLeftQty = 0;
            var sLeftProdTimes = 0;
            var lSourceID = 0;
            var iRow = 0;
            var sSourceName = "";
            var sSourceNumber = "";
            var ds = [];
            var dsSub = [];
            var bFind = false;
            var HPlanDay = 0;
            var HDelData = 0;
            JDTLen = (100 / option.data.length).toFixed(2);
            var HJDLen = 0;
            var HReportQty = 0;
            //如果锁定计划,则不需要再排程
            //查询本车间是否有锁定计划的数据
            var HinterID_S = [];
            for (var i = 0; i < option.data.length; i++) {
                if (option.data[i]["小时产能"] == "0") {
                    return layer.msg("请先点击准备按钮,确保小时产能不为0!!!")
                }
                HinterID_S.push(option.data[i]["hmainid"]);
            }
            $.ajax({
                url: GetWEBURL() + '/JIT_DayPlanPlatFormBill/JIT_DayPlanPlatFormBillHinterIDList',
                type: "GET",
                async: false,
                data: { "sWhere": HinterID_S.toString(), "num": 1 },
                success: function (data1) {
                    if (data1.count == 1) {
                        HPlanDay = data1.data[0].DayNum;
                    } else {
                        layer.alert(data1.code + data1.Message, { icon: 5 });
                    }
                }, error: function () {
                    layer.alert("接口请求失败!", { icon: 5 });
                }
            });
            //根据车间删除没有锁定的数据
            var sql = "delete from Sc_WorkBillSortBillSub where HMasterDate>=convert(varchar(10) ,DATEADD(DAY," + HPlanDay + ",GETDATE()),20) and HInterID in(select  HInterID from Sc_WorkBillSortBillMain where HWorkShopID=" + HWorkShopID + " and HLockOrder != 1 )";
            $.ajax({
                url: GetWEBURL() + '/Gy_SOPBillList/UpDelSQL',
                type: "GET",
                async: false,
                data: { "sWhere": sql },
                success: function (data1) {
                    if (data1.count == 1) {
                    } else {
                        layer.alert(data1.code + data1.Message, { icon: 5 });
                    }
                }, error: function () {
                    layer.alert("接口请求失败!", { icon: 5 });
                }
            });
            get_HFData(0, 0);
            //初始化表格数据
            for (var i = 0; i < option.data.length; i++) {
                for (var j = (22 + HPlanDay); j < 53; j++) {
                    if (option.data[i][option.cols[0][j].field] != null) {
                        option.data[i][option.cols[0][j].field] = "";
                    }
                }
            }
            //get_FastQuery(2);
            //按任务单优先级 å¾ªçޝ
            for (var i = 0; i < option.data.length; i++) {
                //获取锁定的排产数量
                var SDSum = 0;
                if (HPlanDay > 0) {
                    for (var j = 22; j < (22 + HPlanDay); j++) {
                        SDSum += TableData[i][option.cols[0][j].field];
                    }
                }
                //找到本任务单 å¯ç”¨ç”Ÿäº§èµ„源
                lMainID = option.data[i]["HICMOInterID"];
                sICMOBillNo = option.data[i]["生产订单号"];
                dEndDate = Format(option.data[i]["最迟完工日期"], 'yyyy/MM/dd');
                sProdTimes = option.data[i]["生产周期"];
                sPlanQty = option.data[i]["拆单数量"];
                lHGroupID = option.data[i]["HGroupID"];
                sGroupName = option.data[i]["HGroupName"];
                lMaterID = option.data[i]["HMaterID"];
                sMaterNumber = option.data[i]["物料代码"];
                sMaterName = option.data[i]["物料名称"];
                sMaterModel = option.data[i]["规格型号"];
                sWorkQty = option.data[i]["小时产能"];
                sYX = option.data[i]["优先级"];
                HReportQty = option.data[i]["拆单汇报数量"];
                if (SDSum > 0) {
                    sPlanQty = sPlanQty - SDSum - HReportQty;
                }
                //剩余需求工时
                iLeftQty = sPlanQty - HReportQty;
                if (sWorkQty <= 0) {
                    sLeftProdTimes = 0;
                }
                else {
                    sLeftProdTimes = iLeftQty / sWorkQty;
                }
                //若本任务单已有安排资源(上次排程或者手工排程) åˆ™ä¸å†å¯»æ‰¾èµ„源,直接排程
                if (option.data[i]["HSourceID"] != 0 && option.data[i]["生产资源"] != "") {
                    //获取该生产资源的剩余工时进行排程。
                    lSourceID = option.data[i]["HSourceID"];
                    sSourceName = option.data[i]["生产资源"];
                    sSourceNumber = option.data[i]["生产资源代码"];
                    //查询生产资源的剩余工时进行排程。
                    var sql = "exec h_p_Sc_ICMOGetWorkSource2 " + lMaterID + ",'" + dEndDate + "'," + sProdTimes + "," + lSourceID;
                    $.ajax({
                        url: GetWEBURL() + '/Gy_SOPBillList/WindowPrintList',
                        type: "GET",
                        async: false,
                        data: { "sWhere": sql },
                        success: function (data1) {
                            if (data1.count == 1) {
                                ds = data1.data
                            } else {
                                layer.alert(data1.code + data1.Message, { icon: 5 });
                            }
                        }, error: function () {
                            layer.alert("接口请求失败!", { icon: 5 });
                        }
                    });
                }
                else //没有资源则 è‡ªåŠ¨æ‰¾åˆ°èµ„æº
                {
                    //查询生产资源的剩余工时进行排程。
                    var sql = "exec h_p_Sc_ICMOGetWorkSource " + lMaterID + ",'" + dEndDate + "'," + sProdTimes;
                    $.ajax({
                        url: GetWEBURL() + '/Gy_SOPBillList/WindowPrintList',
                        type: "GET",
                        async: false,
                        data: { "sWhere": sql },
                        success: function (data1) {
                            if (data1.count == 1) {
                                ds = data1.data
                            } else {
                                layer.alert(data1.code + data1.Message, { icon: 5 });
                            }
                        }, error: function () {
                            layer.alert("接口请求失败!", { icon: 5 });
                        }
                    });
                }
                if (ds == null || ds.length == 0) //没有可以排的资源
                {
                    get_HFData(1, i);
                    //跳到下一单  æœ¬å•红色显示
                    $("tr[data-index='" + i + "']").attr({ "style": "background:red;color:black;" });
                    continue;
                }
                else {
                    $("tr[data-index='" + i + "']").attr({ "style": "background:White;color:black;" });
                    //开始排单
                    bFind = false;
                    //超交货期  ä»ç„¶æŽ’程
                    for (var j = 0; j < ds.length; j++) {
                        //判断资源剩余工时,是否大于 ç”Ÿäº§å‘¨æœŸ
                        if (parseFloat(ds[j]["剩余工时"]) >= sLeftProdTimes) {
                            if (iLeftQty > 0) // ç”Ÿäº§è®¢å•剩余数量
                            {
                                //在本资源上生产
                                //获取该生产资源的剩余工时进行排程。
                                lSourceID = ds[j]["HitemID"];
                                sSourceName = ds[j]["资源名称"];
                                sSourceNumber = ds[j]["资源代码"];
                                option.data[i]["HSourceID"] = lSourceID;
                                option.data[i]["生产资源"] = sSourceName;
                                option.data[i]["生产资源代码"] = sSourceNumber;
                                var sql = "exec h_p_Sc_ICMOGetWorkSourceTime " + lSourceID;
                                $.ajax({
                                    url: GetWEBURL() + '/Gy_SOPBillList/WindowPrintList',
                                    type: "GET",
                                    async: false,
                                    data: { "sWhere": sql },
                                    success: function (data1) {
                                        if (data1.count == 1) {
                                            dsSub = data1.data
                                        } else {
                                            layer.alert(data1.code + data1.Message, { icon: 5 });
                                        }
                                    }, error: function () {
                                        layer.alert("接口请求失败!", { icon: 5 });
                                    }
                                });
                                if (dsSub == null || dsSub.length == 0) {
                                    get_HFData(1, i);
                                    continue;//如果没有剩余则 æ‰§è¡Œä¸‹ä¸€ä¸ªç”Ÿäº§è®¢å•
                                }
                                if (dsSub != null)//不加班排程
                                {
                                    iRow = i + 1;
                                    //将数据排到网格中
                                    SetInfoToGrid(option, dsSub, null, (iRow - 1), iLeftQty, sWorkQty, false, HPlanDay);
                                    set_AddNew1(option.data[i]);
                                }
                                bFind = true;
                            }
                        } else {
                            get_HFData(1, i);
                        }
                    }
                    //if (!bFind) {
                    //    for (var j = 0; j < ds.length; j++) {
                    //        //判断资源最大剩余工时,是否大于 ç”Ÿäº§å‘¨æœŸ
                    //        if (parseFloat(ds[j]["最大剩余工时"]) > sLeftProdTimes) {
                    //            if (iLeftQty > 0) {
                    //                //在本资源上生产
                    //                grdMain.RowCount = grdMain.RowCount + 1;
                    //                //获取该生产资源的剩余工时进行排程。
                    //                lSourceID = ds[j]["HitemID"];
                    //                sSourceName = ds[j]["资源名称"];
                    //                sSourceNumber = ds[j]["资源代码"];
                    //                option.data[i]["HSourceID"] = lSourceID;
                    //                option.data[i]["生产资源"] = sSourceName;
                    //                option.data[i]["生产资源代码"] = sSourceNumber;
                    //                var sql = "exec h_p_Sc_ICMOGetWorkSourceTime " + lSourceID;
                    //                $.ajax({
                    //                    url: GetWEBURL() + '/Gy_SOPBillList/WindowPrintList',
                    //                    type: "GET",
                    //                    async: false,
                    //                    data: { "sWhere": sql },
                    //                    success: function (data1) {
                    //                        if (data1.count == 1) {
                    //                            dsSub = data1.data
                    //                        } else {
                    //                            layer.alert(data1.code + data1.Message, { icon: 5 });
                    //                        }
                    //                    }, error: function () {
                    //                        layer.alert("接口请求失败!", { icon: 5 });
                    //                    }
                    //                });
                    //                if (dsSub == null || dsSub.length == 0) {
                    //                    continue;
                    //                }
                    //                //if (dsSub != null)//加班排程
                    //                //{
                    //                //    //将数据排到网格中
                    //                //    grdMain.RowCount = grdMain.RowCount + 1;  //  grdmain æ–°å¢žä¸€è¡Œ
                    //                //    grdMain.Rows[grdMain.RowCount - 1].Cells[HSecICMOBillNoCol].Value = sICMOBillNo;
                    //                //    grdMain.Rows[grdMain.RowCount - 1].Cells[HSecICMOInterIDCol].Value = lMainID;
                    //                //    grdMain.Rows[grdMain.RowCount - 1].Cells[HSecLeftQtyCol].Value = iLeftQty;
                    //                //    grdMain.Rows[grdMain.RowCount - 1].Cells[HSecGroupIDCol].Value = lHGroupID;
                    //                //    grdMain.Rows[grdMain.RowCount - 1].Cells[HSecGroupNameCol].Value = sGroupName;
                    //                //    grdMain.Rows[grdMain.RowCount - 1].Cells[HSecMaterIDCol].Value = lMaterID;
                    //                //    grdMain.Rows[grdMain.RowCount - 1].Cells[HSecMaterNameCol].Value = sMaterName;
                    //                //    grdMain.Rows[grdMain.RowCount - 1].Cells[HSecMaterNumberCol].Value = sMaterNumber;
                    //                //    grdMain.Rows[grdMain.RowCount - 1].Cells[HSecMaterModelCol].Value = sMaterModel;
                    //                //    grdMain.Rows[grdMain.RowCount - 1].Cells[HSecPlanEndDateCol].Value = dEndDate;
                    //                //    grdMain.Rows[grdMain.RowCount - 1].Cells[HSecPlanQtyCol].Value = sPlanQty;
                    //                //    grdMain.Rows[grdMain.RowCount - 1].Cells[HSecSourceIDCol].Value = lSourceID;
                    //                //    grdMain.Rows[grdMain.RowCount - 1].Cells[HSecSourceNameCol].Value = sSourceName;
                    //                //    grdMain.Rows[grdMain.RowCount - 1].Cells[HSecSourceNumberCol].Value = sSourceNumber;
                    //                //    grdMain.Rows[grdMain.RowCount - 1].Cells[HSecYXCol].Value = sYX;
                    //                //    Sc_ICMOSortBillFun.SetInfoToGrid(grdMain, dsSub, null, grdMain.RowCount - 1, ref iLeftQty, sWorkQty, true, oClsGridValues);
                    //                //}
                    //            }
                    //            bFind = true;
                    //        }
                    //    }
                    //}
                    //if (!bFind) {
                    //    //如果没有找到合适资源则,直接排最后一个剩余最大的资源。
                    //    //获取该生产资源的剩余工时进行排程。
                    //    lSourceID = ds[ds.length - 1]["HitemID"];
                    //    sSourceName = ds[ds.length - 1]["资源名称"];
                    //    sSourceNumber = ds[ds.length - 1]["资源代码"];
                    //    option.data[i]["HSourceID"] = lSourceID;
                    //    option.data[i]["生产资源"] = sSourceName;
                    //    option.data[i]["生产资源代码"] = sSourceNumber;
                    //    //获取该生产资源的剩余工时进行排程。
                    //    var sql = "exec h_p_Sc_ICMOGetWorkSourceTime " + lSourceID;
                    //    $.ajax({
                    //        url: GetWEBURL() + '/Gy_SOPBillList/WindowPrintList',
                    //        type: "GET",
                    //        async: false,
                    //        data: { "sWhere": sql },
                    //        success: function (data1) {
                    //            if (data1.count == 1) {
                    //                dsSub = data1.data
                    //            } else {
                    //                layer.alert(data1.code + data1.Message, { icon: 5 });
                    //            }
                    //        }, error: function () {
                    //            layer.alert("接口请求失败!", { icon: 5 });
                    //        }
                    //    });
                    //    if (dsSub == null || dsSub.length == 0) {
                    //        continue;
                    //    }
                    //    //if (dsSub != null)//加班排程
                    //    //{
                    //    //    //将数据排到网格中
                    //    //    grdMain.RowCount = grdMain.RowCount + 1;  //  grdmain æ–°å¢žä¸€è¡Œ
                    //    //    grdMain.Rows[grdMain.RowCount - 1].Cells[HSecICMOBillNoCol].Value = sICMOBillNo;
                    //    //    grdMain.Rows[grdMain.RowCount - 1].Cells[HSecICMOInterIDCol].Value = lMainID;
                    //    //    grdMain.Rows[grdMain.RowCount - 1].Cells[HSecLeftQtyCol].Value = iLeftQty;
                    //    //    grdMain.Rows[grdMain.RowCount - 1].Cells[HSecGroupIDCol].Value = lHGroupID;
                    //    //    grdMain.Rows[grdMain.RowCount - 1].Cells[HSecGroupNameCol].Value = sGroupName;
                    //    //    grdMain.Rows[grdMain.RowCount - 1].Cells[HSecMaterIDCol].Value = lMaterID;
                    //    //    grdMain.Rows[grdMain.RowCount - 1].Cells[HSecMaterNameCol].Value = sMaterName;
                    //    //    grdMain.Rows[grdMain.RowCount - 1].Cells[HSecMaterNumberCol].Value = sMaterNumber;
                    //    //    grdMain.Rows[grdMain.RowCount - 1].Cells[HSecMaterModelCol].Value = sMaterModel;
                    //    //    grdMain.Rows[grdMain.RowCount - 1].Cells[HSecPlanEndDateCol].Value = dEndDate;
                    //    //    grdMain.Rows[grdMain.RowCount - 1].Cells[HSecPlanQtyCol].Value = sPlanQty;
                    //    //    grdMain.Rows[grdMain.RowCount - 1].Cells[HSecSourceIDCol].Value = lSourceID;
                    //    //    grdMain.Rows[grdMain.RowCount - 1].Cells[HSecSourceNameCol].Value = sSourceName;
                    //    //    grdMain.Rows[grdMain.RowCount - 1].Cells[HSecSourceNumberCol].Value = sSourceNumber;
                    //    //    grdMain.Rows[grdMain.RowCount - 1].Cells[HSecYXCol].Value = sYX;
                    //    //    Sc_ICMOSortBillFun.SetInfoToGrid(grdMain, dsSub, null, grdMain.RowCount - 1, ref iLeftQty, sWorkQty, true, oClsGridValues);
                    //    //}
                    //}
                }
            }
            table.render(option);
        }
        //组装排产
        function get_btnProZZPC(HWorkShopID) {
            var JDTLen = 0;
@@ -2771,6 +2444,444 @@
            get_FastQuery(2);
        }
        //焊接排产
        function get_btnProHJPC(HWorkShopID) {
            var JDTLen = 0;
            var lMainID = 0;
            var sICMOBillNo = "";
            var dEndDate = "";
            var sProdTimes = 0;
            var sPlanQty = 0;
            var lHGroupID = 0;
            var sGroupName = "";
            var lMaterID = 0;
            var sMaterNumber = "";
            var sMaterName = "";
            var sMaterModel = "";
            var sWorkQty = 0;
            var sYX = 0;
            var iLeftQty = 0;
            var sLeftProdTimes = 0;
            var lSourceID = 0;
            var iRow = 0;
            var sSourceName = "";
            var sSourceNumber = "";
            var ds = [];
            var dsSub = [];
            var bFind = false;
            var HPlanDay = 0;
            var HDelData = 0;
            JDTLen = (100 / option.data.length).toFixed(2);
            var HJDLen = 0;
            var HReportQty = 0;
            //如果锁定计划,则不需要再排程
            //查询本车间是否有锁定计划的数据
            var HinterID_S = [];
            for (var i = 0; i < option.data.length; i++) {
                //if (option.data[i]["小时产能"] == "0") {
                //    return layer.msg("请先点击准备按钮,确保小时产能不为0!!!")
                //}
                HinterID_S.push(option.data[i]["hmainid"]);
            }
            $.ajax({
                url: GetWEBURL() + '/JIT_DayPlanPlatFormBill/JIT_DayPlanPlatFormBillHinterIDList',
                type: "GET",
                async: false,
                data: { "sWhere": HinterID_S.toString(), "num": 1 },
                success: function (data1) {
                    if (data1.count == 1) {
                        HPlanDay = data1.data[0].DayNum;
                    } else {
                        layer.alert(data1.code + data1.Message, { icon: 5 });
                    }
                }, error: function () {
                    layer.alert("接口请求失败!", { icon: 5 });
                }
            });
            //根据车间删除没有锁定的数据
            var sql = "delete from Sc_WorkBillSortBillSub where HMasterDate>=convert(varchar(10) ,DATEADD(DAY," + HPlanDay + ",GETDATE()),20) and HInterID in(select  HInterID from Sc_WorkBillSortBillMain where HWorkShopID=" + HWorkShopID + " and HLockOrder != 1 )";
            $.ajax({
                url: GetWEBURL() + '/Gy_SOPBillList/UpDelSQL',
                type: "GET",
                async: false,
                data: { "sWhere": sql },
                success: function (data1) {
                    if (data1.count == 1) {
                    } else {
                        layer.alert(data1.code + data1.Message, { icon: 5 });
                    }
                }, error: function () {
                    layer.alert("接口请求失败!", { icon: 5 });
                }
            });
            //根据车间删除器具占用时间
            var sql2 = "delete from Gy_MouldOccupancyTime where HICMOEntryID not in ( select HICMOEntryID from Sc_WorkBillSortBillMain where HInterID in (select HInterID from Sc_WorkBillSortBillSub))";
            $.ajax({
                url: GetWEBURL() + '/Gy_SOPBillList/UpDelSQL',
                type: "GET",
                async: false,
                data: { "sWhere": sql2 },
                success: function (data1) {
                    if (data1.count == 1) {
                    } else {
                        layer.alert(data1.code + data1.Message, { icon: 5 });
                    }
                }, error: function () {
                    layer.alert("接口请求失败!", { icon: 5 });
                }
            });
            get_HFData(0, 0);
            //初始化表格数据
            for (var i = 0; i < option.data.length; i++) {
                for (var j = (22 + HPlanDay); j < 53; j++) {
                    if (option.data[i][option.cols[0][j].field] != null) {
                        option.data[i][option.cols[0][j].field] = "";
                    }
                }
            }
            //get_FastQuery(2);
            //为防止用户手动篡改优先级,重新根据优先级排序数组
            option.data.sort(function (a, b) {
                return a.优先级 - b.优先级
            });
            window.HPCDate = Format(new Date().toLocaleDateString().replaceAll('/', '-'), 'yyyy/MM/dd') //当前排产日期
            window.HArrIndex = []; //用于存储因为当前日期不满足最早开工日期而未能排产的订单下标
            window.HArrIndex_PC = [];//用于存储已经排产的订单下标
            window.HIsPriority = false;//是否优先排产
            var HDataLen = option.data.length;//总排产订单长度
            var HProgress = parseInt(100 / HDataLen);
            var HCount = 0;
            //按任务单优先级 å¾ªçޝ
            for (var i = 0; i < HDataLen; i++) {
                HCount++;
                if (HCount > 50000) {
                    break;
                }
                var old_date = new Date();
                //element.progress('demo', (i + 1) * HProgress + '%')
                //判断数组长度是否发生变化,是则重置数组长度
                if (HDataLen != option.data.length) {
                    HDataLen = option.data.length;
                    if (i == option.data.length) {
                        i = option.data.length - 1;
                    }
                }
                console.log("1.开始排产第" + (i + 1) + "行订单:" + option.data[i].生产订单号 + ",当前排产日期:" + HPCDate + ",最早开工日期:" + option.data[i].最早开工日期);
                //排产最后一笔订单(若本次为最后一笔订单排产,但当前排产日期还不满足最早开工日期,则当前日期进行累加,直到满足最早开工日期为止)
                if (HArrIndex_PC.length == option.data.length - 1 && HArrIndex.length > 0 && Format(option.data[HArrIndex[0]].最早开工日期, 'yyyy/MM/dd') > HPCDate) {
                    for (var k = 0; k < 100; k++) {
                        //排产日期往后推一天
                        var dateTime = new Date(HPCDate);
                        HPCDate = Format(new Date(dateTime.setDate(dateTime.getDate() + 1)), 'yyyy/MM/dd');
                        //当前排产日期满足最早开工日期,终止累加
                        if (Format(option.data[HArrIndex[0]].最早开工日期, 'yyyy/MM/dd') <= HPCDate) {
                            break;
                        }
                    }
                }
                //判断是否有未排产的订单,若有则补排
                if (HArrIndex.length > 0 && (HIsPriority == false || HArrIndex.length + HArrIndex_PC.length == option.data.length)) {//(HIsPriority == false || HArrIndex.length >= 2)
                    //对先前未能排产的订单进行排序
                    HArrIndex.sort(function (a, b) { return a - b });
                    //获取之前排产时未能排产的订单
                    i = HArrIndex[0];
                    var index = 0;
                    //如果存在多个之前未能排产的订单,则看哪个订单能够优先满足最早开工日期,优先排产
                    if (HArrIndex.length > 1) {
                        //排产日期往后推一天
                        var dateTime = new Date(HPCDate);
                        HPCDate = Format(new Date(dateTime.setDate(dateTime.getDate() + 1)), 'yyyy/MM/dd');
                        for (var j = 0; j < HArrIndex.length; j++) {
                            //匹配到满足最早开工日期的订单,把这个订单优先拿去排产,并终止循环匹配
                            if (Format(option.data[HArrIndex[j]].最早开工日期, 'yyyy/MM/dd') <= HPCDate) {
                                i = HArrIndex[j];
                                index = j;
                                break;
                            }
                        }
                    }
                    //移除未排产订单信息
                    HArrIndex.splice(index, 1)
                }
                //如果当前订单的最早开工日期不满足当前排产日期(最早开工日期 > å½“前排产日期),则跳出当前订单的排产,先排下一个订单
                if (Format(option.data[i].最早开工日期, 'yyyy/MM/dd') > HPCDate) {
                    if (HArrIndex.indexOf(i) == -1) {
                        HArrIndex.push(i);
                    }
                    HIsPriority = true;
                    //为满足最后一笔匹配订单也能进行排产,改变总排产订单数组长度,继续循环匹配
                    if (HArrIndex.length > 0 && i == HDataLen - 1) {
                        HDataLen = HDataLen + 1;
                    }
                    continue;
                }
                //如果当前行订单已经排产过,则跳出当前订单排产,接着下一行订单的排产
                if (HArrIndex_PC.indexOf(i) != -1) {
                    continue;
                }
                //记录已经排产的订单下标
                HArrIndex_PC.push(i);
                //console.log("2.开始排产第" + (i + 1) + "行订单:" + option.data[i].生产订单号 + ",当前排产日期:" + HPCDate + ",最早开工日期:" + option.data[i].最早开工日期);
                //如果本次最后一笔订单排产,但还存在因最早开工日期不满足的而排产不了的订单则加长循环长度
                if (i == HDataLen - 1 && HArrIndex.length > 0) {
                    HDataLen = HDataLen + 1;
                }
                //获取锁定的排产数量
                var SDSum = 0;
                if (HPlanDay > 0) {
                    for (var j = 22; j < (22 + HPlanDay); j++) {
                        SDSum += TableData[i][option.cols[0][j].field];
                    }
                }
                //找到本任务单 å¯ç”¨ç”Ÿäº§èµ„源
                lMainID = option.data[i]["HICMOInterID"];
                sICMOBillNo = option.data[i]["生产订单号"];
                dEndDate = Format(option.data[i]["最迟完工日期"], 'yyyy/MM/dd');
                sProdTimes = option.data[i]["生产周期"];
                sPlanQty = option.data[i]["拆单数量"];
                lHGroupID = option.data[i]["HGroupID"];
                sGroupName = option.data[i]["HGroupName"];
                lMaterID = option.data[i]["HMaterID"];
                sMaterNumber = option.data[i]["物料代码"];
                sMaterName = option.data[i]["物料名称"];
                sMaterModel = option.data[i]["规格型号"];
                sWorkQty = option.data[i]["小时产能"];
                sYX = option.data[i]["优先级"];
                HReportQty = option.data[i]["拆单汇报数量"];
                if (SDSum > 0) {
                    sPlanQty = sPlanQty - SDSum - HReportQty;
                }
                //剩余需求工时
                iLeftQty = sPlanQty - HReportQty;
                if (sWorkQty <= 0) {
                    sLeftProdTimes = 0;
                }
                else {
                    sLeftProdTimes = iLeftQty / sWorkQty;
                }
                var HIsContinue = false;    //是否能匹配到合适的产品器具清单,匹配不到则跳过当前订单
                //若本任务单已有安排资源(上次排程或者手工排程) åˆ™ä¸å†å¯»æ‰¾èµ„源,直接排程
                if (option.data[i]["HSourceID"] != 0 && option.data[i]["生产资源"] != "") {
                    //获取该生产资源的剩余工时进行排程。
                    lSourceID = option.data[i]["HSourceID"];
                    sSourceName = option.data[i]["生产资源"];
                    sSourceNumber = option.data[i]["生产资源代码"];
                    //查询生产资源的剩余工时进行排程。
                    var sql = "exec h_p_Sc_ICMOGetWorkSource2 " + lMaterID + ",'" + dEndDate + "'," + sProdTimes + "," + lSourceID;
                    $.ajax({
                        url: GetWEBURL() + '/Gy_SOPBillList/WindowPrintList',
                        type: "GET",
                        async: false,
                        data: { "sWhere": sql },
                        success: function (data1) {
                            if (data1.count == 1) {
                                ds = data1.data
                                //看是否能匹配到满足生产条件的产品器具清单
                                var HMaterMouldData = get_MouldByMater(lMaterID, lSourceID);
                                if (HMaterMouldData.length < 1) {
                                    //没有匹配到器具,生产不了,把订单挂到待排产列表中,先匹配下一优先级的订单
                                    if (HArrIndex.indexOf(i) == -1) {
                                        HArrIndex.push(i);
                                    }
                                    HIsPriority = true;
                                    //为满足最后一笔匹配订单也能进行排产,改变总排产订单数组长度,继续循环匹配
                                    if (HArrIndex.length > 0 && i == HDataLen - 1) {
                                        HDataLen = HDataLen + 1;
                                    }
                                    HIsContinue = true;
                                } else {
                                    //判断匹配出的器具是否能在此资源上使用
                                    var HSourceMouldData = get_MouldBySource(lSourceID, HMaterMouldData[0].HMouldID);
                                    if (HSourceMouldData.length < 1) {
                                        //没有匹配到资源器具清单,生产不了,把订单挂到待排产列表中,先匹配下一优先级的订单
                                        if (HArrIndex.indexOf(i) == -1) {
                                            HArrIndex.push(i);
                                        }
                                        HIsPriority = true;
                                        //为满足最后一笔匹配订单也能进行排产,改变总排产订单数组长度,继续循环匹配
                                        if (HArrIndex.length > 0 && i == HDataLen - 1) {
                                            HDataLen = HDataLen + 1;
                                        }
                                        HIsContinue = true;
                                    }
                                    option.data[i].HMouldID = HMaterMouldData[0].HMouldID;
                                    option.data[i].HMouldPCTime = HMaterMouldData[0].HPCTime;
                                }
                            } else {
                                layer.alert(data1.code + data1.Message, { icon: 5 });
                            }
                        }, error: function () {
                            layer.alert("接口请求失败!", { icon: 5 });
                        }
                    });
                }
                else //没有资源则 è‡ªåŠ¨æ‰¾åˆ°èµ„æº
                {
                    //查询生产资源的剩余工时进行排程。
                    var sql = "exec h_p_Sc_ICMOGetWorkSource_TK " + lMaterID + ",'" + dEndDate + "'," + sProdTimes;
                    $.ajax({
                        url: GetWEBURL() + '/Gy_SOPBillList/WindowPrintList',
                        type: "GET",
                        async: false,
                        data: { "sWhere": sql },
                        success: function (data1) {
                            if (data1.count == 1) {
                                ds = data1.data
                                if (ds.length > 0) {
                                    //看是否能匹配到满足生产条件的产品器具清单
                                    var HMaterMouldData = get_MouldByMater(lMaterID, ds[0]["HitemID"]);
                                    if (HMaterMouldData.length < 1) {
                                        //没有匹配到器具,生产不了,把订单挂到待排产列表中,先匹配下一优先级的订单
                                        if (HArrIndex.indexOf(i) == -1) {
                                            HArrIndex.push(i);
                                        }
                                        HIsPriority = true;
                                        //为满足最后一笔匹配订单也能进行排产,改变总排产订单数组长度,继续循环匹配
                                        if (HArrIndex.length > 0 && i == HDataLen - 1) {
                                            HDataLen = HDataLen + 1;
                                        }
                                        HIsContinue = true;
                                    } else {
                                        //判断匹配出的器具是否能在此资源上使用
                                        var HSourceMouldData = get_MouldBySource(ds[0]["HitemID"], HMaterMouldData[0].HMouldID);
                                        if (HSourceMouldData.length < 1) {
                                            //没有匹配到资源器具清单,生产不了,把订单挂到待排产列表中,先匹配下一优先级的订单
                                            if (HArrIndex.indexOf(i) == -1) {
                                                HArrIndex.push(i);
                                            }
                                            HIsPriority = true;
                                            //为满足最后一笔匹配订单也能进行排产,改变总排产订单数组长度,继续循环匹配
                                            if (HArrIndex.length > 0 && i == HDataLen - 1) {
                                                HDataLen = HDataLen + 1;
                                            }
                                            HIsContinue = true;
                                        }
                                    }
                                }
                            } else {
                                layer.alert(data1.code + data1.Message, { icon: 5 });
                            }
                        }, error: function () {
                            layer.alert("接口请求失败!", { icon: 5 });
                        }
                    });
                }
                //是否能匹配到合适的产品器具清单,匹配不到则跳过当前订单
                if (HIsContinue) {
                    continue;
                }
                if (ds == null || ds.length == 0) //没有可以排的资源
                {
                    get_HFData(1, i);
                    //跳到下一单  æœ¬å•红色显示
                    $("tr[data-index='" + i + "']").attr({ "style": "background:red;color:black;" });
                    HBackgroundColorIndex.push(i);
                    continue;
                }
                else {
                    $("tr[data-index='" + i + "']").attr({ "style": "background:White;color:black;" });
                    //开始排单
                    bFind = false;
                    //超交货期  ä»ç„¶æŽ’程
                    for (var j = 0; j < ds.length; j++) {
                        //判断资源剩余工时,是否大于 ç”Ÿäº§å‘¨æœŸ
                        if (parseFloat(ds[j]["剩余工时"]) >= sLeftProdTimes) {
                            if (iLeftQty > 0) // ç”Ÿäº§è®¢å•剩余数量
                            {
                                //在本资源上生产
                                //获取该生产资源的剩余工时进行排程。
                                lSourceID = ds[j]["HitemID"];
                                sSourceName = ds[j]["资源名称"];
                                sSourceNumber = ds[j]["资源代码"];
                                option.data[i]["HSourceID"] = lSourceID;
                                option.data[i]["生产资源"] = sSourceName;
                                option.data[i]["生产资源代码"] = sSourceNumber;
                                console.log("======" + "第" + (i + 1) + "行订单:" + option.data[i].生产订单号 + ", è‡ªåŠ¨åŒ¹é…" + ds.length + "个生产资源,最终选择:" + sSourceName);
                                var sql = "exec h_p_Sc_ICMOGetWorkSourceTime " + lSourceID;
                                $.ajax({
                                    url: GetWEBURL() + '/Gy_SOPBillList/WindowPrintList',
                                    type: "GET",
                                    async: false,
                                    data: { "sWhere": sql },
                                    success: function (data1) {
                                        if (data1.count == 1) {
                                            dsSub = data1.data
                                        } else {
                                            layer.alert(data1.code + data1.Message, { icon: 5 });
                                        }
                                    }, error: function () {
                                        layer.alert("接口请求失败!", { icon: 5 });
                                    }
                                });
                                if (dsSub == null || dsSub.length == 0) {
                                    get_HFData(1, i);
                                    continue;//如果没有剩余则 æ‰§è¡Œä¸‹ä¸€ä¸ªç”Ÿäº§è®¢å•
                                }
                                if (dsSub != null)//不加班排程
                                {
                                    iRow = i + 1;
                                    //将数据排到网格中
                                    SetInfoToGrid(option, dsSub, null, (iRow - 1), iLeftQty, sWorkQty, false, HPlanDay);
                                    set_AddNew_HJPC(option.data[i]);
                                }
                                bFind = true;
                                break;
                            }
                        } else {
                            get_HFData(1, i);
                        }
                    }
                }
                var new_date = new Date();
                var difftime = (new_date - old_date) / 1000; //计算时间差,并把毫秒转换成秒
                var days = parseInt(difftime / 86400); // å¤©  24*60*60*1000
                var hours = parseInt(difftime / 3600) - 24 * days;    // å°æ—¶ 60*60 æ€»å°æ—¶æ•°-过去的小时数=现在的小时数
                var minutes = parseInt(difftime % 3600 / 60); // åˆ†é’Ÿ -(day*24) ä»¥60秒为一整份 å–ä½™ å‰©ä¸‹ç§’æ•° ç§’æ•°/60 å°±æ˜¯åˆ†é’Ÿæ•°
                var seconds = parseInt(difftime % 60);  // ä»¥60秒为一整份 å–ä½™ å‰©ä¸‹ç§’æ•°
                console.log("时间差是: " + days + "天, " + hours + "小时, " + minutes + "分钟, " + seconds + "秒");
            }
            table.render(option);
            get_FastQuery(2);
        }
        var TableData = [];
        function get_HFData(num,nums) {
            if (num == 0) {
@@ -3036,6 +3147,48 @@
                }
            }
        }
        //物料匹配产品器具清单
        function get_MouldByMater(HMaterID, HSourceID) {
            var HReturnData = [];
            $.ajax({
                url: GetWEBURL() + '/JIT_DayPlanPlatFormBill/GetMouldByMater',
                type: "GET",
                async: false,
                data: { "HMaterID": HMaterID, "HSourceID": HSourceID },
                success: function (data1) {
                    if (data1.count == 1) {
                        HReturnData = data1.data;
                    } else {
                        console.log(new Date() + ",匹配产品器具清单出错1");
                    }
                }, error: function () {
                    console.log(new Date() + ",匹配产品器具清单出错1");
                }
            });
            return HReturnData;
        }
        //资源匹配资源器具清单
        function get_MouldBySource(HSourceID, HMouldID) {
            var HReturnData = [];
            $.ajax({
                url: GetWEBURL() + '/JIT_DayPlanPlatFormBill/GetMouldBySource',
                type: "GET",
                async: false,
                data: { "HSourceID": HSourceID, "HMouldID": HMouldID },
                success: function (data1) {
                    if (data1.count == 1) {
                        HReturnData = data1.data;
                    } else {
                        console.log(new Date() + ",匹配产品器具清单出错1");
                    }
                }, error: function () {
                    console.log(new Date() + ",匹配产品器具清单出错1");
                }
            });
            return HReturnData;
        }
        //查询生产订单
@@ -3497,6 +3650,51 @@
            });
        }
        function set_AddNew_HJPC(num) {
            //var sMainStr = JSON.stringify(data.field);
            var sSubStr = "[" + JSON.stringify(num) + "]";
            var sMainSub = sSubStr + "&和" + sessionStorage["HUserName"];
            //var index = layer.load();
            $.ajax({
                type: "POST",
                url: GetWEBURL() + "/JIT_DayPlanPlatFormBill/JIT_DayPlanPlatFormBill_btnSave",
                async: false,
                data: { "sMainSub": sMainSub },
                dataType: "json",
                success: function (data) {
                    if (data.count == 1) {
                        $.ajax({
                            url: GetWEBURL() + '/JIT_DayPlanPlatFormBill/AddMouldOccupancyTime',
                            type: "GET",
                            async: false,
                            data: { "HMouldID": num.HMouldID, "HSourceID": num.HSourceID, "HICMOInterID": num.HICMOInterID, "HICMOEntryID": num.HICMOEntryID, "HMouldPCTime": num.HMouldPCTime },
                            success: function (data1) {
                                if (data1.count == 1) {
                                } else {
                                    layer.alert(data1.code + data1.Message, { icon: 5 });
                                }
                            }, error: function () {
                                layer.alert("接口请求失败!", { icon: 5 });
                            }
                        });
                    }
                    else {
                        //layer.close(index);
                        layer.msg(data.Message, { icon: 5, btn: ['确认'], time: 100000, offset: 't', skin: 'layui-layer-lan', title: "温馨提示" });
                    }
                },
                error: function (err) {
                    //layer.close(index);
                    layer.msg("错误:" + err, { icon: 5, btn: ['确认'], time: 100000, offset: 't', skin: 'layui-layer-lan', title: "温馨提示" });
                }
            });
        }
        //行内快捷键
        function set_GridCellCheck(obj) {
            $(document).off('keydown', ".layui-table-edit").on('keydown', '.layui-table-edit', function (e) {