<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('录入盘点结果')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-task-result" th:object="${amsInventoryTask}">
            <input name="taskId" th:field="*{taskId}" type="hidden">
            <div class="row">
                <div class="col-sm-4">
                    <div class="form-group">
                        <label class="col-sm-4 control-label">任务号：</label>
                        <div class="col-sm-8"><p class="form-control-static" th:text="*{taskNo}"></p></div>
                    </div>
                </div>
                <div class="col-sm-4">
                    <div class="form-group">
                        <label class="col-sm-4 control-label">范围：</label>
                        <div class="col-sm-8"><p class="form-control-static" th:text="*{@dict.getLabel('ams_inventory_scope_type', scopeType)}"></p></div>
                    </div>
                </div>
                <div class="col-sm-4">
                    <div class="form-group">
                        <label class="col-sm-4 control-label">状态：</label>
                        <div class="col-sm-8"><p class="form-control-static" th:text="*{@dict.getLabel('ams_inventory_task_status', taskStatus)}"></p></div>
                    </div>
                </div>
            </div>

            <h4 class="form-header h4">应盘明细结果</h4>
            <div class="col-sm-12 select-table table-striped">
                <table class="table table-bordered table-hover">
                    <thead>
                        <tr>
                            <th style="width: 110px;">资产编码</th>
                            <th style="width: 140px;">资产名称</th>
                            <th style="width: 120px;">账面仓库</th>
                            <th style="width: 120px;">账面位置</th>
                            <th style="width: 130px;">盘点结果</th>
                            <th style="width: 180px;">盘点仓库</th>
                            <th style="width: 180px;">盘点位置</th>
                            <th style="width: 180px;">备注</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr th:each="item, stat : *{amsInventoryTaskItemList}">
                            <td>
                                <input type="hidden" th:name="|amsInventoryTaskItemList[${stat.index}].itemId|" th:value="${item.itemId}">
                                <span th:text="${item.assetCode}"></span>
                            </td>
                            <td th:text="${item.assetName}"></td>
                            <td th:text="${item.bookWarehouseName}"></td>
                            <td th:text="${item.bookLocationName}"></td>
                            <td>
                                <select class="form-control" th:name="|amsInventoryTaskItemList[${stat.index}].inventoryResult|"
                                        th:with="type=${@dict.getType('ams_inventory_result')}" required>
                                    <option value="">请选择</option>
                                    <option th:each="dict : ${type}" th:if="${dict.dictValue != 'SURPLUS'}"
                                            th:text="${dict.dictLabel}" th:value="${dict.dictValue}"
                                            th:selected="${dict.dictValue == item.inventoryResult}"></option>
                                </select>
                            </td>
                            <td>
                                <select class="form-control" th:name="|amsInventoryTaskItemList[${stat.index}].inventoryWarehouseId|">
                                    <option value="">默认账面仓库</option>
                                    <option th:each="warehouse : ${warehouseList}" th:value="${warehouse.warehouseId}"
                                            th:text="${warehouse.warehouseCode + ' - ' + warehouse.warehouseName}"
                                            th:selected="${warehouse.warehouseId == item.inventoryWarehouseId}"></option>
                                </select>
                            </td>
                            <td>
                                <select class="form-control" th:name="|amsInventoryTaskItemList[${stat.index}].inventoryLocationId|">
                                    <option value="">默认账面位置</option>
                                    <option th:each="location : ${locationList}" th:value="${location.locationId}"
                                            th:text="${location.locationCode + ' - ' + location.locationName}"
                                            th:selected="${location.locationId == item.inventoryLocationId}"></option>
                                </select>
                            </td>
                            <td>
                                <input class="form-control" type="text" maxlength="500"
                                       th:name="|amsInventoryTaskItemList[${stat.index}].remark|" th:value="${item.remark}">
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </form>

        <h4 class="form-header h4">盘盈明细</h4>
        <form class="form-horizontal m" id="form-surplus-add"
              th:if="${amsInventoryTask.taskStatus == 'ISSUED' or amsInventoryTask.taskStatus == 'INVENTORYING'}">
            <input name="taskId" th:value="${amsInventoryTask.taskId}" type="hidden">
            <div class="row">
                <div class="col-sm-2">
                    <select class="form-control" name="identifyMethod" required>
                        <option value="EPC">EPC识别</option>
                        <option value="ASSET_CODE">资产编码</option>
                        <option value="MANUAL">手工记录</option>
                    </select>
                </div>
                <div class="col-sm-2"><input class="form-control" name="epcCode" maxlength="128" placeholder="EPC编码"></div>
                <div class="col-sm-2"><input class="form-control" name="assetCode" maxlength="64" placeholder="资产编码"></div>
                <div class="col-sm-2"><input class="form-control" name="assetName" maxlength="100" placeholder="资产名称"></div>
                <div class="col-sm-2">
                    <select class="form-control" name="inventoryWarehouseId" required>
                        <option value="">盘点仓库</option>
                        <option th:each="warehouse : ${warehouseList}" th:value="${warehouse.warehouseId}"
                                th:text="${warehouse.warehouseCode + ' - ' + warehouse.warehouseName}"></option>
                    </select>
                </div>
                <div class="col-sm-2">
                    <select class="form-control" name="inventoryLocationId" required>
                        <option value="">盘点位置</option>
                        <option th:each="location : ${locationList}" th:value="${location.locationId}"
                                th:text="${location.locationCode + ' - ' + location.locationName}"></option>
                    </select>
                </div>
            </div>
            <div class="row m-t-sm">
                <div class="col-sm-10"><input class="form-control" name="remark" maxlength="500" placeholder="备注"></div>
                <div class="col-sm-2"><a class="btn btn-primary btn-block" onclick="addSurplus()">新增盘盈</a></div>
            </div>
        </form>
        <div class="col-sm-12 select-table table-striped">
            <table class="table table-bordered table-hover">
                <thead>
                    <tr>
                        <th>类型</th>
                        <th>识别方式</th>
                        <th>资产编码</th>
                        <th>资产名称</th>
                        <th>EPC</th>
                        <th>账面仓库</th>
                        <th>账面位置</th>
                        <th>盘点仓库</th>
                        <th>盘点位置</th>
                        <th>状态</th>
                        <th>盘点人</th>
                        <th>备注</th>
                        <th th:if="${amsInventoryTask.taskStatus == 'ISSUED' or amsInventoryTask.taskStatus == 'INVENTORYING'}">操作</th>
                    </tr>
                </thead>
                <tbody>
                    <tr th:each="surplus : ${amsInventoryTask.amsInventoryTaskSurplusList}">
                        <td th:text="${@dict.getLabel('ams_inventory_surplus_type', surplus.surplusType)}"></td>
                        <td th:text="${@dict.getLabel('ams_inventory_identify_method', surplus.identifyMethod)}"></td>
                        <td th:text="${surplus.assetCode}"></td>
                        <td th:text="${surplus.assetName}"></td>
                        <td th:text="${surplus.epcCode}"></td>
                        <td th:text="${surplus.bookWarehouseName}"></td>
                        <td th:text="${surplus.bookLocationName}"></td>
                        <td th:text="${surplus.inventoryWarehouseName}"></td>
                        <td th:text="${surplus.inventoryLocationName}"></td>
                        <td th:text="${@dict.getLabel('ams_inventory_surplus_status', surplus.confirmStatus)}"></td>
                        <td th:text="${surplus.inventoryUserName}"></td>
                        <td th:text="${surplus.remark}"></td>
                        <td th:if="${amsInventoryTask.taskStatus == 'ISSUED' or amsInventoryTask.taskStatus == 'INVENTORYING'}">
                            <a class="btn btn-danger btn-xs" th:onclick="|removeSurplus(${surplus.surplusId})|"><i class="fa fa-remove"></i>删除</a>
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var prefix = ctx + "asset/task";
        $("#form-task-result").validate({ focusCleanup: true });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/result/submit", $("#form-task-result").serialize());
            }
        }

        function addSurplus() {
            $.operate.saveModal(prefix + "/surplus/add", $("#form-surplus-add").serialize(), function(result) {
                if (result.code == web_status.SUCCESS) {
                    setTimeout(function() { location.reload(); }, 500);
                }
            });
        }

        function removeSurplus(surplusId) {
            $.modal.confirm("确认删除该盘盈明细吗？", function() {
                $.operate.saveModal(prefix + "/surplus/remove/" + surplusId, {}, function(result) {
                    if (result.code == web_status.SUCCESS) {
                        setTimeout(function() { location.reload(); }, 500);
                    }
                });
            });
        }
    </script>
</body>
</html>
