yangle
2023-10-26 8cf62e71565cf44dae2e56d1d9c62aabe1e6117e
WebTM/views/Éú²ú¹ÜÀí/Éú²ú¼Æ»®Æ½Ì¨/JIT_DayPlanPlatForm.html
@@ -26,6 +26,8 @@
                            <button class="layui-btn layui-btn-normal" style="margin-left: 0px" type="button" lay-submit="" lay-filter="btnCompleteSetAnalysis" id="btnCompleteSetAnalysis">齐套分析</button>
                            <button class="layui-btn layui-btn-normal" style="margin-left: 0px" type="button" lay-submit="" lay-filter="btnTLYS" id="btnTLYS">提料运算</button>
                            <button class="layui-btn layui-btn-normal" style="margin-left: 0px" type="button" lay-submit="" lay-filter="btnICMOBill" id="btnICMOBill">生产订单选单</button>
                            <button class="layui-btn layui-btn-normal" style="margin-left: 0px" type="button" lay-submit="" lay-filter="btnReady" id="btnReady">准备</button>
                            <button class="layui-btn layui-btn-normal" style="margin-left: 0px" type="button" lay-submit="" lay-filter="btnProPC" id="btnProPC">排产</button>
                        </div>
                        <div class="layui-collapse">
                            <div class="layui-colla-item">
@@ -41,13 +43,16 @@
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label" style="width: 85px;">生产订单组织</label>
                                    <label class="layui-form-label" style="width: 85px;">提料类型</label>
                                    <div class="layui-input-block" style="margin-left: 120px; width: 185px;">
                                        <select name="HProdORGID" id="HProdORGID" lay-verify="HProdORGID">
                                            <!--动态渲染组织-->
                                        <select name="HTLType" id="HTLType" lay-verify="HTLType">
                                            <option value="缺料" selected="selected">缺料</option>
                                            <option value="生产用料清单">生产用料清单</option>
                                            <!--<option value="采购订单">采购订单</option> æš‚时没有-->
                                        </select>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label" style="width: 85px;padding: 9px 18px;">生产车间</label>
                                    <div class="layui-input-block" style="margin-left: 77px;">
@@ -72,7 +77,7 @@
                                            <label class="layui-form-label" style="width: 85px;padding: 9px 18px;">物料编码</label>
                                            <div class="layui-input-block" style="margin-left: 77px;">
                                                <input type="hidden" class="layui-input" lay-verify="HMaterID" name="HMaterID" id="HMaterID" value="0" style="background-color:#efefef4d;width: 60%;display: inline-block;" readonly>
                                                <input type="text" class="layui-input" lay-verify="HMaterNumber" name="HMaterNumber" id="HMaterNumber" value="" style="background-color:#efefef4d;width: 60%;display: inline-block;" readonly>
                                                <input type="text" class="layui-input" lay-verify="HMaterNumber" name="HMaterNumber" id="HMaterNumber" value="" style="width: 60%;display: inline-block;">
                                                <button class="layui-btn layuiadmin-btn-order" type="button" lay-submit="" lay-filter="btnHMaterID" id="btnHMaterID" style="padding: 0 10px;float: right;margin-right: 3px;">
                                                    <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                                                </button>
@@ -95,15 +100,14 @@
                                        <div class="layui-inline">
                                            <label class="layui-form-label" style="width: 85px;">物料名称</label>
                                            <div class="layui-input-block" style="margin-left: 120px;">
                                                <input type="text" class="layui-input" name="HMaterName" id="HMaterName" style="background-color:#efefef4d" readonly>
                                                <input type="text" class="layui-input" name="HMaterName" id="HMaterName">
                                            </div>
                                        </div>
                                        <div class="layui-inline">
                                            <label class="layui-form-label" style="width: 85px;">齐套类型</label>
                                            <div class="layui-input-block" style="margin-left: 120px; width: 185px;">
                                                <select name="HOrderType" id="HOrderType" lay-verify="HOrderType">
                                                    <option value="全部">全部</option>
                                                    <option value="生产用料清单">生产用料清单</option>
                                                    <option value="生产用料清单" selected="selected">生产用料清单</option>
                                                    <option value="标准Bom">标准Bom</option>
                                                </select>
                                            </div>
@@ -119,7 +123,7 @@
                                        <div class="layui-inline">
                                            <label class="layui-form-label" style="width: 85px;">规格型号</label>
                                            <div class="layui-input-block" style="margin-left: 120px;">
                                                <input type="text" class="layui-input" name="HMaterModel" id="HMaterModel" style="background-color:#efefef4d" readonly>
                                                <input type="text" class="layui-input" name="HMaterModel" id="HMaterModel">
                                            </div>
                                        </div>
                                        <div class="layui-inline">
@@ -129,16 +133,64 @@
                                            </div>
                                        </div>
                                    </div>
                                    <div class="layui-row" style="margin-top:10px;">
                                        <div class="layui-inline">
                                            <label class="layui-form-label" style="width: 85px;">生产订单组织</label>
                                            <div class="layui-input-block" style="margin-left: 120px; width: 185px;">
                                                <select name="HProdORGID" id="HProdORGID" lay-verify="HProdORGID">
                                                    <!--动态渲染组织-->
                                                </select>
                                            </div>
                                        </div>
                                        <div class="layui-inline">
                                            <label class="layui-form-label" style="width: 85px;">排产日期</label>
                                            <div class="layui-input-block" style="margin-left: 120px;">
                                                <input type="date" class="layui-input" lay-verify="HMastersDate" name="HMastersDate" id="HMastersDate" style="padding-left: 75px;">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="layui-row" style="margin-top: 10px; margin-bottom: 10px;">
                                        <div class="layui-inline">
                                            <label class="layui-form-label">过滤</label>
                                            <div class="layui-input-block">
                                                <select name="ColName" id="ColName" lay-filter="ColName" style="width:190px;">
                                                </select>
                                            </div>
                                        </div>
                                        <div class="layui-inline">
                                            <select name="Comparator" id="Comparator" lay-filter="Comparator" style="width:190px;">
                                                <option value="0" selected="selected"></option>
                                                <option value="=">=</option>
                                                <option value=">=">>=</option>
                                                <option value=">">></option>
                                                <option value="<="><=</option>
                                                <option value="<"><</option>
                                                <option value="<>"><></option>
                                                <option value="7">包含</option>
                                                <option value="8">左包含</option>
                                                <option value="9">右包含</option>
                                                <option value="10">不包含</option>
                                            </select>
                                        </div>
                                        <div class="layui-inline">
                                            <input type="text" class="layui-input" value="" name="ColContent" id="ColContent">
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div id="HProgressBar"></div>
                        <table class="" id="mainTable" lay-filter="mainTable"></table>
                        <script type="text/html" id="toolbarDemo">
                            <div class="layui-btn-container">
                                <button type="button" class="layui-btn layui-btn-sm" lay-event="set_BatchFill"><i class="layui-icon layui-icon-file-b"></i>批量填充</button>
                                <!--<button type="button" class="layui-btn layui-btn-sm" lay-event="set_ShowBill"><i class="layui-icon layui-icon-form"></i>编辑</button>-->
                                <!--<button type="button" class="layui-btn layui-btn-sm" lay-event="set_BatchFill"><i class="layui-icon layui-icon-file-b"></i>批量填充</button>
            <button type="button" class="layui-btn layui-btn-sm" lay-event="set_ShowBill"><i class="layui-icon layui-icon-form"></i>编辑</button>-->
                                <button type="button" class="layui-btn layui-btn-sm" lay-event="btn-CopyLine"><i class="layui-icon layui-icon-form"></i>复制行</button>
                                <button type="button" class="layui-btn layui-btn-sm" lay-event="set_DeleteBill"><i class="layui-icon layui-icon-delete"></i>删除行</button>
                                <button type="button" class="layui-btn layui-btn-sm" lay-event="set_MoverUp"><i class="layui-icon layui-icon-delete"></i>上移</button>
                                <button type="button" class="layui-btn layui-btn-sm" lay-event="set_MoverDown"><i class="layui-icon layui-icon-delete"></i>下移</button>
                                <button type="button" class="layui-btn layui-btn-sm" lay-event="set_Priority"><i class="layui-icon layui-icon-delete"></i>优先级</button>
                                <button type="button" class="layui-btn layui-btn-sm" lay-event="set_ReadyAsc"><i class="layui-icon layui-icon-delete"></i>准备排序</button>
                                <button type="button" class="layui-btn layui-btn-sm" lay-event="set_HideColumn"><i class="layui-icon layui-icon-form"></i>列设置</button>
                            </div>
                        </script>
