WebTM/views/Éú²ú¹ÜÀí/Éú²ú¼Æ»®Æ½Ì¨/JIT_DayPlanPlatFormImport.html
@@ -11,37 +11,6 @@
    <script src="../../../layuiadmin/Scripts/jquery-1.4.1.js"></script>
    <script src="../../../layuiadmin/Scripts/webConfig.js"></script>
    <script src="../../../layuiadmin/PubCustom.js"></script>
    <style>
        .main-btn { /*头部主按钮*/
            padding: 0 2px; /*调整按钮左右空隙大小*/
            height: 30px;
            line-height: 30px;
        }
        .btn-title {
            font-size: 16px;
        }
        /* é˜²æ­¢ä¸‹æ‹‰æ¡†çš„下拉列表被隐藏---必须设置--- */
        .layui-table-cell {
            overflow: visible !important;
        }
        /* ä½¿å¾—下拉框与单元格刚好合适 */
        td .layui-form-select {
            margin-top: -10px;
            margin-left: -15px;
            margin-right: -15px;
        }
        .layui-form-item .layui-inline {
            margin-top: 5px;
            margin-bottom: 5px;
            margin-right: 0px;
        }
        .layui-form-label {
            width: 25%;
        }
    </style>
</head>
<body>
    <div class="layui-fluid" style="padding: 0;">
@@ -152,20 +121,25 @@
            contentType: 'application/json',
            exts: 'xls|xlsx', //允许上传的类型
            before: function (data) {
                loadIndex = layer.load(2);
                layer.load();
            },
            done: function (data1) {
                layer.closeAll('loading');
                if (data1.count == 1) {
                    var HVersion_Import_Temp = Format(new Date(), "yyyy-MM-dd hh:mm:ss");
                    for (var i = 0; i < data1.data.length; i++) {
                        data1.data[i].HVersion_Import = HVersion_Import_Temp;
                    }
                    option.data = data1.data;
                    table.render(option);
                    layer.close(loadIndex);
                } else {
                    layer.close(loadIndex);
                    layer.alert(data1.code + data1.Message, { icon: 5 });
                }
            },
            error: function (err) {
                debugger
                layer.closeAll('loading');
                layer.alert('导入出现异常', { icon: 2 });
            }
        });
