@model AMESCoreStudio.Web.ViewModels.PCS.PCS009RViewModel
@{
    ViewData["Title"] = "條碼追蹤查詢";
    Layout = "~/Views/Shared/_AMESLayout.cshtml";
}

<style>
    .control-label {
        justify-content: flex-end !important;
    }
</style>


<div class="layui-card">
    <form enctype="multipart/form-data" class="layui-form">
        <div asp-validation-summary="ModelOnly" class="text-danger"></div>
        <div class="layui-card-body">
            <fieldset class="layui-elem-field layui-field-title">
                <legend style="color: #e18917">條碼資料</legend>
            </fieldset>
            <div class="layui-row">
                <div class="layui-col-xs2">
                    <label class="layui-form-label-col" style="text-align:right;">生產序號:</label>
                </div>
                <div class="layui-col-xs2">
                    <div class="layui-form-item">
                        <div class="layui-input-block" style="margin-left:auto;">
                            <label class="layui-form-label" style="text-align: left; width: 150px;">@Model.BarCodeNo</label>
                        </div>
                    </div>
                </div>
                <div class="layui-col-xs2">
                    <label class="layui-form-label-col" style="text-align:right;">出貨序號:</label>
                </div>
                <div class="layui-col-xs2">
                    <div class="layui-form-item">
                        <div class="layui-input-block" style="margin-left:auto;">
                            <label class="layui-form-label" style="text-align: left; width: 150px;">@Model.ExtraBarCodeNo</label>
                        </div>
                    </div>
                </div>
                <div class="layui-col-xs2">
                    <label class="layui-form-label-col" style="text-align:right;">包裝箱號:</label>
                </div>
                <div class="layui-col-xs2">
                    <div class="layui-form-item">
                        <div class="layui-input-block" style="margin-left:auto;">
                            <label class="layui-form-label" style="text-align: left; width: 150px;">@Model.BoxNo</label>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-row">
                <div class="layui-col-xs2">
                    <label class="layui-form-label-col" style="text-align:right;">狀態描述:</label>
                </div>
                <div class="layui-col-xs2">
                    <div class="layui-form-item">
                        <div class="layui-input-block" style="margin-left:auto;">
                            <label class="layui-form-label" style="text-align: left; width: 150px;">@Model.StatusNo</label>
                        </div>
                    </div>
                </div>
                <div class="layui-col-xs2">
                    <label class="layui-form-label-col" style="text-align:right;">入庫單號:</label>
                </div>
                <div class="layui-col-xs2">
                    <div class="layui-form-item">
                        <div class="layui-input-block" style="margin-left:auto;">
                            <label class="layui-form-label" style="text-align: left; width: 150px;">@Model.InhouseNo</label>
                        </div>
                    </div>
                </div>
                <div class="layui-col-xs2">
                    <label class="layui-form-label-col" style="text-align:right;">重量(g):</label>
                </div>
                <div class="layui-col-xs2">
                    <div class="layui-form-item">
                        <div class="layui-input-block" style="margin-left:auto;">
                            <label class="layui-form-label" style="text-align: left; width: 150px;">@Model.Wight</label>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-row">
                <fieldset class="layui-elem-field layui-field-title">
                    <legend style="color: #e18917">工單歷程</legend>
                </fieldset>
                <table id="rulestionOld" class="layui-table" lay-skin="nob">
                    <tbody>
                        @foreach (var index in Model.WinInfos)
                        {
                            <tr>
                                <td style="width:70px;">
                                    工單號碼:
                                </td>
                                <td>
                                    @index.WipNo
                                </td>
                                <td>
                                    料號:
                                </td>
                                <td>
                                    @index.ItemNo
                                </td>
                                <td>
                                    BOM版本:
                                </td>
                                <td>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    生產單位:
                                </td>
                                <td>
                                    @index.UnitNo
                                </td>
                                <td>
                                    線別:
                                </td>
                                <td>
                                    @index.Line
                                </td>
                                <td>
                                    ECN:
                                </td>
                                <td>
                                    @index.ECN
                                </td>
                                <td>
                                    EAN:
                                </td>
                                <td>
                                    @index.EAN
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    建置日期:
                                </td>
                                <td>
                                    @DateTime.Parse(index.CreateDate).ToString("yyyy/MM/dd HH:mm:ss")
                                </td>
                                <td>
                                    DATE CODE:
                                </td>
                                <td>
                                    @index.DateCode
                                </td>
                                <td>
                                    客戶料號:
                                </td>
                                <td>
                                    @index.CustomerItemNo
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Remarks:
                                </td>
                                <td colspan="7">
                                    @index.Remarks
                                </td>
                            </tr>
                        }
                    </tbody>
                </table>
            </div>
            <div class="layui-row">
                <fieldset class="layui-elem-field layui-field-title">
                    <legend style="color: #e18917">生產歷程</legend>
                </fieldset>
                <table class="layui-table" lay-even lay-size="sm">
                    <thead>
                        <tr>
                            <th>
                                站別名稱
                            </th>
                            <th>
                                規格描述
                            </th>
                            <th>
                                系統類型
                            </th>
                            <th>
                                使用者
                            </th>
                            <th>
                                過站時間
                            </th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach (var index in Model.BarCodeLogs)
                        {
                            <tr>
                                <td>
                                    @index.Station
                                </td>
                                @if (index.RuleStation == "F")
                                {
                                    <td><span style="color:red">@index.RuleStation</span></td>
                                }
                                else
                                {
                                    <td>
                                        @index.RuleStation
                                    </td>
                                }

                                <td>
                                    @index.SysType
                                </td>
                                <td>
                                    @index.User
                                </td>
                                <td>
                                    @DateTime.Parse(index.InputDate).ToString("yyyy/MM/dd HH:mm:ss")
                                </td>
                            </tr>
                        }
                    </tbody>
                </table>
            </div>

            @if (Model.testLogs.Count != 0)
            {
                <div class="layui-row">
                    <fieldset class="layui-elem-field layui-field-title">
                        <legend style="color: #e18917">TestLog</legend>
                    </fieldset>
                    <table class="layui-table" lay-even lay-size="sm">
                        <thead>
                            <tr>
                                <th>
                                    結果
                                </th>
                                <th>
                                    測試時間
                                </th>
                                <th>
                                    檔案路徑
                                </th>
                                <th style="width:70px;"></th>
                                <th style="width:70px;"></th>
                            </tr>
                        </thead>
                        <tbody>
                            @foreach (var index in Model.testLogs)
                            {
                                <tr>
                                    <td>
                                        @if (index.Result == "FAIL")
                                        {
                                            <span style="color:red">@index.Result</span>
                                        }
                                        else
                                        {
                                            <span style="color:blue">@index.Result</span>
                                        }
                                    </td>
                                    <td>
                                        @index.Record_Time
                                    </td>
                                    <td>
                                        <a style="cursor: pointer;" onclick='show("@index.FilePath","testlog");'>@index.FileName</a>
                                    </td>
                                    <td>
                                        <input type="hidden" id="filePath" name="filePath" value="@index.FilePath">
                                        <a class="layui-btn layui-btn-primary layui-border-blue layui-btn-sm" onclick='Filedownload(this,"testlog");'>檔案下載</a>
                                    </td>
                                    <td>
                                        <a class="layui-btn layui-btn-primary layui-border-black layui-btn-sm" onclick='testLog(@index.TestId);'>測試項目</a>
                                    </td>
                                </tr>
                            }
                        </tbody>
                    </table>
                </div>
            }

            @if (Model.packingWeighs.Count != 0)
            {
                <div class="layui-row">
                    <fieldset class="layui-elem-field layui-field-title">
                        <legend style="color: #e18917">包裝秤重</legend>
                    </fieldset>
                    <table class="layui-table" lay-even lay-size="sm">
                        <thead>
                            <tr>
                                <th>
                                    結果
                                </th>
                                <th>
                                    秤重時間
                                </th>
                                <th>
                                    秤重值
                                </th>
                                <th>
                                    檔案名稱
                                </th>
                                <th style="width:70px;"></th>
                            </tr>
                        </thead>
                        <tbody>
                            @foreach (var index in Model.packingWeighs)
                            {
                                <tr>
                                    <td>
                                        @if (index.Result == "FAIL")
                                        {
                                            <span style="color:red">@index.Result</span>
                                        }
                                        else
                                        {
                                            <span style="color:blue">@index.Result</span>
                                        }
                                    </td>
                                    <td>
                                        @index.Record_Time
                                    </td>
                                    <td>
                                        @index.Weight
                                    </td>
                                    <td>
                                        <a style="cursor: pointer;" onclick='show("@index.FilePath","packing");'>@index.FileName</a>
                                    </td>
                                    <td>
                                        <input type="hidden" id="filePath" name="filePath" value="@index.FilePath">
                                        <a class="layui-btn layui-btn-primary layui-border-blue layui-btn-sm" onclick='Filedownload(this,"packing");'>檔案下載</a>
                                    </td>
                                </tr>
                            }
                        </tbody>
                    </table>
                </div>
            }

            <div class="layui-row">
                <fieldset class="layui-elem-field layui-field-title">
                    <legend style="color: #e18917">組件清單</legend>
                </fieldset>
                <table class="layui-table" lay-even lay-size="sm">
                    <thead>
                        <tr>
                            <th>
                                站別名稱
                            </th>
                            <th>
                                組件名稱
                            </th>
                            <th>
                                組件條碼
                            </th>
                            <th>
                                組件料號
                            </th>
                            <th>
                                綁入人員
                            </th>
                            <th>
                                綁入時間
                            </th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach (var index in Model.BarCodeKPs)
                        {
                            <tr>
                                <td>
                                    @index.StationName
                                </td>
                                <td>
                                    @index.ItemNoName
                                </td>
                                <td>
                                    @index.PartNo
                                </td>
                                <td>
                                    @index.KpItemNo
                                </td>
                                <td>
                                    @index.CreateUser
                                </td>
                                <td>
                                    @index.CreateDate.ToString("yyyy/MM/dd HH:mm:ss")
                                </td>
                            </tr>
                        }
                    </tbody>
                </table>
            </div>
            <div class="layui-row">
                <fieldset class="layui-elem-field layui-field-title">
                    <legend style="color: #e18917">送修紀錄</legend>
                </fieldset>
                <table class="layui-table" lay-even lay-size="sm">
                    <thead>
                        <tr>
                            <th>
                                站別名稱
                            </th>
                            <th>
                                不良代碼
                            </th>
                            <th>
                                零件位置
                            </th>
                            <th>
                                維修代碼
                            </th>
                            <th>
                                維修狀態
                            </th>
                            <th>
                                回覆人員
                            </th>
                            <th>
                                回覆日期
                            </th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach (var index in Model.nGInfoDtos)
                        {
                            <tr>
                                <td>
                                    @index.StationName
                                </td>
                                <td>
                                    @index.NGNo
                                </td>
                                <td>
                                    @index.LocationNo
                                </td>
                                <td>
                                    @index.RepairNo
                                </td>
                                <td>
                                    @index.Status
                                </td>
                                <td>
                                    @index.ReplyUser
                                </td>
                                <td>
                                    @DateTime.Parse(index.ReplyDate).ToString("yyyy/MM/dd HH:mm:ss")
                                </td>
                            </tr>
                        }
                    </tbody>
                </table>
            </div>
            <div class="layui-row">
                <fieldset class="layui-elem-field layui-field-title">
                    <legend style="color: #e18917">治具清單</legend>
                </fieldset>
                <table class="layui-table" lay-even lay-size="sm">
                    <thead>
                        <tr>
                            <th>
                                站別名稱
                            </th>
                            <th>
                                設備編號
                            </th>
                            <th>
                                過站時間
                            </th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach (var index in Model.Outfits)
                        {
                            <tr>
                                <td>
                                    @index.Station
                                </td>
                                <td>
                                    @index.OutfitNo
                                </td>
                                <td>
                                    @DateTime.Parse(index.InputDate).ToString("yyyy/MM/dd HH:mm:ss")
                                </td>
                            </tr>
                        }
                    </tbody>
                </table>
            </div>
            <div class="layui-row">
                <fieldset class="layui-elem-field layui-field-title">
                    <legend style="color: #e18917">條碼變更</legend>
                </fieldset>
                <table class="layui-table" lay-even lay-size="sm">
                    <thead>
                        <tr>
                            <th>
                                (舊)條碼序號
                            </th>
                            <th>
                                (新)條碼序號
                            </th>
                            <th>
                                變更類型
                            </th>
                            <th>
                                備註
                            </th>
                            <th>
                                變更人員
                            </th>
                            <th>
                                變更時間
                            </th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach (var index in Model.BarCodeChanges)
                        {
                            <tr>
                                <td>
                                    @index.BarCodeOld
                                </td>
                                <td>
                                    @index.BarCodeNew
                                </td>
                                <td>
                                    @index.BarCodeChangeType
                                </td>
                                <td>
                                    @index.Memo
                                </td>
                                <td>
                                    @index.User
                                </td>
                                <td>
                                    @index.Date
                                </td>
                            </tr>
                        }
                    </tbody>
                </table>
            </div>
            <div class="layui-row">
                <fieldset class="layui-elem-field layui-field-title">
                    <legend style="color: #e18917">組件變更</legend>
                </fieldset>
                <table class="layui-table" lay-even lay-size="sm">
                    <thead>
                        <tr>
                            <th>
                                站別名稱
                            </th>
                            <th>
                                組件名稱
                            </th>
                            <th>
                                (舊)組件條碼
                            </th>
                            <th>
                                替換人員
                            </th>
                            <th>
                                替換時間
                            </th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach (var index in Model.KPChanges)
                        {
                            <tr>
                                <td>
                                    @index.StationName
                                </td>
                                <td>
                                    @index.ItemNoName
                                </td>
                                <td>
                                    @index.PartNoOld
                                </td>
                                <td>
                                    @index.CreateUser
                                </td>
                                <td>
                                    @index.CreateDate.ToString("yyyy/MM/dd HH:mm:ss")
                                </td>
                            </tr>
                        }
                    </tbody>
                </table>
            </div>
            <div class="layui-row">
                <fieldset class="layui-elem-field layui-field-title">
                    <legend style="color: #e18917">備料</legend>
                </fieldset>
            </div>
        </div>
    </form>
