<!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('载具A')"/>
</head>
<body class="gray-bg">
<input type="hidden" id="rowIds">
<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="orderId"/>
                        </li>
                        <li>
                            <label>状态：</label>
                            <input type="text" name="status"/>
                        </li>
                        <li>
                            载具入库时间：
                            <input type="text" id="startDate" name="startDate" class="time-input"
                                   placeholder="开始时间">
                            --
                            <input type="text" id="endDate" name="endDate" class="time-input"
                                   placeholder="结束时间">
                        </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="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success single disabled" onclick="callAgvOut()">
                <i class="fa fa-plus"></i> 呼叫AGV工单出库
            </a>
            <a class="btn btn-primary" onclick="callAgvTakeEmpty()">
                <i class="fa fa-edit"></i> 呼叫AGV取空载具
            </a>
            <a class="btn btn-danger single disabled" onclick="stsOut()">
                <i class="fa fa-check"></i> 已出库
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()">
                <i class="fa fa-download"></i> 导出
            </a>
            <label class="toggle-switch switch-solid">
                是否启用
                <input type="checkbox" th:value="${switchA}"
                       th:checked="${switchA == '1' ? true : false}"
                       onchange="makeOn()" shiro:hasPermission="business:orderTaskManage:cancel">
                <span></span>
            </label>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
    var prefix = ctx + "business/mesManage/vehicleA";

    $(function () {
        var options = {
            url: prefix + "/vehicleInfo",
            showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            fixedColumns: true,
            fixedNumber: 3,
            columns: [{
                checkbox: true
                },
                {
                    field: 'vehicleId',
                    title: '载具编码',
                    sortable: true
                },
                {
                    field: 'orderId',
                    title: '工单号',
                    sortable: true
                },
                {
                    field: 'finishNum',
                    title: '已出数量',
                    sortable: true
                },
                {
                    field: 'vehicleInTime',
                    title: '载具入库时间',
                    sortable: true
                },
                {
                    field: 'vehicleOutTime',
                    title: '出库时间',
                    sortable: true
                },
                {
                    field: 'status',
                    title: '状态',
                    formatter: function(value, row, index) {
                        if (value == "1") {
                            return "已出库"
                        } else {
                            return "排队中"
                        }
                    }
                }
            ]
        };
        $.table.init(options);
    });

    // 呼叫AGV工单出库
    function callAgvOut() {
        var url = prefix + "/callAgvOut";
        var data = { "vehicleIds": rows.join() };
        $.operate.post(url, data, function (res) {
            if (res.code == "0") {
                $.modal.msgSuccess('状态已更新')
            } else {
                $.modal.msgError('状态更新错误')
            }
            $.table.refresh();
        });
    }

    // 呼叫agv取空托盘
    function callAgvTakeEmpty() {
        var url = prefix + "/callAgvTakeEmpty";
        var data = { "vehicleIds": rows.join() };
        $.operate.post(url, data, function (res) {
            if (res.code == "0") {
                $.modal.msgSuccess('状态已更新')
            } else {
                $.modal.msgError('状态更新错误')
            }
            $.table.refresh();
        });
    }

    // 改变当前工单状态为已出库
    function stsOut() {
        var rows = $.table.selectColumns("vehicleId");
        if (rows.length == 0) {
            $.modal.alertWarning("请至少选择一条记录");
            return;
        }
        var url = prefix + "/checkOut";
        var data = { "vehicleIds": rows.join() };
        $.operate.post(url, data, function (res) {
            if (res.code == "0") {
                $.modal.msgSuccess('状态已更新')
            } else {
                $.modal.msgError('状态更新错误')
            }
            $.table.refresh();
        });
    }
    
    function makeOn() {
        $.ajax({
            type: "post",
            url: prefix + "/vehicleA/makeOn",
            success: function (data) {
                console.log(data)
                if (data.code == 0) {
                    $.modal.msgSuccess(data.msg)
                } else {
                    $.modal.msgError('失败')
                }
            },
            error: function () {
                $.modal.msgError('错误')
            }
        });
    }
</script>
</body>
</html>