<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('绑定RFID标签')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-tag-bind" th:object="${amsRfidTag}">
            <input name="tagId" type="hidden" th:field="*{tagId}">
            <div class="form-group">
                <label class="col-sm-3 control-label">标签编码：</label>
                <div class="col-sm-8">
                    <input class="form-control" type="text" th:value="*{tagCode}" readonly>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">EPC编码：</label>
                <div class="col-sm-8">
                    <input class="form-control" type="text" th:value="*{epcCode}" readonly>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">资产编码：</label>
                <div class="col-sm-8">
                    <div class="input-group">
                        <input id="assetCode" name="assetCode" class="form-control" type="text"
                               placeholder="请选择待绑定资产" readonly required>
                        <span class="input-group-btn">
                            <button type="button" class="btn btn-primary" onclick="selectAsset()">
                                <i class="fa fa-search"></i> 选择
                            </button>
                        </span>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">资产名称：</label>
                <div class="col-sm-8">
                    <input id="assetName" class="form-control" type="text" readonly>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">资产状态：</label>
                <div class="col-sm-8">
                    <input id="assetStatusName" class="form-control" type="text" readonly>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">仓库 / 位置：</label>
                <div class="col-sm-8">
                    <input id="assetLocation" class="form-control" type="text" readonly>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <textarea name="remark" maxlength="500" class="form-control" rows="3"></textarea>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var prefix = ctx + "asset/tag";
        var assetStatusDatas = [[${@dict.getType('ams_asset_status')}]];

        $("#form-tag-bind").validate({
            focusCleanup: true
        });

        function selectAsset() {
            var options = {
                title: "选择待绑定资产",
                url: prefix + "/selectAsset",
                width: "1100",
                height: "650",
                callBack: setSelectedAsset
            };
            $.modal.openOptions(options);
        }

        function setSelectedAsset(index, layero) {
            var selectedAsset = layero.find("iframe")[0].contentWindow.getSelectedAsset();
            if (!selectedAsset) {
                $.modal.alertWarning("请选择一条资产记录");
                return;
            }
            $("#assetCode").val(selectedAsset.assetCode);
            $("#assetName").val(selectedAsset.assetName);
            $("#assetStatusName").val($.table.selectDictLabel(assetStatusDatas, selectedAsset.assetStatus));
            $("#assetLocation").val((selectedAsset.warehouseName || "-") + " / " + (selectedAsset.locationName || "-"));
            $.modal.close(index);
        }

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/bind", $("#form-tag-bind").serialize());
            }
        }
    </script>
</body>
</html>
