InspectionExt.cshtml 22 KB
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 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@{
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@section header
    {
    <style type="text/css">
        .head {
            padding-top: 7px;
            border-bottom: 1px solid #eee !important;
        }
    </style>
}
<div class="layui-fluid">
    <!--head-->
    <header class="layui-row head layui-form" lay-filter="example">
        <div class="layui-col-sm3">
            <div class="layui-form-item">
                <label class="layui-form-label">条码信息<span class="lable-required">*</span></label>
                <div class="layui-input-inline">
                    <input type="text" name="barCode" id="barCode" lay-verify="required" onkeydown="enter(event)" autocomplete="off" placeholder="请录入条码信息" class="layui-input" />
                </div>
            </div>
        </div>
        <div class="layui-col-sm3">
            <div class="layui-form-item">
                <label class="layui-form-label">工位信息<span class="lable-required">*</span></label>
                <div class="layui-input-inline" lay-filter="stationCode">
                    <select name="stationCode" id="stationCode" lay-filter="stationCode"></select>
                </div>
            </div>
        </div>
        <div class="layui-col-sm3">
            <div class="layui-form-item">
                <label class="layui-form-label">操作时间<span class="lable-required">*</span></label>
                <div class="layui-input-inline">
                    <input name="optionTime" id="optionTime" autocomplete="off" lay-verify="required" class="layui-input layui-date" value="@DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")" />
                </div>
            </div>
        </div>
    </header>
    <!--内容-->
    <div class="layui-row content">
        <div class="layui-row">
            <div class="layui-card">
                <div class="layui-card-header">
                    <b>工序信息</b><span>&nbsp;&nbsp;</span>
                    <button class="layui-btn layui-btn-sm" onclick="search(false)"><i class="layui-icon layui-icon-search"></i>获取数据</button>
                    <button class="layui-btn layui-btn-sm" onclick="resert()"><i class="layui-icon layui-icon-refresh"></i>重置</button>
                </div>
                <div class="layui-card-body">
                    <table class="layui-table" id="mainList" lay-filter="mainList"></table>
                </div>
            </div>
        </div>
    </div>

    <div class="layui-row">
        <div class="layui-col-md6">
            <div class="layui-card">
                <div class="layui-card-header"><b>物料信息</b></div>
                <div class="layui-card-body">
                    <table class="layui-table" id="materialInfo" lay-filter="materialInfo"></table>
                </div>
            </div>
        </div>
        <div class="layui-col-md6">
            <div class="layui-card">
                <div class="layui-card-header"><b>设备信息</b></div>
                <div class="layui-card-body">
                    <table class="layui-table" id="equipmentInfo" lay-filter="equipmentInfo"></table>
                </div>
            </div>
        </div>
    </div>

    <!--按钮-->
    <footer class="layui-btn-container layui-container">
        <button id="start" class="layui-btn layui-btn-normal layui-btn-lg" onclick="start()"><i class="layui-icon layui-icon-flag"></i>工序开工</button>
        <button id="complate" class="layui-btn layui-btn-lg" onclick="complete()"><i class="layui-icon layui-icon-ok"></i>工序完工</button>
        <button id="workReport" class="layui-btn layui-btn-warm layui-btn-lg" onclick="workReport()"><i class="layui-icon layui-icon-release"></i>报工MOM</button>
    </footer>
</div>

<script type="text/html" id="MaterialUseLog">
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delete">删除</a>
</script>

<script type="text/html" id="EquipmentProcessTemplate">
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delete">删除</a>
</script>

