HPSC009.js 18.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443
$(function () {
    var factoryCodes = __eiInfo.getBlock("factory_code_block_id").getMappedRows();
    var groupCodes = __eiInfo.getBlock("group_code1_block_id").getMappedRows();
    var userIds = __eiInfo.getBlock("user_id1_block_id").getMappedRows();
    var factoryCode = __eiInfo.getBlock("factory_code1_block_id").getMappedRows();
    var groupName = __eiInfo.getBlock("group_name_block_id").getMappedRows();
    var userName = __eiInfo.getBlock("user_name_block_id").getMappedRows();

    $(".row").children().attr("class", "col-md-3");

    $("#QUERY").on("click", query);

    IPLATUI.EFGrid = {
        "result": {
            pageable: {
                pageSize: 10,
                pageSizes: [10, 20, 30, 50, 100, 200],
            },
            columns: [/*{
                field: "operator",
                template: function (item) {
                    console.log(item)
                    let auditStatus = item.status;
                    let template = '';
                    if (item.matId != null) {
                        template += '<a style="cursor: pointer;display: inline-flex;justify-content: center;margin:auto 5px" '
                            + 'onclick="showUploadFile(' + item.matId + ')"  >附件清单</a>';
                    }
                    if (auditStatus == 0) {
                        template += '<a style="cursor: pointer;display: inline-flex;justify-content: center;" '
                            +
                            'onclick="check(' + item.id + ',1, \'' + item.planInfoNo + '\')" >提交</a>';
                    }
                    /!*else {
                        template += '<a hidden="hidden" style="cursor: pointer;display: inline-flex;justify-content: center;" ' +
                            'onclick="check(' + item.id + ',0)" >撤回</a>';
                    }*!/
                    return template;
                }
            },*/{
                field: "registerDate",
                attributes: {
                    class: "i-input-readonly"
                },
                defaultValue: function () {
                    return currShortDate();
                }
            },{
                field: "factoryCode",
                title: "工厂",
                filter: function (options) {
                    return factoryCode;
                },
                template: function (dataItem) {
                    for (let i = 0; i < factoryCodes.length; i++) {
                        if (factoryCodes[i]['valueField'] === dataItem['factoryCode']) {
                            return factoryCodes[i]['textField'];
                        }
                    }
                    return dataItem["factoryCode"];
                }
            },{
                field: "groupCode",
                title: "下料组",
                filter: function (options) {
                    var province = options.model['factoryCode'];
                    if(province) {
                        // 返回我们过滤后的数据集
                        /*return options.values[0][province];*/
                        return _.filter(groupCodes, function (item) {
                            return item["param1Field"]==province;
                        })
                    } else {
                        return groupCodes;
                    }
                },
                template: function (dataItem) {
                    for (let i = 0; i < groupName.length; i++) {
                        if (groupName[i]['valueField'] === dataItem['groupCode']) {
                            return groupName[i]['textField'];
                        }
                    }
                    return dataItem["groupCode"];
                }
            },{
                field: "userId",
                title: "员工",
                filter: function (options) {
                    var province = options.model['factoryCode'];
                    var groupCode = options.model['groupCode'];
                    if(province) {
                        // 返回我们过滤后的数据集
                        /*return options.values[0][province];*/
                        return _.filter(userIds, function (item) {
                            return item["param1Field"]==province && item["param2Field"]==groupCode;
                        })
                    } else {
                        return userIds;
                    }
                },
                template: function (dataItem) {
                    for (let i = 0; i < userName.length; i++) {
                        if (userName[i]['valueField'] === dataItem['userId']) {
                            return userName[i]['textField'];
                        }
                    }
                    return dataItem["userId"];
                }
            }],
            loadComplete: function(grid) {
                // 此 grid 对象
                // 处理父子级联动,通过监听 change 事件,判断父级节点是否发生变化
                grid.dataSource.bind("change", function(e) {
                    // 判断父级节点是否发生变化
                    if (e.field == "factoryCode") {
                        loadChange(grid,e,"groupCode");
                    } else if (e.field == "groupCode") {
                        if (e.items[0].factoryCode.length===0){
                            loadChange(grid,e,"factoryCode");
                        }
                        loadChange(grid,e,"userId");
                    }else if (e.field == "userId") {
                        if (e.items[0].groupCode.length === 0) {
                            loadChange(grid, e, "groupCode");
                        }
                        if (e.items[0].factoryCode.length === 0) {
                            loadChange(grid, e, "factoryCode");
                        }
                    }
                });
            },
            afterEdit:function (e) {
                if (e.field === "groupCode" && e.model["factoryCode"].length === 0){
                    for (let i = 0; i < groupName.length; i++) {
                        if (e.model[e.field] === groupName[i]["valueField"]){
                            e.model["factoryCode"]=groupName[i]["param1Field"]
                            break;
                        }
                    }
                }else if (e.field === "userId" && e.model["groupCode"].length === 0){
                    for (let i = 0; i < userName.length; i++) {
                        if (e.model[e.field] === userName[i]["valueField"]){
                            //e.model["factoryCode"]=userName[i]["param1Field"]
                            e.model["groupCode"]=userName[i]["param2Field"]
                            break;
                        }
                    }
                }
            },
            onAdd: function (e) {
                //e.sender.dataSource.options.fields[4].values = factoryCode;
                //e.sender.dataSource.options.fields[5].values = groupCode
                //e.sender.dataSource.options.fields[6].values = userId;
                // 动态设置默认邮箱
                /*$.each(e.items, function(index, item){

                    item['prdtName'] = "demo"+ index + "@baosight.com";
                });*/
            },
            onSave: function (e) {
                // 阻止默认请求,使用自定义保存
                //e.preventDefault();
                //let btnNode = $(this);
                //禁用按钮
                //btnNode.attr("disabled", true);
                //saveResult(btnNode);
            },
            onSuccess: function (e) {
                console.log("onSuccess:"+e)
                if (e.eiInfo.extAttr.methodName == 'update' || e.eiInfo.extAttr.methodName == 'insert') {
                    query();
                }
            },
            onRowClick: function (e) {
                /*var block = detailGrid.getEiBlock();
                if (block != null) {
                    block.setRows([]);
                    detailGrid.setEiBlock(block);
                }
                var info = new EiInfo()
                var parentId = e.model['planInfoNo'];
                info.set("parentId", parentId);
                EiCommunicator.send("HPSC004", "queryDetail", info, {
                    onSuccess: function (ei) {//返回结果集
                        detailGrid.setEiInfo(ei);
                    }, onFail: function (ei) {
                    }
                }, {async: false});*/
            },
        }
    }

    //工厂类型下拉联动
    $('input[name="inqu_status-0-factoryCode"]').change(function () {
        var inInfo=new EiInfo();
        var factoryCode=$("#inqu_status-0-factoryCode").val();
        inInfo.set("factoryCode",factoryCode);
        inInfo.set("groupType","cutGroup");
        EiCommunicator.send("HPSC009", "queryFactoryCode", inInfo, {
            onSuccess: function (ei) {
                var input=$("#inqu_status-0-groupCode");
                let dataEdition=ei.getBlock("group_code_block_id").getMappedRows();
                input.kendoDropDownList({
                    valuePrimitive: true,
                    dataTextField: "textField",
                    dataValueField: "valueField",
                    optionLabel:"请选择",
                    dataSource: dataEdition,
                    template: "#=textField#"
                });
            }, onFail: function (ei) {
            }
        }, {async: false});
    });
    //下料组下拉联动
    $('input[name="inqu_status-0-groupCode"]').change(function () {
        var inInfo=new EiInfo();
        var factoryCode=$("#inqu_status-0-factoryCode").val();
        inInfo.set("factoryCode",factoryCode);
        var groupCode=$("#inqu_status-0-groupCode").val();
        inInfo.set("groupCode",groupCode);
        inInfo.set("groupType","cutGroup");
        EiCommunicator.send("HPSC009", "queryGroupCode", inInfo, {
            onSuccess: function (ei) {
                var input=$("#inqu_status-0-userId");
                let dataEdition=ei.getBlock("user_id_block_id").getMappedRows();
                input.kendoDropDownList({
                    valuePrimitive: true,
                    dataTextField: "textField",
                    dataValueField: "valueField",
                    optionLabel:"请选择",
                    dataSource: dataEdition,
                    template: "#=textField#"
                });
            }, onFail: function (ei) {
            }
        }, {async: false});
    });
});