@@ -154,9 +206,7 @@
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script>
    var treeCkData = { id: 0 };
    var TagId = "";
    var TagParentId = "";
    var OptionData = [];
    layui.config({
        base: '../../../layuiadmin/' //静态资源所在路径
    }).extend({
@@ -176,6 +226,7 @@
        var sWhere = "";
        var option = [];
        var HModName = "JIT_DayPlanPlatForm";
        //#endregion
        //#region è¿›å…¥é¡µé¢å³åŠ è½½
@@ -195,13 +246,14 @@
            var dd = myDate.getDate();
            var SumMonth = 31; //动态两月之差 new Date(yyyy, MM, 0).getDate()
            var dateHQty = 0;
            var SumHQty = 0;//拆单数量
            for (var i = 0; i <= (SumMonth - dd); i++) {
                if (obj.field == "生产资源") {
                    return;
                }
                if (!isNaN(parseInt(obj.data[Format(yyyy + '/' + MM + '/' + (dd + i), 'yyyy-MM-dd')]))) {
                    dateHQty += parseInt(obj.data[Format(yyyy + '/' + MM + '/' + (dd + i), 'yyyy-MM-dd')]);
                    dateHQty += parseInt(obj.data[Format(yyyy + '/' + MM + '/' + (dd + i), 'yyyy-MM-dd')])  ;
                }
            }
            for (var i = 1; i < dd; i++) {
@@ -209,15 +261,66 @@
                    dateHQty += parseInt(obj.data[Format(yyyy + '/' + (MM + 1) + '/' + i, 'yyyy-MM-dd')]);
                }
            }
            //查询所有数据相同的订单
            for (var i = 0; i < option.data.length; i++) {
                if (obj.data["生产订单号"] == option.data[i]["生产订单号"] && obj.data["生产订单明细行号"] == option.data[i]["生产订单明细行号"]) {
                    SumHQty += parseInt(option.data[i]["拆单数量"]);
                }
            }
            if (obj.value == "0" && obj.field == "拆单数量") {
                return layer.msg("拆单数量不能为0!");
            }
            if (SumHQty > (parseInt(obj.data["计划数量"]))) {
                obj.update({
                    "拆单数量": "0"
                });
                return layer.msg("拆单数量大于订单数量!");
            }
            var NowDate = obj.field;
            if (dateHQty > (parseInt(obj.data["计划数量"]))) {
                obj.update({
                    "日计划数量总量": dateHQty - obj.value,
                    [NowDate]: 0
                });
                return layer.msg("排产数量大于订单数量!")
            }
            //修改数据
            obj.update({
                "日计划数量总量": dateHQty
                "日计划数量总量": dateHQty,
            });
        })
        //双击表格事件
        table.on('rowDouble(mainTable)', function (obj) {
            btnrowDouble(obj.data);
        })
        //点击行选中数据
        table.on('row(mainTable)', function (obj) {
            //选中行改变颜色
            var flag = !obj.tr.find(':checkbox:first').prop('checked');
            obj.tr.find(':checkbox').prop('checked', flag);
            if (flag) {
                obj.tr.find('.layui-form-checkbox').addClass('layui-form-checked');  //设置复选框选中样式
                //$(obj.tr.selector).attr({ "style": "background:#ceedfa;color:black" });//改变当前tr背景颜色和字体颜色
            } else {
                obj.tr.find('.layui-form-checkbox').removeClass('layui-form-checked');//取消复选框选中样式
                //$(obj.tr.selector).attr({ "style": "background:" });//取消当前tr颜色
            }
            //mainTable ä¸ºè¡¨æ ¼ID   æ³¨æ„æ­¤å¤„如果ID不正确将导致你在监听复选框时获取不到你选择的数据,前面的只是添加或删除选中未选中样式以及设置背景色,字体颜色
            layui.each(table.cache.mainTable, function (i, l) {
                if (obj.tr.index() == l.LAY_TABLE_INDEX) {
                    l.LAY_CHECKED = flag;
                }
            });
        })
        //头工具栏事件
@@ -237,6 +340,40 @@
                        data[0]["HSourceID"] = "";
                        data[0]["hmainid"] = "";
                        data[0]["单据号"] = "";
                        data[0]["拆单数量"] = 0;
                        var myDate = new Date();
                        //获取年
                        var yyyy = myDate.getFullYear();
                        //获取月份
                        var MM = myDate.getMonth() + 1;
                        //获取开始月份的最大天数
                        var SumMonth = new Date(yyyy, MM, 0).getDate(); //动态两月之差
                        //获取开始日期的天数
                        var HBEGINDATE = myDate.getDate(); //获取当天日期天数
                        var columns=[]
                        var k = 0;//收集循环次数
                        for (var j = 0; j <= (30 - k); j++) {
                            data[0][Format(yyyy + '/' + MM + '/' + (HBEGINDATE + j), 'yyyy-MM-dd')] = "";
                            //跨年的话 ä¼šä»Žä¸€æœˆä¸€å·å¼€å§‹
                            if (MM == 12 && (HBEGINDATE + j) == 31) {
                                yyyy += 1;
                                MM = 1;
                                SumMonth = new Date(yyyy, MM, 0).getDate();
                                HBEGINDATE = 0;
                                k += j;
                                j = 0;
                            } else if ((HBEGINDATE + j) == SumMonth) { //跨月 æœˆæ•°åР䏀  å¤©æ•°ä»Žä¸€å¼€å§‹
                                HBEGINDATE = 0;
                                MM += 1;
                                SumMonth = new Date(yyyy, MM, 0).getDate();
                                k += j;
                                j = 0;
                            }
                        }
                        var copydata = JSON.stringify(data);
                        var copydata2 = copydata.substring(1, copydata.length);//去除首行字符'['
                        var copyrow = copydata2.substring(0, copydata2.length - 1);//去除末尾字符']'
