<!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('工单管理')"/>
<!--    <link th:href="~/Content/bootstrap-table/extensions/reorder-rows/bootstrap-table-reorder-rows.css" rel="stylesheet" />-->
</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>
                            <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-primary multiple disabled" onclick="cancelOrder()" shiro:hasPermission="business:orderTaskManage:cancel">
                <i class="fa fa-edit"></i> 工单取消
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<div th:include="include :: footer"></div>
<!--<th:block th:include="include :: bootstrap-table-reorder-rows-js"></th:block>-->
<script th:inline="javascript">
    var prefix = ctx + "business/mesManage/orderTaskManage";

    $(function () {
        var options = {
            url: prefix + "/main",
            showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            fixedColumns: true,
            fixedNumber: 3,
            columns: [{
                checkbox: true
            },
                {
                    field: 'orderId',
                    title: '工单号',
                    sortable: true
                },
                {
                    field: 'goodsId',
                    title: '物料编码',
                    sortable: true
                },
                {
                    field: 'needNum',
                    title: '需求数量',
                    sortable: true
                },
                {
                    field: 'finishNum',
                    title: '已发数量',
                    sortable: true
                },
                {
                    field: 'waitNum',
                    title: '待发数量',
                    sortable: true
                },
                {
                    field: 'actualNum',
                    title: '实发数量',
                    sortable: true
                },
                {
                    field: 'status',
                    title: '状态',
                    formatter: function(value, row, index) {
                        if (value == "1") {
                            return "已下发"
                        } else if (value == "0") {
                            return "待下发"
                        }
                    }
                },
                {
                    field: 'updateTime',
                    title: '时间',
                    sortable: true
                },
                {
                    title: '排序',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<button id="scan" class="btn btn-warning btn-xs" onclick="upOneOrder(\'' + row.orderId + '\', ' + row.goodsId + ')">上移一位</button>');
                        return actions.join('');
                    },
                    align: 'center'
                }
            ]
        };
        $.table.init(options);
    });

    // 工单取消
    function cancelOrder() {
        var rows = $.table.selectColumns("orderId");
        if (rows.length == 0) {
            $.modal.alertWarning("请至少选择一条记录");
            return;
        }
        var url = prefix + "/cancelOrder";
        var data = { "orderIds": rows.join() };
        $.operate.post(url, data, function (res) {
            if (res.code == "0") {
                $.modal.msgSuccess('工单已取消')
            } else {
                $.modal.msgError('取消失败，可能数据库连接错误')
            }
            $.table.refresh();
        });
    }

    // 排序，上移一位
    function upOneOrder(orderId, goodsId) {
        console.log(orderId)
        $.ajax({
            type: "post",
            url: prefix + "/reorder",
            data: {
                "orderId": orderId,
                "goodsId": goodsId
            },
            success: function (data) {
                console.log(data)
                if (data.code == 0) {
                    if (data.msg == "1") {
                        $.modal.msgSuccess('更改顺序成功')
                        $.table.refresh();
                    } else {
                        $.modal.msgError('错误')
                    }
                } else {
                    $.modal.msgError('错误')
                }
            },
            error: function () {
                $.modal.msgError('错误')
            }
        });
    }
</script>
</body>
</html>