function showUploadFile(id) {
    JSColorbox.open({
        href: "HPSC002B?methodName=initLoad&inqu_status-0-bizType=WL&inqu_status-0-id=" + id,
        title: "<div style='text-align: center;'>附件清单</div>",
        width: "80%",
        height: "80%",
    });
}
function check(id, auditStatus,planInfoNo) {
    const inEiInfo = new EiInfo();
    inEiInfo.set("id", id);
    inEiInfo.set("planInfoNo",planInfoNo);
    //先判断本身是否填写
    EiCommunicator.send('HPSC003', 'getInfo', inEiInfo, {
            onSuccess(ei) {
                var model=ei.get("model");
                if(!(model.planCompletionDate).trim()) {
                    NotificationUtil("提交失败!原因:基本信息中计划完成日期未填写", "error");
                    return;
                } else {
                    //提交
                    //提交前先判断明细信息中的计划开始和计划结束时间是否都已经填写,只有填写了之后才能进行提交
                    if (auditStatus == 1) {
                        EiCommunicator.send('HPSC004', 'inspectDetail', inEiInfo, {
                                onSuccess(ei) {
                                    var list=ei.get("list");
                                    if(list) {
                                        var count = list[0];
                                        if (count > 0) {
                                            NotificationUtil("提交失败!原因:明细信息中有未填写的计划开始时间或计划结束时间", "error");
                                        } else {
                                            EiCommunicator.send('HPSC004','queryDetail',inEiInfo,{
                                                onSuccess(ei){
                                                    var rows = ei.blocks.detail.rows;
                                                    var res = check_time(model,rows);
                                                    if (!res){
                                                        NotificationUtil("计划结束时间应该大于计划开始时间!", "error");
                                                    }
                                                    else {
                                                        // 提交通过,生成
                                                        EiCommunicator.send('HPSC003', 'submitPlan', inEiInfo, {
                                                                onSuccess(response) {
                                                                    NotificationUtil(response.msg);
                                                                    resultGrid.dataSource.page(1);
                                                                },
                                                                onFail(errorMessage, status, e) {
                                                                    NotificationUtil("执行失败!", "error");
                                                                }
                                                            },
                                                            {
                                                                async: false
                                                            }
                                                        );
                                                    }


                                                }
                                            })

                                        }
                                    } else {
                                        NotificationUtil("提交失败!未找到明细信息", "error");
                                    }
                                },
                                onFail(errorMessage, status, e) {
                                    NotificationUtil("执行失败!", "error");
                                }
                            },
                            {
                                async: false
                            }
                        );
                    } else {
                        // 撤回

                    }
                }
            },
            onFail(errorMessage, status, e) {
                NotificationUtil("执行失败!", "error");
            }
        },
        {
            async: false
        }
    );


}