@@ -253,6 +390,23 @@
                case 'set_DeleteBill':
                    set_DeleteBill();
                    break;
                //上移
                case 'set_MoverUp':
                    set_MoverUp(data);
                    break;
                //下移
                case 'set_MoverDown':
                    set_MoverDown(data);
                    break;
                //优先级
                case 'set_Priority':
                    set_Priority();
                    break;
                //准备排序
                case 'set_ReadyAsc':
                    set_ReadyAsc();
                    break;
            }
        });
@@ -269,7 +423,7 @@
            } else if (table.cache["mainTable"].length == 0) {
                return layer.msg("无数据,无法保存!");
            } else {
                set_AddNew(data);
                set_AddNew();
            }
        });
@@ -308,10 +462,57 @@
            get_btnICMOBill();
        })
        //准备
        form.on('submit(btnReady)', function (data) {
            get_btnReady();
        })
        //排产
        form.on('submit(btnProPC)', 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_btnProPC(HWorkShopID);
                    layer.close(index);
                }, 1000)
            }
        })
        //行内事件
        table.on('tool(mainTable)', function (obj) {
            set_GridDelete(obj);   //行内删除
            set_GridCellCheck(obj); //行内快捷键筛选
            //#region ä¿®æ”¹æ—¶é—´
            var data = obj.data;
            //日计划生产日期
            if (obj.event == 'HPlanEndDate') {
                var field = $(this).data('field');
                laydate.render({
                    elem: this.firstChild
                    , show: true //直接显示
                    , closeStop: this
                    , done: function (nowDate) {
                        //时间选择完成,行数据更新
                        data[field] = nowDate;
                        obj.update(data);
                    }
                });
            }
            //#endregion
        });
        //锁定
@@ -344,6 +545,8 @@
            //初始化时间
            $("#HPlanBeginDate").val(Format(new Date(new Date() - 1000 * 60 * 60 * 24 * 30), "yyyy-MM-dd"));
            $("#HPlanEndDate").val(Format(new Date(), "yyyy-MM-dd"));
            $("#HMastersDate").val("");
            get_ReadConfigFile();
            //组织
            Organ();
            //初始化表格