<script type="text/html" id="stateLable">
    {{# if(d.state==0){ }}
    <span>初始化</span>
    {{# }else if(d.state==30){ }}
    <span>生产中</span>
    {{# }else if(d.state==60){ }}
    <span>运输中</span>
    {{# }else if(d.state==100){ }}
    <span>已完成</span>
    {{# }else if(d.state==100){ }}
    <span>已变更无需处理</span>
    {{# }else { }}
    <span>{{ d.state}}</span>
    {{# } }}
</script>
<script type="text/html" id="workReportLable">
    {{# if(d.workReportStatus==0){ }}
    <span>未报工</span>
    {{# }else if(d.workReportStatus==10){ }}
    <span>开工已报工</span>
    {{# }else if(d.workReportStatus==20){ }}
    <span>完工已报工</span>
    {{# }else if(d.workReportStatus==30){ }}
    <span>无需报工</span>
    {{# }else { }}
    <span>{{ d.workReportStatus}}</span>
    {{# } }}
</script>
@section Scripts
    {
    <script>
        var element, table, laydate, form, layer = null;
        //默认值
        const defaultData =
        {
            id: 0,
            headKeys: "",
            bodyKeys: "",
            workOrderInfo: [],
            materInfo: [],
            equipmentInfo: []
        };
        var allTableData = defaultData;
        layui.use(['table', 'element', 'laydate', 'form', 'layer'], function () {
            element = layui.element;
            table = layui.table;
            laydate = layui.laydate;
            form = layui.form;
            layer = layui.layer;
            laydate.render({
                elem: '#optionTime',
                type: 'datetime'
            });
            reloadTable();
        });

        //重载所有表格数据
        function reloadTable() {
            //工序信息
            table.render({
                elem: '#mainList',
                even: true,
                height: 150,
                data: allTableData.workOrderInfo,
                size: 'sm',
                cols: [[
                    { field: "id", width: 60, title: " ID" },
                    { field: "keys", width: 150, hide: true, title: "keys" },
                    { field: "bodyKeys", width: 150, hide: true, title: "bodyKeys" },
                    { field: "planCode", width: 150, title: "生产计划号" },
                    { field: "productHeaderCode", width: 150, title: "产品编号" },
                    { field: "productHeaderName", width: 150, title: "产品名称" },
                    { field: "workCenterCode", width: 150, title: "工作中心编号" },
                    { field: "lineCode", width: 150, title: "线体编号" },
                    { field: "lineName", width: 150, title: "线体名称" },
                    { field: "workOrderCode", width: 150, title: "订单编号" },
                    { field: "state", width: 150, title: "状态", templet: "#stateLable" },
                    { field: "workReportStatus", width: 150, title: "报工状态", templet: "#workReportLable" },
                    { field: "serialNumber", width: 150, title: "工序" },
                    { field: "planStartTime", width: 150, title: "计划开始时间" },
                    { field: "planEndTime", width: 150, title: "计划结束时间" },
                    { field: "actualStartTime", width: 150, title: "实际开始时间" },
                    { field: "actualEndTime", width: 150, title: "实际结束时间" },
                    { field: "createTime", width: 150, title: "创建时间" },
                ]],
                done: function (res, curr, count) {
                    var that = this.elem.next();
                    res.Result.forEach(function (item, index) {
                        if (item.id == allTableData.id) {
                            var tr = that.find(".layui-table-box tbody tr[data-index='" + index + "']");
                            tr.css("background-color", "#31BDEC");
                            tr.css("color", "white");
                        }
                    });
                }
            });

            //物料信息
            table.render({
                elem: '#materialInfo',
                even: true,
                height: 200,
                data: allTableData.materInfo,
                size: 'sm',
                cols: [[
                    { field: "id", width: 80, title: "id", hide: true },
                    { field: "key", width: 80, title: "Keys", hide: true },
                    { field: "materialCode", width: 150, title: "物料编码" },
                    { field: "materialName", width: 150, title: "物料名称" },
                    { field: "qyt", width: 80, title: "数量" },
                    { field: "crux", width: 100, title: "精追件标识", templet: function (obj) { return obj.crux == "false" ? "否" : "是" } },
                    { field: "createTime", width: 170, title: "创建时间" },
                    { field: "createBy", width: 150, title: "创建人" },
                    { field: "remarks", width: 150, title: "备注" },
                    { fixed: 'right', title: '操作', width: 70, toolbar: '#MaterialUseLog' }
                ]],
            });

            table.on(`tool(materialInfo)`, function (obj) {
                if (obj.event === "delete") {
                    layer.confirm(`你确定删除【${obj.data.materialCode}】行吗?`, function (index) {
                        var deleteItem = allTableData.materInfo.find(x => x.id == obj.data.id);
                        allTableData.materInfo.splice(allTableData.materInfo.indexOf(deleteItem), 1)
                        obj.del();
                        layer.close(index);
                    });
                }
            });

            //重载设备Table信息
            reloadEquipmentTable();

            //启用或禁用按钮
            if (allTableData.workOrderInfo.length === 0) {
                //禁用
                if (!$("#start").hasClass("layui-btn-disabled")) {
                    $("#start").addClass("layui-btn-disabled");
                }
                if (!$("#complate").hasClass("layui-btn-disabled")) {
                    $("#complate").addClass("layui-btn-disabled");
                }
                if (!$("#workReport").hasClass("layui-btn-disabled")) {
                    $("#workReport").addClass("layui-btn-disabled");
                }
            }
            else {
                //启用
                if ($("#start").hasClass("layui-btn-disabled")) {
                    $("#start").removeClass("layui-btn-disabled");
                }
                if ($("#complate").hasClass("layui-btn-disabled")) {
                    $("#complate").removeClass("layui-btn-disabled");
                }
                if ($("#workReport").hasClass("layui-btn-disabled")) {
                    $("#workReport").removeClass("layui-btn-disabled");
                }
                //当前待报工的工序
                var workOrder = allTableData.workOrderInfo.find(x => x.id == allTableData.id);
                $("#stationCode").empty();
                layui.form.render("select");
                $.ajax({
                    type: "post",
                    url: "/configure/Station/LoadStationCodeByworkCenterCode",
                    data: {
                        workCenterCode: workOrder.workCenterCode,
                        lineCode: workOrder.lineCode
                    },
                    success: function (res) {
                        var data = JSON.parse(res);
                        if (data.Status) {
                            $.each(data.Result, function (index, value) {
                                $("#stationCode").append(new Option(value.workStationName, value.workStationCode));
                            });
                            layui.form.render("select");
                        }
                        else {
                            layer.msg(data.Message, { icon: 2 });
                        }
                    },
                    error: function (err) {
                        console.log(err);
                        layer.msg(err.statusText, { icon: 2 });
                    }
                })

                ////监听工位选中事件
                form.on('select(stationCode)', function (data) {
                    var stationCode = form.val('example').stationCode;
                    var workOrder = allTableData.workOrderInfo.find(x => x.id == allTableData.id);
                    if (stationCode != null && stationCode != "") {
                        $.ajax({
                            type: "post",
                            url: "GetEquipmentInfo",
                            data: {
                                "bodyKeys": allTableData.bodyKeys,
                                "workCenterCode": workOrder.workCenterCode,
                                "stationCode": stationCode
                            },
                            success: function (res) {
                                var resultData = JSON.parse(res);
                                allTableData.equipmentInfo = resultData.Result;
                                reloadEquipmentTable();
                                if (resultData.Status) {
                                    layer.msg(resultData.Message, { icon: 1 });
                                }
                                else {
                                    layer.msg(resultData.Message, { icon: 2 });
                                }
                            },
                            error: function (ero) {
                                layer.msg(err.statusText, { icon: 2 });
                            }
                        })
                    }
                })
            }
        }

        //重载设备Table信息
        function reloadEquipmentTable() {
            table.render({
                elem: '#equipmentInfo',
                even: true,
                height: 200,
                data: allTableData.equipmentInfo,
                size: 'sm',
                cols: [[
                    { field: "id", width: 80, title: "id", hide: true },
                    { field: "key", width: 80, title: "key", hide: true },
                    { field: "device_code", width: 150, title: "设备编号" },
                    { field: "device_information", width: 150, title: "设备信息" },
                    { field: "processing_steps", width: 150, title: "加工步骤" },
                    { field: "processing_parameters", width: 150, title: "加工参数名称" },
                    { field: "processing_results", width: 150, title: "加工参数执行结果" },
                    { field: "createTime", width: 170, title: "创建时间" },
                    { field: "createBy", width: 150, title: "创建人" },
                    { field: "remarks", width: 150, title: "备注" },
                    { fixed: 'right', title: '操作', width: 70, toolbar: '#EquipmentProcessTemplate' }
                ]],
            });

            table.on(`tool(equipmentInfo)`, function (obj) {
                if (obj.event === "delete") {
                    layer.confirm(`你确定删除【${obj.data.device_information}】行吗?`, function (index) {
                        var deleteItem = allTableData.equipmentInfo.find(x => x.id == obj.data.id);
                        allTableData.equipmentInfo.splice(allTableData.equipmentInfo.indexOf(deleteItem), 1)
                        obj.del();
                        layer.close(index);
                    });
                }
            });
        }

        //根据条码获取数据
        function search(local) {
            var code = $("#barCode").val();
            $.ajax({
                type: "post",
                data: {
                    barCode: code
                },
                success: function (data) {
                    var resultData = JSON.parse(data);
                    if (resultData.Status) {
                        if (local) {
                            //只更新工序信息数据
                            allTableData.workOrderInfo = resultData.Result.workOrderInfo;
                        } else {
                            //更新所有数据
                            allTableData = resultData.Result;
                            layer.msg(resultData.Message);
                        }
                        reloadTable();
                    }
                    else {
                        layer.msg(resultData.Message, { icon: 2 });
                        allTableData = defaultData;
                        reloadTable();
                    }
                },
                error: function (err) {
                    console.log(err);
                    layer.msg(err.statusText, { icon: 2 });
                }
            });
        }

        //工序开工
        function start() {
            var stationCode = form.val('example').stationCode;
            if (stationCode == null || stationCode == "") {
                layer.msg("请选择工位信息", { icon: 2 });
                return;
            }
            var optionTime = $("#optionTime").val();
            if (optionTime == null || optionTime == "") {
                layer.msg("时间不能为空!", { icon: 2 });
                return;
            }
            $.ajax({
                type: "post",
                url: "UpdateProcess",
                data: {
                    headKeys: allTableData.headKeys,
                    bodyKeys: allTableData.bodyKeys,
                    id: allTableData.id,
                    actualStartTime: optionTime,
                    Material: allTableData.materInfo,
                    Equipment: allTableData.equipmentInfo,
                    stationCode: stationCode
                },
                success: function (data) {
                    var resultData = JSON.parse(data);
                    console.log(resultData);
                    if (resultData.Status) {
                        search(true);
                        workReport("当前工序已开工,");
                    }
                    else {
                        layer.msg(resultData.Message, { icon: 2 });
                    }
                },
                error: function (err) {
                    console.log(err);
                    layer.msg(err.statusText, { icon: 2 });
                }
            })
        }

        //工序完工
        function complete() {
            var optionTime = $("#optionTime").val();
            if (optionTime == null || optionTime == "") {
                layer.msg("时间不能为空!", { icon: 2 });
                return;
            }
            $.ajax({
                type: "post",
                url: "WorkComplete",
                data: {
                    headKeys: allTableData.headKeys,
                    id: allTableData.id,
                    actualEndTime: optionTime
                },
                success: function (data) {
                    var resultData = JSON.parse(data);
                    if (resultData.Status) {
                        search(true);
                        workReport("当前工序已完工,");
                    }
                    else {
                        layer.msg(resultData.Message, { icon: 2 });
                    }
                },
                error: function (err) {
                    console.log(err);
                    layer.msg(err.statusText, { icon: 2 });
                }
            })
        }

        //重置
        function resert() {
            $("#barCode").val("");
            allTableData = defaultData;
            reloadTable();
            $("#stationCode").empty();
            layui.form.render("select");
        }

        //条码录入回车事件
        function enter(event) {
            if (event.keyCode == 13) {
                search(false);
            }
        }

        //报工
        function workReport(title) {
            if (title == undefined) {
                title = `ID:“${allTableData.id}”,`;
            }
            layer.confirm(`${title}是否需要报工?`, { icon: 3, title: '提示' }, function (idnex) {
                $.ajax({
                    type: "post",
                    url: `WorkReport`,
                    data: { headKey: allTableData.headKeys },
                    success: function (res) {
                        var resData = JSON.parse(res);
                        if (resData.Status == false) {
                            layer.msg(resData.Message);
                        }
                        else {
                            layer.confirm(resData.Message, { icon: 3, title: '提示' }, function (index) {
                                $.ajax({
                                    type: "post",
                                    url: `WorkReport`,
                                    data: { headKey: allTableData.headKeys, IsValdate: false },
                                    success: function (result) {
                                        resData = JSON.parse(result);
                                        if (resData.Status == false) {
                                            layer.msg(resData.Message, { icon: 2 });
                                        }
                                        else {
                                            search(true);
                                            layer.msg(resData.Message, { icon: 1 });
                                        }
                                    },
                                    error: function (err) {
                                        console.log(err);
                                        layer.msg(err.statusText, { icon: 2 });
                                    }
                                });
                                layer.close(index);
                            });
                        }
                    },
                    error: function (err) {
                        console.log(err);
                        layer.msg(err.statusText, { icon: 2 });
                    }
                });
            });
        }
    </script>
}