<!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('托盘管理列表')" />
</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="rfidNum"/>
                            </li>
                            <li>
                                <label>使用状态：</label>
                                <select name="usedFlag" th:with="type=${@dict.getType('palletUseflag')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </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>
                                <a class="btn btn-success btn-rounded btn-sm" onclick="$.operate.add()" shiro:hasPermission="nanjing:WorkTrayRealTimeInfo:add"><i class="fa fa-plus"></i> 添加</a>
<!--                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.table.exportExcel()" shiro:hasPermission="nanjing:WorkTrayRealTimeInfo:export"><i class="fa fa-download"></i> 导出</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 editFlag = [[${@permission.hasPermi('nanjing:WorkTrayRealTimeInfo:edit')}]];
        var removeFlag = [[${@permission.hasPermi('nanjing:WorkTrayRealTimeInfo:remove')}]];
        var stateDatas = [[${@dict.getType('palletState')}]];
        var usedFlagDatas = [[${@dict.getType('palletUseflag')}]];
        var prefix = ctx + "nanjing/WorkTrayRealTimeInfo";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "托盘管理",
                columns: [
                {
                    field: 'rfidNum',
                    title: '托盘条码'
                },
                    {
                        field: 'insertTime',
                        title: '添加时间'
                    },
                    {
                        field: 'deleteTime',
                        title: '停用时间'
                    },
                {
                    field: 'usedFlag',
                    title: '使用状态',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(usedFlagDatas, value);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="startUse(\'' + row.rfidNum + '\')"><i class="fa fa-edit"></i>启用</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="endUse(\'' + row.rfidNum + '\')"><i class="fa fa-remove"></i>停用</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        function startUse(rfidNum) {
            var formData = new FormData();
            formData.append("rfidNum",rfidNum);
            $.ajax({
                type: "post",
                url: prefix+"/start",
                data: formData,
                contentType: false,
                processData: false,
                dataType: "json",
                success: function (result) {
                    console.log(result.msg);
                    if (result.code == web_status.SUCCESS){
                        alert(result.msg);
                        $.table.refresh();
                    }else{
                        alert(result.msg);
                    }
                }
            })
        }

        function endUse(rfidNum) {
            var formData = new FormData();
            formData.append("rfidNum",rfidNum);
            $.ajax({
                type: "post",
                url: prefix+"/end",
                data: formData,
                contentType: false,
                processData: false,
                dataType: "json",
                success: function (result) {
                    console.log(result.msg);
                    if (result.code == web_status.SUCCESS){
                        alert(result.msg);
                        $.table.refresh();
                    }else{
                        alert(result.msg);
                    }
                }
            })
        }
    </script>
</body>
</html>