<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('移库任务列表')"/>
    <link th:href="@{/ruoyi/css/ry-ui-custom.css?v=4.7.3}" rel="stylesheet"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row" style="height: auto !important;">
        <div class="col-sm-12 pr0 pl0 shadow">
            <div class="ibox float-e-margins ">
                <div class="ibox-title">
                    <div class="col-sm-8  pl0 pr0">
                        <h8>移库任务列表</h8>
                    </div>
                </div>
                <div class="ibox-content ibox-content-1" style="margin: 0; height: 350px">
                    <div class="btn-group-sm" id="toolbar" role="group">
                        <form id="formId">
                            <div class="select-list">
                                <ul>
                                    <li>
                                        <label>托盘号：</label>
                                        <input type="text" name="vehicleId"/>
                                    </li>
                                    <li>
                                        <a class="btn btn-primary btn-rounded btn-sm"
                                           onclick="$.table.search('formId')"><i
                                                class="fa fa-search"></i>&nbsp;搜索</a>
                                        <a class="btn btn-warning btn-rounded btn-sm"
                                           onclick="$.form.reset('formId')"><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" data-resizable="true"></table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var prefix = ctx + "business/taskMonitor/moveTask";

    /**
     * 表格初始化
     */
    $(function () {
        var options = {
            url: prefix + "/list",
            modalName: "移库任务列表",
            showSearch: false,
            showToggle: false,
            showRefresh: false,
            showColumns: false,
            search: false,
            columns: [
                {
                    field: 'taskId',
                    title: '任务id',
                    formatter: function (value, row, index) {
                        return $.table.tooltip(value, 8);
                    }
                },
                {
                    field: 'taskType',
                    title: '任务类型',
                    formatter: function (value, row, index) {
                        return value == "1" ? "移库" : "其他";
                    }
                },
                {
                    field: 'taskStatus',
                    title: '任务状态',
                    formatter: function (value, row, index) {
                        if (value == "0") {
                            return "待执行"
                        } else if (value == "1") {
                            return "执行中"
                        } else if (value == "2") {
                            return "已完成"
                        }
                        return "异常状态"
                    }
                },
                {
                    field: 'vehicleId',
                    title: '托盘号'
                },
                {
                    field: 'isCrossTunnel',
                    title: '跨巷道',
                    formatter: function (value, row, index) {
                        return value == "1" ? "是" : "否";
                    }
                },
                {
                    field: 'origin',
                    title: '起始库位'
                },
                {
                    field: 'destination',
                    title: '目标库位'
                },
                {
                    field: 'plcId',
                    title: 'plc任务号'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        if (row.taskStatus != "2") {
                            if (row.taskStatus != "0") {
                                actions.push('<button id="restart" class="btn btn-default btn-xs" onclick="changeMoveTask(\'' + row.taskId + '\', ' + 0 + ')">重置</button>');
                            }
                            actions.push('<button id="cancel" class="btn btn-default btn-xs" onclick="changeMoveTask(\'' + row.taskId + '\', ' + 9 + ')">取消</button>');
                            actions.push('<button id="finish" class="btn btn-default btn-xs" onclick="changeMoveTask(\'' + row.taskId + '\', ' + 2 + ')">完成</button>');
                        }

                        return actions.join('');
                    }
                },
            ]
        };
        $.table.init(options);
    });

    // 删除任务
    function changeMoveTask(taskId, taskStatus) {
        $.ajax({
            type: "post",
            url: prefix + "/changeMoveTask",
            data: {
                "taskId": taskId,
                "taskStatus": taskStatus
            },
            success: function (data) {
                if (data.code == 0) {
                    $.modal.msgSuccess(data.msg)
                } else {
                    $.modal.msgError(data.msg)
                }
                $.table.search('formId');
            },
            error: function () {
                $.modal.msgError('发生错误')
                $.table.search('formId');
            }
        });
    }
</script>
</body>
</html>
<style>
    .inner_row_style {
        margin-left: 0px;
        margin-right: 0px;
        padding-top: 5px;
    }
</style>