@@ -213,39 +187,65 @@
            var dd = myDate.getDate();
            var SumMonth = 31; //动态两月之差 new Date(yyyy, MM, 0).getDate()
            var columns = [];
            var HBEGINDATE = new Date(new Date($("#HDate").val())).getDate(); //获取开始日期天数
            columns.push({ type: 'checkbox', fixed: 'left' });
            columns.push({ field: 'hmainid', title: 'hmainid', width: 200, hide: true });
            columns.push({ field: '单据号', title: '单据号', width: 200 });
            columns.push({ field: '生产订单号*', title: '生产订单号' });
            columns.push({ field: '生产订单号*', title: '生产订单号', width: 150 });
            columns.push({ field: '生产订单明细行号*', title: '生产订单明细行号', width: 200 });
            columns.push({ field: '组织编码*', title: '组织编码' });
            columns.push({ field: '组织编码*', title: '组织编码', width: 150});
            columns.push({ field: 'HWorkShopID', title: 'HWorkShopID', hide: true });
            columns.push({ field: '生产车间编码*', title: '生产车间' });
            columns.push({ field: '生产车间编码*', title: '生产车间', width: 150});
            columns.push({ field: 'HSourceID', title: 'HSourceID', hide: true });
            columns.push({ field: '生产资源编码*', title: '生产资源', edit: 'text', event: "HSourceID"   });
            columns.push({ field: '生产资源编码*', title: '生产资源', edit: 'text', event: "HSourceID" });
            columns.push({ field: '产能', title: '产能', edit: 'text' });
            columns.push({ field: '优先级', title: '优先级' });
            columns.push({ field: 'HEmpID', title: 'HEmpID', hide: true });
            columns.push({ field: '员工', title: '员工' });
            columns.push({ field: '员工编码', title: '员工编码' });
            columns.push({ field: '员工', title: '员工', width: 150 });
            columns.push({ field: '员工编码', title: '员工编码', width: 150 });
            columns.push({ field: 'HMaterID', title: '物料ID', hide: true });
            columns.push({ field: '物料编码*', title: '物料编码' });
            columns.push({ field: '物料编码*', title: '物料编码', width: 150 });
            columns.push({ field: '物料名称', title: '物料名称', width: 200 });
            columns.push({ field: '规格型号', title: '规格型号' });
            columns.push({ field: '规格型号', title: '规格型号', width: 150});
            columns.push({ field: 'HUnitID', title: 'HUnitID', hide: true });
            columns.push({ field: '计量单位', title: '计量单位' });
            columns.push({ field: '批次号', title: '批次' });
            columns.push({ field: '计量单位', title: '计量单位', width: 150});
            columns.push({ field: '批次号', title: '批次', width: 150});
            columns.push({ field: '销售订单数量', title: '销售订单数量', width: 200 });
            columns.push({ field: '生产订单数量', title: '生产订单数量', width: 200 });
            columns.push({ field: '总齐套数量', title: '总齐套数量', width: 200 });
            columns.push({ field: 'ICMOBillHInterID', title: 'ICMOBillHInterID', hide: true});
            columns.push({ field: 'ICMOBillHEntryID', title: 'ICMOBillHEntryID', hide: true });
            for (var i = 0; i <= (SumMonth - dd); i++) {
                columns.push({ field: Format(yyyy + '/' + MM + '/' + (dd + i), 'yyyy-MM-dd'), title: Format(yyyy + '/' + MM + '/' + (dd + i), 'yyyy-MM-dd'), edit: 'text' })
            columns.push({ field: 'HProdORGID', title: 'HProdORGID', hide: true });
            columns.push({ field: 'HVersion_Import', title: '导入序列号'});
            var k = 0;//收集循环次数
            var Days = 45;
            for (var j = 0; j <= (Days - k); j++) {
                columns.push({ field: Format(yyyy + '/' + MM + '/' + (HBEGINDATE + j), 'yyyy-MM-dd'), title: Format(yyyy + '/' + MM + '/' + (HBEGINDATE + j), 'MM.dd'), width: 70, totalRow: true })
                //跨年的话 ä¼šä»Žä¸€æœˆä¸€å·å¼€å§‹
                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;
                }
            }
            for (var i = 1; i < dd; i++) {
                columns.push({ field: Format(yyyy + '/' + (MM + 1) + '/' + i, 'yyyy-MM-dd'), title: Format(yyyy + '/' + (MM + 1) + '/' + i, 'yyyy-MM-dd'), edit: 'text' })
            }
            //for (var i = 0; i <= (SumMonth - dd); i++) {
            //    columns.push({ field: Format(yyyy + '/' + MM + '/' + (dd + i), 'yyyy-MM-dd'), title: Format(yyyy + '/' + MM + '/' + (dd + i), 'MM.dd'), edit: 'text', width:80 })
            //}
            //for (var i = 1; i <= dd; i++) {
            //    columns.push({ field: Format(yyyy + '/' + (MM + 1) + '/' + i, 'yyyy-MM-dd'), title: Format(yyyy + '/' + (MM + 1) + '/' + i, 'MM.dd'), edit: 'text', width: 80 })
            //}
            columns.push({ fixed: 'right', title: '操作', toolbar: '#barDemo' });
            option = {
@@ -262,52 +262,100 @@
            //渲染页面
            table.render(option);
        }
        }
        //导入(保存)
        function set_AddNew(data) {
            var msgError = "";
            var num = [];
            for (var i = 0; i < table.cache["mainTable"].length; i++) {
                if (table.cache["mainTable"][i] != "") {
                    table.cache["mainTable"][i].LAY_TABLE_INDEX = i;
                    if (table.cache["mainTable"][i].物料名称.indexOf("\"") != -1 || table.cache["mainTable"][i].物料名称.indexOf(";") != -1) {
                        table.cache["mainTable"][i].物料名称 = table.cache["mainTable"][i].物料名称.replaceAll("\"", "”").replaceAll(";", ";")
                    }
                    if (table.cache["mainTable"][i].规格型号.indexOf("\"") != -1 || table.cache["mainTable"][i].规格型号.indexOf(";") != -1) {
                        table.cache["mainTable"][i].规格型号 = table.cache["mainTable"][i].规格型号.replaceAll("\"", "”").replaceAll(";", ";")
                    }
                    num.push(table.cache["mainTable"][i])
                }
            }
            data.field.HPRDORGID = sessionStorage["OrganizationID"];//组织
            var sMainStr = JSON.stringify(data.field);
            var sSubStr = JSON.stringify(num);
            var sMainSub = sMainStr + ';' + sSubStr + ';' + sessionStorage["HUserName"];
            var index = layer.load();
            $.ajax({
                type: "POST",
                url: GetWEBURL() + "/JIT_DayPlanPlatFormImport/JIT_DayPlanPlatFormImport_btnSave",
                async: true,
                data: { "sMainSub": sMainSub },
                dataType: "json",
                success: function (data) {
                    if (data.count == 1) {
                        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: "温馨提示" });
            for (var i = 0; i < option.data.length; i++) {
                if (option.data[i].物料名称.indexOf("\"") != -1 || option.data[i].物料名称.indexOf(";") != -1) {
                    option.data[i].物料名称 = option.data[i].物料名称.replaceAll("\"", "”").replaceAll(";", ";")
                }
            });
                if (option.data[i].规格型号.indexOf("\"") != -1 || option.data[i].规格型号.indexOf(";") != -1) {
                    option.data[i].规格型号 = option.data[i].规格型号.replaceAll("\"", "”").replaceAll(";", ";")
                }
            }
            //判断是否有导入权限,如果有则将总装车间之前的日计划工单作废
            if (!set_ModCheck("Sc_WorkBillSortBill_Edit")) {
                layer.msg("导入失败!无导入权限!", { icon: 5, btn: ['确认'], time: 100000, offset: 't', skin: 'layui-layer-lan', title: "温馨提示" });
                return;
            } else {
                if (!setWorkBillSortBillForDelete()) {
                    layer.msg("导入失败!往期日计划作废失败!", { icon: 5, btn: ['确认'], time: 100000, offset: 't', skin: 'layui-layer-lan', title: "温馨提示" });
                    return;
                }
            }
            var HDataSub = [];
            //JIT导入计划,每次导入100行数据,可修改i的自增值决定每次循环导入的行数
            for (var i = 0; i < option.data.length; i += 100) {
                HDataSub = option.data.slice(i, i + 100)
                data.field.HPRDORGID = sessionStorage["OrganizationID"];//组织
                var sMainStr = JSON.stringify(data.field);
                var sSubStr = JSON.stringify(HDataSub);
                var sMainSub = sMainStr + ';' + sSubStr + ';' + sessionStorage["HUserName"];
                var index = layer.load();
                $.ajax({
                    type: "POST",
                    url: GetWEBURL() + "/JIT_DayPlanPlatFormImport/JIT_DayPlanPlatFormImport_btnSave",
                    async: false,
                    data: { "sMainSub": sMainSub },
                    dataType: "json",
                    success: function (data) {
                        if (data.count == 1) {
                            layer.close(index);
                           /* layer.msg("提交成功");*/
                        }
                        else {
                            layer.close(index);
                            msgError += data.Message + ";";
                            //layer.msg(data.Message, { icon: 5, btn: ['确认'], time: 100000, offset: 't', skin: 'layui-layer-lan', title: "温馨提示" });
                        }
                    },
                    error: function (err) {
                        layer.close(index);
                        msgError += err + ";";
                        //layer.msg("错误:" + err, { icon: 5, btn: ['确认'], time: 100000, offset: 't', skin: 'layui-layer-lan', title: "温馨提示" });
                    }
                });
            }
            if (msgError.length == 0) {
                layer.msg("提交成功");
            } else {
                layer.msg(msgError, { icon: 5, btn: ['确认'], time: 100000, offset: 't', skin: 'layui-layer-lan', title: "温馨提示" });
            }
        }
        //行内删除
        function set_GridDelete(obj) {
            var rowIndex = $(obj.tr).attr("data-index");
            if (obj.event === 'del') {
                layer.confirm('真的删除行吗?', function (index) {
                    obj.del();
                    table.cache["mainTable"].splice(rowIndex, 1);  //②彻底移除元素,从缓存里移除这一行
                    option.data = table.cache["mainTable"];//将数据绑定到data上
                    table.reload(option);
                    layer.close(index);
@@ -367,6 +415,79 @@
            return vars;
        }
        //#region æƒé™åˆ¤å®š
        function set_ModCheck(ModRightNameCheck) {
            var Permission = false;
            $.ajax({
                type: "GET",
                url: GetWEBURL() + "/LMES/getReportByModRightNameCheck", //方法所在页面和方法名
                async: false,
                data: { "ModRightNameCheck": ModRightNameCheck, "user": sessionStorage["HUserName"] },
                success: function (result) {
                    if (result.count == 1) {
                        Permission = true;
                    } else {
                        //layer.alert("当前模块没有查询权限!", { icon: 5 });
                    }
                }, error: function (e) {
                    layer.alert("接口请求失败!", { icon: 5 });
                }
            });
            return Permission;
        }
        //#endregion
        //#region ä½œåºŸå¯¹åº”生产车间的日计划工单
        function setWorkBillSortBillForDelete() {
            //拼接生产车间的ID
            var HWorkShopIDArrayList = [];
            for (var i = 0; i < option.data.length; i++) {
                option.data[i]["单据号"] = "";
                option.data[i]["hmainid"] = "";
                if ($.inArray(option.data[i]["HWorkShopID"], HWorkShopIDArrayList) == -1) {
                    HWorkShopIDArrayList.push(option.data[i]["HWorkShopID"]);
                }
            }
            var HWorkShopIDListStr = "";
            for (var i = 0; i < HWorkShopIDArrayList.length; i++) {
                if (i == HWorkShopIDArrayList.length - 1) {
                    HWorkShopIDListStr = HWorkShopIDArrayList[i];
                } else {
                    HWorkShopIDListStr = HWorkShopIDArrayList[i] + ",";
                }
            }
            //作废对应生产车间ID的日计划工单
            var resultBool = false;
            var sql = "";
            if (HWorkShopIDListStr != "") {
                sql = "update Sc_WorkBillSortBillMain set HDeleteMan = '" + sessionStorage["HUserName"] + "',HDeleteDate = getdate(),HBillStatus = 4 where HWorkShopID in (" + HWorkShopIDListStr + ")";
            } else {
                return resultBool;
            }
            var ModRightNameCheck = "";
            $.ajax({
                url: GetWEBURL() + '/CommonModel/commonMethod',
                type: "GET",
                async: false,
                data: { "sql": sql, "user": sessionStorage["HUserName"], "ModRightNameCheck": ModRightNameCheck },
                success: function (data1) {
                    if (data1.count == 1) {
                        resultBool = true;
                    } else {
                        layer.alert(data1.code + data1.Message, { icon: 5 });
                    }
                }, error: function (e) {
                    layer.alert("接口请求失败!", { icon: 5 });
                }
            });
            return resultBool;
        }
        //#endregion
        //#endregion
    });