let query = function () {
    resultGrid.dataSource.page(1);
}

function check_time(model,rows){
    for (var i=0;i<rows.length;i++){
        if (model.planInfoNo == rows[i][5]) {
            var start_time = rows[i][22];
            var end_time = rows[i][23];

            if (end_time < start_time) {

                return false;
            }
        }
    }
    return true;
}


/**
 * 保存汇总
 */
function saveResult(btn) {
    let rows = resultGrid.getCheckedRows();
    if (rows.length < 1) {
        message("请选择数据");
        return;
    }
    let flag = true;
    $.each(rows, function(index, item) {
        let planCompletionDate= item.get("planCompletionDate");
        if(isBlank(planCompletionDate)){
            message("选中的第"+(index+1)+"行\"计划结束时间\",不能为空!");
            flag = false;
            return false;
        }
    });
    if(flag) {
        JSUtils.confirm("确定对勾选中的[" + rows.length + "]条数据做\"保存\"操作? ", {
            ok: function () {
                JSUtils.submitGridsData("result", "HPSC003", "update", true);
                //释放禁用按钮
                btn.attr("disabled", false);
            }
        });
    }
}


/**
 * 保存明细
 */
function saveDetail(btn) {
    let rows = detailGrid.getCheckedRows();
    if (rows.length < 1) {
        message("请选择数据");
        return;
    }
    let flag = true;
    $.each(rows, function(index, item) {
        let planCommentDate= item.get("planCommentDate");
        let planCompletionDate= item.get("planCompletionDate");
        if(isBlank(planCommentDate)){
            message("选中的第"+(index+1)+"行\"计划开始时间\",不能为空!");
            flag = false;
            return false;
        }
        if(isBlank(planCompletionDate)){
            message("选中的第"+(index+1)+"行\"计划结束时间\",不能为空!");
            flag = false;
            return false;
        }
        let startT = new Date(planCommentDate).getTime();
        let endT = new Date(planCompletionDate).getTime();
        if (startT > endT) {
            message("选中的第"+(index+1)+"行\"计划开始时间\"不能大于\"计划结束时间\"!");
            flag = false;
            return false;
        }
    });
    if(flag) {
        JSUtils.confirm("确定对勾选中的[" + rows.length + "]条数据做\"保存\"操作? ", {
            ok: function () {
                JSUtils.submitGridsData("detail", "HPSC003", "updatePlanDetail", true);
                //释放禁用按钮
                btn.attr("disabled", false);
            }
        });
    }
}

function loadChange(grid,e,field) {
    var cell_label = field,that = grid;
    // locked 表示是否为固定列
    var locked = that.isCellLocked(cell_label);
    // tr 表示 locked 和非 locked 的行,index 表示此行的第几列
    var tr,index;
    // 获取此 model 元素信息
    var item = e.items[0];
    var _uid = item.uid;
    if (locked) {
        tr = $(".k-grid-content-locked tr[data-uid="+ _uid +"]");
        index = $("th[data-field='"+cell_label+"']").data("index");
    } else {
        tr = $(".k-grid-content tr[data-uid="+ _uid +"]");
        index = parseInt($("th[data-field='"+cell_label+"']").data("index")) - that.lockedHeader.find("th").length;
    }
    // 获取子 cell(td)
    var td = tr.children("td:eq("+index+")");
    // 触发 td.click 事件,
    td.trigger("click");
}