<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('资产台账列表')" />
    <th:block th:include="include :: select2-css" />
</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>
                                <select name="categoryId" class="select2-control" style="width: 170px">
                                    <option value="">所有</option>
                                    <option th:each="category : ${categoryList}" th:text="${category.categoryName}" th:value="${category.categoryId}"></option>
                                </select>
                            </li>
                            <li>
                                <label>所属仓库：</label>
                                <select id="searchWarehouseId" name="warehouseId" class="select2-control" style="width: 170px">
                                    <option value="">所有</option>
                                    <option th:each="warehouse : ${warehouseList}" th:text="${warehouse.warehouseName}" th:value="${warehouse.warehouseId}"></option>
                                </select>
                            </li>
                            <li>
                                <label>存放位置：</label>
                                <select id="searchLocationId" name="locationId" class="select2-control" style="width: 170px">
                                    <option value="">所有</option>
                                    <option th:each="location : ${locationList}" th:text="${location.locationName}" th:value="${location.locationId}" th:data-warehouse-id="${location.warehouseId}"></option>
                                </select>
                            </li>
                            <li>
                                <label>使用部门：</label>
                                <select name="useDeptId" class="select2-control" style="width: 170px">
                                    <option value="">所有</option>
                                    <option th:each="dept : ${deptList}" th:text="${dept.deptName}" th:value="${dept.deptId}"></option>
                                </select>
                            </li>
                            <li>
                                <label>使用人：</label>
                                <select name="useUserId" class="select2-control" style="width: 170px">
                                    <option value="">所有</option>
                                    <option th:each="user : ${userList}" th:text="${user.userName + '（' + user.loginName + '）'}" th:value="${user.userId}"></option>
                                </select>
                            </li>
                            <li>
                                <label>资产状态：</label>
                                <select name="assetStatus" th:with="type=${@dict.getType('ams_asset_status')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li class="select-time">
                                <label>下次维保日期：</label>
                                <input type="text" class="time-input" id="beginNextMaintenanceDate" placeholder="开始日期" name="params[beginNextMaintenanceDate]"/>
                                <span>-</span>
                                <input type="text" class="time-input" id="endNextMaintenanceDate" placeholder="结束日期" name="params[endNextMaintenanceDate]"/>
                            </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="resetSearch()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="asset:asset:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="asset:asset:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="asset:asset:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-info" onclick="$.table.importExcel()" shiro:hasPermission="asset:asset:import">
                    <i class="fa fa-upload"></i> 导入
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="asset:asset:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: select2-js" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('asset:asset:edit')}]];
        var removeFlag = [[${@permission.hasPermi('asset:asset:remove')}]];
        var assetStatusDatas = [[${@dict.getType('ams_asset_status')}]];
        var prefix = ctx + "asset/asset";

        $(function() {
            $(".select2-control").select2({
                placeholder: "请选择",
                allowClear: true
            });
            $("#searchWarehouseId").on("change", refreshSearchLocationOptions);
            refreshSearchLocationOptions();

            var options = {
                url: prefix + "/list",
                viewUrl: prefix + "/view/{id}",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                importUrl: prefix + "/importData",
                importTemplateUrl: prefix + "/importTemplate",
                modalName: "资产台账",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'assetId',
                    title: '资产ID',
                    visible: false
                },
                {
                    field: 'assetCode',
                    title: '资产编码'
                },
                {
                    field: 'assetName',
                    title: '资产名称'
                },
                {
                    field: 'categoryName',
                    title: '资产类别'
                },
                {
                    field: 'specModel',
                    title: '规格型号'
                },
                {
                    field: 'brand',
                    title: '品牌'
                },
                {
                    field: 'warehouseName',
                    title: '所属仓库'
                },
                {
                    field: 'locationName',
                    title: '存放位置'
                },
                {
                    field: 'useDeptName',
                    title: '使用部门'
                },
                {
                    field: 'useUserName',
                    title: '使用人'
                },
                {
                    field: 'custodianName',
                    title: '保管人'
                },
                {
                    field: 'purchaseDate',
                    title: '购置日期'
                },
                {
                    field: 'originalValue',
                    title: '资产原值'
                },
                {
                    field: 'nextMaintenanceDate',
                    title: '下次维保日期'
                },
                {
                    field: 'assetStatus',
                    title: '资产状态',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(assetStatusDatas, value);
                    }
                },
                {
                    field: 'tagCode',
                    title: '当前标签编码'
                },
                {
                    field: 'epcCode',
                    title: '当前绑定EPC'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-info btn-xs" href="javascript:void(0)" onclick="$.operate.view(\'' + row.assetId + '\')"><i class="fa fa-eye"></i>查看</a> ');
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.assetId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.assetId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        function refreshSearchLocationOptions() {
            var warehouseId = $("#searchWarehouseId").val();
            var $location = $("#searchLocationId");
            $location.find("option[data-warehouse-id]").each(function() {
                var matched = !warehouseId || String($(this).data("warehouse-id")) === String(warehouseId);
                $(this).prop("disabled", !matched);
            });
            if ($location.find("option:selected").prop("disabled")) {
                $location.val("").trigger("change");
            }
        }

        function resetSearch() {
            $.form.reset();
            $(".select2-control").val("").trigger("change");
            refreshSearchLocationOptions();
        }
    </script>
</body>
<!-- 导入区域 -->
<script id="importTpl" type="text/template">
<form enctype="multipart/form-data" class="mt20 mb10">
    <div class="col-xs-offset-1">
        <input type="file" id="file" name="file"/>
        <div class="mt10 pt5">
            资产编码已存在时导入失败，不覆盖已有资产。
            &nbsp; <a onclick="$.table.importTemplate()" class="btn btn-default btn-xs"><i class="fa fa-file-excel-o"></i> 下载模板</a>
        </div>
        <font color="red" class="pull-left mt10">
            提示：仅允许导入“xls”或“xlsx”格式文件！
        </font>
    </div>
</form>
</script>
</html>