@@ -383,26 +586,27 @@
            var oneday = 1000 * 60 * 60 * 24;
            columns.push({ type: 'checkbox', fixed: 'left' });
            columns.push({ type: 'numbers', title: '序号'});
            columns.push({ field: '单据号', title: '单据号', hide: true });
            columns.push({ field: '销售订单号', title: '销售订单号', width: 150});
            columns.push({ field: '生产订单号', title: '生产订单号', width: 150, style: 'background-color: #f9f9f9;' });
            columns.push({ field: '生产订单明细行号', title: '生产订单明细行号', width: 150 });
            columns.push({ field: '优先级', title: '优先级', width: 150, edit: 'text' });
            columns.push({ field: 'HProdORGID', title: 'HProdORGID', hide: true });
            columns.push({ field: '生产组织', title: '生产组织', width:150 });
            columns.push({ field: 'HMaterID', title: 'HMaterID', hide: true });
            columns.push({ field: '物料代码', title: '物料编码', width:150 });
            columns.push({ field: '物料名称', title: '物料名称', width:150 });
            columns.push({ field: '规格型号', title: '规格型号', width:150 });
            columns.push({ field: 'HUnitID', title: 'HUnitID', hide: true });
            columns.push({ field: '销售订单数量', title: '销售订单数量', width:150 });//0
            columns.push({ field: '计划数量', title: '生产订单数量', width: 150 });//0
            columns.push({field: '日计划数量总量', title: '日计划数量总量', width: 150});//0
            columns.push({ field: '今日之前日计划数量', title: '今日之前日计划数量', width: 150 });//0
            columns.push({ field: '计划开始日期', title: '预计开工日期', width: 150, templet: "<div>{{d.计划开始日期 ==null ?'':layui.util.toDateString(d.计划开始日期, 'yyyy-MM-dd')}}</div>"});
            columns.push({ field: 'HWorkShopID', title: 'HWorkShopID', hide: true });
            columns.push({ field: '计划结束日期', title: '计划结束日期', width: 150, event: "HPlanEndDate" });
            columns.push({ field: '订单可排数量', title: '订单可排数量', width: 150});
            columns.push({ field: '拆单数量', title: '拆单数量', width: 150, edit: 'text' });
            columns.push({ field: '昨日数量', title: '昨日数量'});
            columns.push({ field: '生产车间', title: '生产车间', width: 150});
            columns.push({ field: 'HSourceID', title: 'HSourceID', hide:true });
            columns.push({ field: '生产资源', title: '生产资源', width: 150, edit: 'text', event: "HSourceID" });
            columns.push({
@@ -537,15 +741,29 @@
            columns.push({ field: '产线入库数量', title: '产线入库数量', width: 150 });
            columns.push({ field: '未排数量', title: '可排数量', width: 150 });
            columns.push({ field: '订单等级', title: '订单等级', width: 150 });
            columns.push({ field: '交货日期', title: '交货日期', width: 150, templet: "<div>{{d.交货日期 =='' ?'':layui.util.toDateString(d.交货日期, 'yyyy-MM-dd HH:mm:ss')}}</div>"});
            columns.push({ field: '订单交货期', title: '订单交货期', width: 150, templet: "<div>{{d.订单交货期 =='1900-01-01' ?'':layui.util.toDateString(d.订单交货期, 'yyyy-MM-dd')}}</div>" });
            columns.push({ field: '订单需求数量', title: '订单需求数量', width: 150 });
            columns.push({ field: '开工余量', title: '开工余量', width: 150 });
            columns.push({ field: '小时产能', title: '小时产能', width: 150 });
            columns.push({ field: '生产周期', title: '生产周期', width: 150 });
            columns.push({ field: '最迟开工日期', title: '最迟开工日期', width: 150, templet: "<div>{{d.最迟开工日期 =='' ?'':layui.util.toDateString(d.最迟开工日期, 'yyyy-MM-dd')}}</div>" });
            columns.push({ field: '最迟完工日期', title: '最迟完工日期', width: 150, templet: "<div>{{d.最迟完工日期 =='' ?'':layui.util.toDateString(d.最迟完工日期, 'yyyy-MM-dd')}}</div>"});
            columns.push({ field: '源单主内码', title: '源单主内码', width: 150 });
            columns.push({ field: '源单子内码', title: '源单子内码', width: 150 });
            columns.push({ field: 'hmainid', title: '日计划工单主码', width: 150 });
            columns.push({ field: '电压/功率/底板', title: '电压/功率/底板', width: 150 });
            columns.push({ field: '计量单位', title: '计量单位', width: 150 });
            columns.push({ field: '拆单数量', title: '拆单数量', width: 150 });//0
            columns.push({ field: '订单可排数量', title: '订单可排数量', width: 150 });
            columns.push({ field: '未入库数量', title: '未入库数量', width: 150 });//0
            columns.push({ field: 'HICMOInterID', title: 'HICMOInterID', width: 150, hide:true });
            columns.push({ field: 'HGroupID', title: 'HGroupID', width: 150, hide:true });
            columns.push({ field: 'HGroupName', title: 'HGroupName', width: 150, hide:true });
            columns.push({ field: '生产资源代码', title: '生产资源代码', width: 150, hide: true });
            columns.push({ field: 'HSourceID', title: 'HSourceID', hide: true });
            columns.push({ field: 'HMaterID', title: 'HMaterID', hide: true });
            columns.push({ field: 'HWorkShopID', title: 'HWorkShopID', hide: true });
            columns.push({ field: 'HUnitID', title: 'HUnitID', hide: true });
            columns.push({ field: 'HProdORGID', title: 'HProdORGID', hide: true });
            columns.push({ fixed: 'right', title: '操作', toolbar: '#barDemo' });
            option = {
@@ -556,8 +774,29 @@
                , cellMinWidth: 90
                , cols: [columns]
                , limit: Number.MAX_VALUE//默认显示全部
                //, done: function (res, page, count) {
                //    var that = this.elem.next();
                //    res.data.forEach(function (item, index) {
                //        var NumCount = item.FBASEQTY;//获取总库存数量
                //        for (var i = 0; i < Days; i++) {
                //            var dateNowTime = Format(new Date($("#HBEGINDATE").val()).setDate(new Date($("#HBEGINDATE").val()).getDate() + i), 'yyyy-MM-dd');
                //            if (item[dateNowTime] != null) {
                //                if (NumCount > parseFloat(item[dateNowTime])) {
                //                    NumCount -= parseFloat(item[dateNowTime]);
                //                } else {
                //                    var num = 6;//即时库存与日期挨着  ä»Žå³æ—¶åº“存开始算
                //                    tr = that.find(".layui-table-box tbody tr[data-index='" + index + "']");
                //                    rq = tr.children()[num + 1 + i];
                //                    rq.style.color = '#f66161';//然后变色
                //                    rq = tr.children()[num];
                //                    rq.style.color = '#f66161';//然后变色
                //                }
                //            }
                //        }
                //    });
                //    $('.layui-table-cell').css({ 'height': 'auto' });
                //}
            };
        }
        //查询加载数据
@@ -566,6 +805,7 @@
            $.ajax({
                url: GetWEBURL() + '/JIT_DayPlanPlatFormBill/JIT_DayPlanPlatFormBillList',
                type: "GET",
                async: false,
                data: { "sWhere": sWhere, "user": sessionStorage["HUserName"] },
                success: function (data1) {
                    if (data1.count == 1) {
@@ -580,6 +820,11 @@
                            get_Display_1(HinterID_S);
                            get_Display_2(HinterID_S)
                        }
                        if ($("#Comparator").val() == 0 && $("#ColContent").val() == "") {
                            ColFilter();
                        }
                    } else {
                        layer.close(ajaxLoad);
                        layer.alert(data1.code + data1.Message, { icon: 5 });
@@ -597,9 +842,19 @@
            $.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) {
                        for (var i = 0; i < 31; i++) {
                            option.cols[0][22 + i]["edit"] = "text";
                            option.cols[0][22 + i]["style"] = "";
                            var TableDate = option.cols[0][22 + i].field;
                            var date = new Date(TableDate).getDay();
                            if (date == 6 || date == 0) {
                                option.cols[0][22 + i]["style"] = "   background-color: #c3fec8";
                            }
                        }
                        if (data1.data[0]["DayNum"] > 0) {
                            //获取被锁定的列数
                            var tableNum = 0;
@@ -625,12 +880,13 @@
                                option.cols[0][22 + i]["style"] = "   background-color: #e6e6e6";
                            }
                        } else {
                            for (var i = 0; i < 31; i++) {
                                option.cols[0][22 + i]["edit"] = "text";
                                option.cols[0][22 + i]["style"] = "";
                            }
                        }
                        //else {
                        //    for (var i = 0; i < 31; i++) {
                        //        option.cols[0][22 + i]["edit"] = "text";
                        //        option.cols[0][22 + i]["style"] = "";
                        //    }
                        //}
                        table.render(option);
                        layer.close(ajaxLoad);
                        //layer.alert("查询成功", { icon: 1 });
@@ -651,6 +907,7 @@
            $.ajax({
                url: GetWEBURL() + '/JIT_DayPlanPlatFormBill/JIT_DayPlanPlatFormBillHinterIDList',
                type: "GET",
                async: false,
                data: { "sWhere": HinterID_S.toString(), "num": 2 },
                success: function (data1) {
                    if (data1.count == 1) {
@@ -772,7 +1029,7 @@
                , area: ['90%', '90%']//大小
                , title: '生产车间列表'//标题
                , shift: 2//弹出动画
                , content: ['../../Baseset/基础资料/Gy_DepartmentList.html', 'yes']
                , content: ['../../基础资料/公用基础资料/Gy_DepartmentList.html', 'yes']
                , btn: ['确定', '取消']
                , btn1: function (index, layero) {//按钮【按钮一】的回调
                    var iframeWindow = window['layui-layer-iframe' + index]  //获取弹框页面
@@ -782,19 +1039,44 @@
                    }
                    //获取数据
                    $("#HWorkShopID").val(checkStatus.data[0].HItemID);//车间id
                    $("#HWorkShopIDName").val(checkStatus.data[0].HName);//车间名称
                    $("#HWorkShopIDName").val(checkStatus.data[0].部门名称);//车间名称
                    get_WriteConfigFile();
                    layer.close(index); //它获取的始终是最新弹出的某个层,值是由layer内部动态递增计算的
                }
                , btn2: function (index, layero) { }
            })
        }
        //读取配置文件
        function get_ReadConfigFile() {
            //获取本地存储的数据
            var data = localStorage.getItem("JIT_DayPlanPlatForm_HWorkShop");
            if (data != null) {
                var data2 = JSON.parse(data);
                $("#HWorkShopID").val(data2["HWorkShopID"]);
                $("#HWorkShopIDName").val(data2["HWorkShopIDName"]);
                form.render('select');
            }
        }
        //存储配置文件
        function get_WriteConfigFile() {
            //清空本地存储的数据
            localStorage.removeItem("JIT_DayPlanPlatForm_HWorkShop");
            var data = {
                HWorkShopID:  $("#HWorkShopID").val()
                , HWorkShopIDName: $("#HWorkShopIDName").val()
            }
            //本地存储
            localStorage.setItem("JIT_DayPlanPlatForm_HWorkShop", JSON.stringify(data));
        }
        //快速过滤
        function get_FastQuery(number) {
            var HWorkShopID = 0;
            var HProdORGID = 0;
            HWorkShopID = $("#HWorkShopID").val();//生产车间
            if (number == 2) {
                HWorkShopID = $("#HWorkShopID").val();//生产车间
                if (HWorkShopID == 0) {
                    return layer.msg("生产车间不能为空!");
                }
@@ -806,9 +1088,36 @@
            }
            var HPlanBeginDate = $("#HPlanBeginDate").val();//开工起始日期
            var HPlanEndDate = $("#HPlanEndDate").val();//开工截止日期
            var HMastersDate = $("#HMastersDate").val();//排产日期
            var HSeOrderBillNo = $("#HSeOrderBillNo").val();//销售订单号
            var HMaterID = $("#HMaterID").val();//物料编码id
            var HICMOBillNo = $("#HICMOBillNo").val();//生产订单号
            var ColName = $("#ColName").val();//复选框
            var Comparator = $("#Comparator").val()
            var ColContent = $("#ColContent").val();
            var sWheres = "";
            if (ColName != 0 && Comparator != 0) {
                var com = "";
                switch (Comparator) {
                    case "7":
                        com = "like''%" + ColContent + "%''";
                        break;
                    case "8":
                        com = "like''%" + ColContent + "''";
                        break;
                    case "9":
                        com = "like''" + ColContent + "%''";
                        break;
                    case "10":
                        com = "not like''%" + ColContent + "%''";
                        break;
                    default:
                        com = "" + Comparator + "''" + ColContent + "''";
                        break;
                }
                sWheres += " and [" + ColName + "] " + com;
            }
            sWhere = {
                HPlanBeginDate: HPlanBeginDate
@@ -818,6 +1127,8 @@
                , HMaterID: HMaterID
                , HICMOBillNo: HICMOBillNo
                , HWorkShopID: HWorkShopID
                , HMastersDate: HMastersDate
                , sWheres: sWheres
            }
            get_Display(JSON.stringify(sWhere));
            sWhere = ""//调用接口后清空sWhere缓存
@@ -837,6 +1148,7 @@
            layer.open({
                type: 2 //类型
                , skin: 'layui-layer-rim'//加上边框
                , maxmin: true //设置最大最小按钮是否显示
                , area: ['90%', '90%']//大小
                , title: '齐套分析明细表'//标题
                , shift: 2//弹出动画
@@ -849,6 +1161,7 @@
            $("#HPlanBeginDate").val(Format(new Date(new Date() - 1000 * 60 * 60 * 24 * 30), "yyyy-MM-dd"));//开工起始日期
            $("#HSeOrderBillNo").val("");//销售订单号
            $("#HPlanEndDate").val(Format(new Date(), "yyyy-MM-dd"));//开工截止日期
            $("#HMastersDate").val("");//排产日期
            $("#HMaterID").val("0");//物料编码id
            $("#HMaterNumber").val("");//物料编码
            $("#HMaterName").val("");//物料名称
@@ -857,6 +1170,9 @@
            $("#HWorkShopID").val("0");//生产车间id
            $("#HWorkShopIDName").val("");//生产车间
            $("#HProdORGID").val(sessionStorage["OrganizationID"])//生产订单组织
            $("#ColContent").val("");
            $("#ColName").val("0");
            $("#Comparator").val("0");
            form.render('select');
            sWhere = "";
        }
@@ -901,12 +1217,13 @@
                HProdORGID: $("#HProdORGID").val()
                , HWorkShopID: $("#HWorkShopID").val()
            }
            var HTLType = $("#HTLType").val();
            sWhere = JSON.stringify(sWhere);
            var ajaxLoad = layer.load();
            $.ajax({
                url: GetWEBURL() + '/JIT_DayPlanPlatFormBill/JIT_TLYS',
                type: "GET",
                data: { "sWhere": sWhere, "user": sessionStorage["Czybm"] },
                data: { "sWhere": sWhere, "user": sessionStorage["Czybm"], "HTLType": HTLType },
                success: function (data1) {
                    if (data1.count == 1) {
                        get_FastQuery(2);
@@ -925,13 +1242,14 @@
        //生产订单选单
        function get_btnICMOBill() {
            var HDeptID = $("#HWorkShopID").val() == "" ? 0 : $("#HWorkShopID").val();
            layer.open({
                type: 2 //类型
                , skin: 'layui-layer-rim'//加上边框
                , area: ['90%', '90%']//大小
                , title: '生产订单列表'//标题
                , shift: 2//弹出动画
                , content: ['../../生产管理/生产任务单/Sc_ICMOBillList.html', 'yes']
                , content: ['../../生产管理/生产任务单/Sc_ICMOBillList.html?HDeptID=' + HDeptID, 'yes']
                , btn: ['确定', '取消']
                , btn1: function (index, layero) {//按钮【按钮一】的回调
                    var iframeWindow = window['layui-layer-iframe' + index]  //获取弹框页面
@@ -955,6 +1273,647 @@
                }
                , btn2: function (index, layero) { }
            })
        }
        //准备
        function get_btnReady() {
            var data = table.cache["mainTable"];
            var HICOMNum = [];
            for (var i = 0; i < data.length; i++) {
                if (isNaN(data[i]["HICMOInterID"])) {
                    return layer.msg("请先进行保存!!")
                }
                if (isNaN(data[i]["HSourceID"])) {
                    return layer.msg("选择生产资源!!")
                }
                HICOMNum.push(data[i]["HICMOInterID"] + ";" + data[i]["HICMOEntryID"] + ";" + data[i]["HSourceID"]);
            }
            $('#HProgressBar').html(`
    <div class="layui-progress" lay-filter="demo-filter-progress">
      <div class="layui-progress-bar" lay-percent="40%"></div>
    </div>
  `);
            // æ¸²æŸ“进度条组件
            element.render('progress', 'demo-filter-progress');
            $.ajax({
                url: GetWEBURL() + '/JIT_DayPlanPlatFormBill/ReadyData',
                type: "GET",
                data: { "SWhere": HICOMNum.toString() },
                success: function (data1) {
                    if (data1.count == 1) {
                        for (var i = 0; i < data1.data.length; i++) {
                            for (var j = 0; j < option.data.length; j++) {
                                if (data1.data[i]["HICMOInterID"] == option.data[j]["HICMOInterID"] && data1.data[i]["HICMOEntryID"] == option.data[j]["HICMOEntryID"]) {
                                    option.data[j]["小时产能"] = data1.data[i]["小时产能"];
                                    option.data[j]["生产周期"] = data1.data[i]["生产周期"];
                                    option.data[j]["开工余量"] = data1.data[i]["开工余量"];
                                    option.data[j]["最迟开工日期"] = data1.data[i]["最迟开工日期"];
                                    option.data[j]["最迟完工日期"] = data1.data[i]["最迟完工日期"];
                                    option.data[j]["订单需求数量"] = data1.data[i]["订单需求数量"];
                                    option.data[j]["订单交货期"] = data1.data[i]["订单交货期"] < "2020-01-01 0:00:00" ? "1900-01-01" : data1.data[i]["订单交货期"];
                                    break;
                                }
                            }
                        }
                        for (var i = 0; i < option.data.length - 1; i++) {
                            for (var j = 0; j < option.data.length - i - 1; j++) {
                                var tables = [];
                                //设置任务单优先排序,并设置优先(最迟完工日期+订单交货期)  å°è£…
                                if (option.data[j]["最迟完工日期"] > option.data[j + 1]["最迟完工日期"]) {
                                    tables.push(option.data[j + 1]);
                                    option.data[j + 1] = option.data[j];
                                    option.data[j] = tables[0];
                                } else if (option.data[j]["最迟完工日期"] == option.data[j + 1]["最迟完工日期"]) {
                                    if (option.data[j]["订单交货期"] > option.data[j + 1]["订单交货期"]) {
                                        tables.push(option.data[j + 1]);
                                        option.data[j + 1] = option.data[j];
                                        option.data[j] = tables[0];
                                    } else if (option.data[j]["订单交货期"] == option.data[j + 1]["订单交货期"]) {
                                        if (option.data[j]["订单需求数"] < option.data[j + 1]["订单需求数"]) {
                                            tables.push(option.data[j + 1]);
                                            option.data[j + 1] = option.data[j];
                                            option.data[j] = tables[0];
                                        }
                                    }
                                }
                            }
                        }
                        $('#HProgressBar').html('')
                        table.render(option);
                    } else {
                        //layer.close(ajaxLoad);
                        layer.alert(data1.code + data1.Message, { icon: 5 });
                    }
                }, error: function () {
                    layer.close(ajaxLoad);
                    layer.alert("接口请求失败!", { icon: 5 });
                }
            });
        }
        //排产
        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 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 + ")";
            $.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]["优先级"];
                if (SDSum > 0) {
                    sPlanQty = sPlanQty - SDSum;
                }
                //剩余需求工时
                iLeftQty = sPlanQty;
                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);
        }
        var TableData = [];
        function get_HFData(num,nums) {
            if (num == 0) {
                TableData = option.data;
            } else {
                option.data[nums] = TableData[nums];
            }
        }
        //将数据排程到网格
        function SetInfoToGrid(grd, ds, dsPre, iRow, sLeftQty, sWorkQty, bAddFlag, HPlanDay) {
            var b = false;
            var oSub;
            //循环网格列
            if (bAddFlag) {
                for (var i = 0; i < ds.length; i++) {
                    //找到对应的列
                    for (var j = 22; j < grd.cols[0].length; j++) {
                        if (sLeftQty > 0) {
                            if (ds[i]["日期"] == grd.cols[0][j].field) //表格的标题上 ä¿å­˜äº†æ—¥æœŸï¼›
                            {
                                //如果时间被 ä¸Šé“余量占用 åˆ™ è·³è¿‡
                                b = false;
                                //if (dsPre != null && dsPre.Tables[0].Rows.Count > 0) {
                                //    for (var m = 0; m < dsPre.Tables[0].Rows.Count; m++)
                                //    {
                                //        if (ds[i]["日期"] < DBUtility.ClsPub.isDate(dsPre.Tables[0].Rows[m]["日期"])) {
                                //            b = true;
                                //        }
                                //    }
                                //}
                                if (b == false) {
                                    if (dsPre != null && ds[i]["日期"] == dsPre[0]["日期"]) {
                                        ////HUseTimes ä¸º ä¸Šé“余量后 å‰©ä½™å·¥æ—¶ã€‚
                                        //if (ds[i]["最大剩余工时"] > dsPre[0]["HUseTimes"]) {
                                        //    if (parseFloat(sLeftQty) > parseFloat(sWorkQty * dsPre[0]["HUseTimes"])) {
                                        //        grd.data[iRow][j] = parseFloat(sWorkQty * (dsPre[0]["HUseTimes"]));
                                        //        sLeftQty = sLeftQty - parseFloat(sWorkQty * (dsPre[0]["HUseTimes"]));
                                        //        oSub = new ClsGridValues();
                                        //        oSub.iRow = iRow;
                                        //        oSub.iCol = j;
                                        //        oSub.HLeftTimes = DBUtility.ClsPub.isSingle(dsPre[0]["HUseTimes"]);
                                        //        oClsGridValues.Add(oSub);
                                        //    }
                                        //    else {
                                        //        grd.data[iRow][j]= sLeftQty;
                                        //        sLeftQty = 0;
                                        //        oSub = new ClsGridValues();
                                        //        oSub.iRow = iRow;
                                        //        oSub.iCol = j;
                                        //        oSub.HLeftTimes = DBUtility.ClsPub.isSingle(dsPre.Tables[0].Rows[0]["HUseTimes"]);
                                        //        oClsGridValues.Add(oSub);
                                        //    }
                                        //}
                                        //else //卓力不需要考虑加班,下面的这一段不需要
                                        //{
                                        //    if (sLeftQty > sWorkQty * ds[i]["最大剩余工时"]) {
                                        //        grd.data[iRow][j]= parseFloat(sWorkQty * ds[i]["最大剩余工时"]);
                                        //        sLeftQty = sLeftQty - (parseFloat(sWorkQty * ds[i]["最大剩余工时"]));
                                        //        sLeftQty = 0;
                                        //        oSub = new ClsGridValues();
                                        //        oSub.iRow = iRow;
                                        //        oSub.iCol = j;
                                        //        oSub.HLeftTimes = ds[i]["最大剩余工时"];
                                        //        oClsGridValues.Add(oSub);
                                        //    }
                                        //    else {
                                        //        grd.data[iRow][j]= sLeftQty;
                                        //        sLeftQty = 0;
                                        //        oSub = new ClsGridValues();
                                        //        oSub.iRow = iRow;
                                        //        oSub.iCol = j;
                                        //        oSub.HLeftTimes = ds[i]["最大剩余工时"];
                                        //        oClsGridValues.Add(oSub);
                                        //    }
                                        //}
                                    }
                                    else {
                                        if (sLeftQty > parseFloat(sWorkQty * ds[i]["最大剩余工时"])) {
                                            grd.data[iRow][grd.cols[0][j + HPlanDay].field] = parseFloat(sWorkQty * ds[i]["最大剩余工时"]);
                                            sLeftQty = sLeftQty - (parseFloat(sWorkQty * ds[i]["最大剩余工时"]));
                                            //oSub = new ClsGridValues();
                                            //oSub.iRow = iRow;
                                            //oSub.iCol = j;
                                            option.data[iRow]["HLeftTimes"] = ds[i]["最大剩余工时"];
                                            break;
                                            //oSub.HLeftTimes = ds[i]["最大剩余工时"];
                                            //oClsGridValues.Add(oSub);
                                        }
                                        else {
                                            grd.data[iRow][grd.cols[0][j + HPlanDay].field] = Math.round(sLeftQty * 10) / 10;
                                            sLeftQty = 0;
                                            //oSub = new ClsGridValues();
                                            //oSub.iRow = iRow;
                                            //oSub.iCol = j;
                                            option.data[iRow]["HLeftTimes"] = ds[i]["最大剩余工时"];
                                            break;
                                            //oSub.HLeftTimes = ds[i]["最大剩余工时"];
                                            //oClsGridValues.Add(oSub);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            else {
                for (var i = 0; i < ds.length; i++) {
                    //找到对应的列
                    for (var j = 22; j < 53; j++) {
                        if (sLeftQty > 0) {
                            if (ds[i]["日期"] == grd.cols[0][j].field) {
                                //如果时间被 ä¸Šé“余量占用 åˆ™ è·³è¿‡
                                b = false;
                                //if (dsPre != null && dsPre.Tables[0].Rows.Count > 0) {
                                //    for (var m = 0; m < dsPre.Tables[0].Rows.Count; m++)
                                //    {
                                //        if (DBUtility.ClsPub.isDate(ds[i]["日期"]) < DBUtility.ClsPub.isDate(dsPre.Tables[0].Rows[m]["日期"])) {
                                //            b = true;
                                //        }
                                //    }
                                //}
                                if (b == false) {
                                    if (dsPre != null && s[i]["日期"] == dsPre[0]["日期"]) {
                                        //if (ds[i]["剩余工时"] > (DBUtility.ClsPub.isSingle(dsPre.Tables[0].Rows[0]["HUseTimes"]))) {
                                        //    if (sLeftQty > parseFloat(sWorkQty * (DBUtility.ClsPub.isSingle(dsPre.Tables[0].Rows[0]["HUseTimes"])))) {
                                        //        grd.data[iRow][j]= parseFloat(sWorkQty * (DBUtility.ClsPub.isSingle(dsPre.Tables[0].Rows[0]["HUseTimes"])));
                                        //        sLeftQty = sLeftQty - parseFloat(sWorkQty * (DBUtility.ClsPub.isSingle(dsPre.Tables[0].Rows[0]["HUseTimes"])));
                                        //        oSub = new ClsGridValues();
                                        //        oSub.iRow = iRow;
                                        //        oSub.iCol = j;
                                        //        oSub.HLeftTimes = DBUtility.ClsPub.isSingle(dsPre.Tables[0].Rows[0]["HUseTimes"]);
                                        //        oClsGridValues.Add(oSub);
                                        //    }
                                        //    else {
                                        //        grd.data[iRow][j]= sLeftQty;
                                        //        sLeftQty = 0;
                                        //        oSub = new ClsGridValues();
                                        //        oSub.iRow = iRow;
                                        //        oSub.iCol = j;
                                        //        oSub.HLeftTimes = DBUtility.ClsPub.isSingle(dsPre.Tables[0].Rows[0]["HUseTimes"]);
                                        //        oClsGridValues.Add(oSub);
                                        //    }
                                        //}
                                        //else {
                                        //    if (sLeftQty > sWorkQty * ds[i]["剩余工时"]) {
                                        //        grd.data[iRow][j]= parseFloat(sWorkQty * ds[i]["剩余工时"]);
                                        //        sLeftQty = sLeftQty - (parseFloat(sWorkQty * ds[i]["剩余工时"]));
                                        //        sLeftQty = 0;
                                        //        oSub = new ClsGridValues();
                                        //        oSub.iRow = iRow;
                                        //        oSub.iCol = j;
                                        //        oSub.HLeftTimes = ds[i]["剩余工时"];
                                        //        oClsGridValues.Add(oSub);
                                        //    }
                                        //    else {
                                        //        grd.data[iRow][j]= sLeftQty;
                                        //        sLeftQty = 0;
                                        //        oSub = new ClsGridValues();
                                        //        oSub.iRow = iRow;
                                        //        oSub.iCol = j;
                                        //        oSub.HLeftTimes = ds[i]["剩余工时"];
                                        //        oClsGridValues.Add(oSub);
                                        //    }
                                        //}
                                    }
                                    else {
                                        if (sLeftQty > parseFloat(sWorkQty * ds[i]["剩余工时"])) {
                                            grd.data[iRow][grd.cols[0][j].field] = parseFloat(sWorkQty * ds[i]["剩余工时"]);
                                            sLeftQty = sLeftQty - (parseFloat(sWorkQty * ds[i]["剩余工时"]));
                                            //oSub = new ClsGridValues();
                                            //oSub.iRow = iRow;
                                            //oSub.iCol = j;
                                            //option.data[iRow]["HLeftTimes"] = ds[i]["最大剩余工时"];
                                            //option.data[iRow]["HUseTimes"] = ds[i]["剩余工时"];
                                            break;
                                            //oSub.HLeftTimes = ds[i]["剩余工时"];
                                            //oClsGridValues.Add(oSub);
                                        }
                                        else {
                                            grd.data[iRow][grd.cols[0][j].field] = sLeftQty;
                                            //option.data[iRow]["HUseTimes"] = parseFloat(sLeftQty / sWorkQty);
                                            sLeftQty = 0;
                                            //oSub = new ClsGridValues();
                                            //oSub.iRow = iRow;
                                            //oSub.iCol = j;
                                            //option.data[iRow]["HLeftTimes"] = ds[i]["最大剩余工时"];
                                            break;
                                            //oSub.HLeftTimes = ds[i]["剩余工时"];
                                            //oClsGridValues.Add(oSub);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        //查询生产订单
@@ -1023,7 +1982,11 @@
        //删除行
        function set_DeleteBill() {
            var CheckStatus = table.checkStatus("mainTable");
            var scrollTop = 0;
            var layuiTable = $('.layui-table-main');
            if (layuiTable != null && layuiTable.length > 0) {
                scrollTop = layuiTable[0].scrollTop;
            }
            if (CheckStatus.data.length == 0) {
                return layer.msg("请选择数据!")
            } else {
@@ -1047,9 +2010,15 @@
                                        //关闭当前frame
                                        layer.close(index);
                                        //修改为功后刷新界面
                                        window.location.reload();
                                        get_FastQuery(2);
                                        ////重载tree
                                        //tree.reload('treeDepartment', {});
                                        setTimeout(function () {
                                            if (layuiTable != null && layuiTable.length > 0) {
                                                $('.layui-table-main').scrollTop(scrollTop)
                                            }
                                        }, 100)
                                    });
                                } else {
                                    layer.alert(result.code + result.Message, { icon: 5 });
@@ -1061,13 +2030,134 @@
            }
        }
        //上移
        function set_MoverUp(data) {
            if (data.length != 1) {
                layer.msg("请选择一行数据!");
            } else if (option.data[0]["hmainid"] == data[0]["hmainid"]) {
                layer.msg("首行数据无法移动!");
            } else {
                var scrollTop = 0;
                var layuiTable = $('.layui-table-main');
                if (layuiTable != null && layuiTable.length > 0) {
                    scrollTop = layuiTable[0].scrollTop;
                }
                var tables = [];
                for (var i = 0; i < option.data.length; i++) {
                    if (option.data[i]["hmainid"] == data[0]["hmainid"]) {
                        tables.push(option.data[i - 1]);
                        data[0].LAY_CHECKED = true;
                        option.data[i - 1] = data[0];
                        option.data[i] = tables[0];
                        table.render(option);
                        break;
                    }
                }
                setTimeout(function () {
                    if (layuiTable != null && layuiTable.length > 0) {
                        $('.layui-table-main').scrollTop(scrollTop)
                    }
                }, 100)
            }
        }
        //下移
        function set_MoverDown(data) {
            if (data.length != 1) {
                layer.msg("请选择一行数据!");
            } else
            if (option.data[option.data.length - 1]["hmainid"] == data[0]["hmainid"]) {
                layer.msg("末行数据无法移动!");
            } else {
                var scrollTop = 0;
                var layuiTable = $('.layui-table-main');
                if (layuiTable != null && layuiTable.length > 0) {
                    scrollTop = layuiTable[0].scrollTop;
                }
                var tables = [];
                for (var i = 0; i < option.data.length; i++) {
                    if (option.data[i]["hmainid"] == data[0]["hmainid"]) {
                        var len = data.length;
                        tables.push(option.data[i + len]);
                        for (var j = 0; j < len; j++) {
                            data[j].LAY_CHECKED = true;
                            option.data[i + 1 + j] = data[j];
                        }
                        option.data[i] = tables[0];
                        table.render(option);
                        break;
                    }
                }
                setTimeout(function () {
                    if (layuiTable != null && layuiTable.length > 0) {
                        $('.layui-table-main').scrollTop(scrollTop)
                    }
                }, 100)
            }
        }
        //优先级
        function set_Priority() {
            var data = table.cache["mainTable"];
            for (var i = 0; i < data.length; i++) {
                data[i]["优先级"] = ((i + 1) * 5);
            }
            option.data = data;
            table.render(option);
        }
        //准备排序
        function set_ReadyAsc() {
            if (option.data.length != 0) {
                for (var i = 0; i < option.data.length - 1; i++) {
                    for (var j = 0; j < option.data.length - i - 1; j++) {
                        var tables = [];
                        //按照计划结束日期   ç”Ÿäº§è®¢å•号  ç”Ÿäº§è®¢å•明细行号的顺序去排
                        if (option.data[j]["计划结束日期"] > option.data[j + 1]["计划结束日期"]) {
                            tables.push(option.data[j + 1]);
                            option.data[j + 1] = option.data[j];
                            option.data[j] = tables[0];
                        } else if (option.data[j]["计划结束日期"] == option.data[j + 1]["计划结束日期"]) {
                            if (option.data[j]["生产订单号"] > option.data[j + 1]["生产订单号"]) {
                                tables.push(option.data[j + 1]);
                                option.data[j + 1] = option.data[j];
                                option.data[j] = tables[0];
                            } else if (option.data[j]["生产订单号"] == option.data[j + 1]["生产订单号"]) {
                                if (option.data[j]["生产订单明细行号"] > option.data[j + 1]["生产订单明细行号"]) {
                                    tables.push(option.data[j + 1]);
                                    option.data[j + 1] = option.data[j];
                                    option.data[j] = tables[0];
                                }
                            }
                        }
                    }
                }
                table.render(option);
            }
            else {
                return layer.msg("无数据!")
            }
        }
        //保存
        function set_AddNew(data) {
        function set_AddNew() {
            //删除子表数据 ä¼šå ç”¨æ•°ç»„的位置,需要重新排一下顺序
            var num = [];
            for (var i = 0; i < table.cache["mainTable"].length; i++) {
                if (table.cache["mainTable"][i] != "") {
                    if (parseFloat(table.cache["mainTable"][i]["拆单数量"]) == 0) {
                        return layer.msg("第" + (i + 1) + "行,拆产数量有误,请重新输入!");
                    }
                    if (parseFloat(table.cache["mainTable"][i]["拆单数量"]) < parseFloat(table.cache["mainTable"][i]["日计划数量总量"]) + parseFloat(table.cache["mainTable"][i]["今日之前日计划数量"])) {
                        return layer.msg("第" + (i + 1) + "行,排产数量超出订单数量!");
                    }
                    table.cache["mainTable"][i].LAY_TABLE_INDEX = i;
                    num.push(table.cache["mainTable"][i])
                }
@@ -1075,7 +2165,7 @@
            //var sMainStr = JSON.stringify(data.field);
            var sSubStr = JSON.stringify(num);
            var sMainSub = sSubStr +";" + sessionStorage["HUserName"];
            var sMainSub = sSubStr +"&和" + sessionStorage["HUserName"];
            var index = layer.load();
            $.ajax({
@@ -1094,6 +2184,36 @@
                        }
                        layer.close(index);
                        layer.msg("保存成功");
                    }
                    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_AddNew1(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) {
                        layer.msg("保存成功");
                        layer.close(index);
                    }
                    else {
                        layer.close(index);
@@ -1131,12 +2251,19 @@
                                if (checkStatus.data.length != 1) {
                                    return layer.msg("请选择一条数据");
                                }
                                OptionData = checkStatus.data[0];
                                //更新表格缓存的数据
                                obj.update({
                                    "HSourceID": checkStatus.data[0].HItemID
                                    , "生产资源": checkStatus.data[0].生产资源名称
                                })
                                layer.close(index);//关闭弹窗
                            }
                            , end: function () {
                                obj.update({
                                    "HSourceID": OptionData.HItemID
                                    , "生产资源": OptionData.生产资源名称
                                })
                            }
                        })
                    }
@@ -1266,9 +2393,9 @@
                            }
                            //设置内容字体大小
                            if (data1.data[0].HFontSize != 0) {
                                option.cols[0][i + 1]["style"] = "font-size:" + data1.data[0].HFontSize + "px;";
                                option.cols[0][i + 1]["style"] += ";font-size:" + data1.data[0].HFontSize + "px;";
                            } else {
                                option.cols[0][i + 1]["style"] = "font-size:100%";
                                option.cols[0][i + 1]["style"] += ";font-size:100%";
                            }
                            //设置列宽
                            //if (data1.data[0].HColumnWidth != 0) {
@@ -1322,7 +2449,24 @@
            })
        }
        //列明显示下拉框
        function ColFilter() {
            var Organization = '<option  value="0" selected="selected" ></option>';
            for (var i = 2; i < option.cols[0].length - 1; i++) {
                if (option.cols[0][i].hide != true) {
                    Organization += '<option  style="color:blue;" value="' + option.cols[0][i].field + '">' + option.cols[0][i].field + '</option>';
                }
            }
            $("#ColName").empty();
            $("#ColName").append(Organization);
            form.render('select');
        }
        //#endregion
        //以上是layui模块
    });
    //双击返回生产资源
    function GetGySource(data) {
        OptionData = data
    }
</script>