<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('选择可退库资产')" />
</head>
<body class="gray-bg">
    <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list"><ul>
                        <li><label>资产编码：</label><input type="text" name="assetCode"></li>
                        <li><label>资产名称：</label><input type="text" name="assetName"></li>
                        <li><label>资产类别：</label><input type="text" name="categoryName"></li>
                        <li>
                            <label>使用部门：</label>
                            <select name="useDeptId">
                                <option value="">所有</option>
                                <option th:each="dept : ${deptList}" th:value="${dept.deptId}" th:text="${dept.deptName}"></option>
                            </select>
                        </li>
                        <li><label>使用人：</label><input type="text" name="useUserName"></li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul></div>
                </form>
            </div>
            <div class="col-sm-12 select-table table-striped"><table id="bootstrap-table"></table></div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var prefix = ctx + "asset/return";
        var orderId = [[${orderId}]];
        var originWarehouseId = [[${originWarehouseId}]];
        var missingOriginOnly = [[${missingOriginOnly}]];
        $(function() {
            var url = prefix + "/availableAssetList";
            var params = [];
            if (orderId) { params.push("orderId=" + orderId); }
            if (originWarehouseId) { params.push("originWarehouseId=" + originWarehouseId); }
            if (missingOriginOnly) { params.push("missingOriginOnly=true"); }
            if (params.length > 0) { url += "?" + params.join("&"); }
            $.table.init({
                url: url,
                showSearch: false,
                showRefresh: true,
                showToggle: false,
                showColumns: false,
                modalName: "可退库资产",
                columns: [
                    { checkbox: true },
                    { field: "assetCode", title: "资产编码" },
                    { field: "assetName", title: "资产名称" },
                    { field: "categoryName", title: "资产类别" },
                    { field: "originWarehouseName", title: "领用前仓库", formatter: function(value, row) { return originText(value, row.originWarehouseEnabled); } },
                    { field: "originLocationName", title: "领用前位置", formatter: function(value, row) { return originText(value, row.originLocationEnabled); } },
                    { field: "useDeptName", title: "当前使用部门" },
                    { field: "useUserName", title: "当前使用人" }
                ]
            });
        });
        function getSelectedAssets() { return $("#bootstrap-table").bootstrapTable("getSelections"); }
        function originText(value, enabled) {
            if (!value) { return "无可追溯来源"; }
            return value + (enabled === "Y" ? "" : "（已停用）");
        }
    </script>
</body>
</html>