</div>

@section Scripts {
    @{
        await Html.RenderPartialAsync("_ValidationScriptsPartial");
        await Html.RenderPartialAsync("_FileinputScriptsPartial");
    }

    <script type="text/javascript">
        // 測試Log
        function testLog(id) {
            layui.use('layer', function () {
                var layer = layui.layer;
                layer.open({
                    title: '測試Log',
                    type: 2,
                    area: ['800px', '400px'],
                    fixed: false, //不固定
                    maxmin: true,
                    content: `/PCS/PCS009T?sn=${@Model.BarCodeNo}&id=${id}`
                });
            });
        };

        function show(id, type) {
            layui.use('layer', function () {
                var layer = layui.layer;
                layer.open({
                    type: 2,
                    title: '預覽文件',
                    shadeClose: true,//点击遮罩关闭层
                    shade: 0.8,
                    area: ['90%', '90%'],
                    zIndex: 19891014,
                    content: `/PCS/PCS009V?id=${id}&type=${type}`
                });
            });
        };

        // 檔案下載
        function Filedownload(obj, type) {
            var FileName = $(obj).closest("TR").find('input[id*=filePath]').val();
            let Path = FileName.replace('&#92;', '/');
            filePath = `/PCS/PCS009U?id=${Path}&type=${type}`;
            console.log(filePath);
            $(obj).attr("href", filePath);
        };
    </script>
}