<!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="@{/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-10  pl0 pr0">
                        <h8>货位库存表</h8>
                    </div>
                </div>
                <div class="ibox-content ibox-content-1" style="margin: 0; height: 200px">
                    <div class="btn-group-sm" id="toolbar" role="group">
                        <form id="formId">
                            <div class="select-list">
                                <ul>
                                    <li>
                                        <label>库位：</label>
                                        <input type="text" name="locationId"/>
                                    </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"></table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var prefix = ctx + "business/stockReport";

    /**
     * 表格初始化
     */
    $(function () {
        var options = {
            url: prefix + "/list",
            modalName: "库存表",
            showSearch: false,
            showToggle: false,
            showRefresh: false,
            showColumns: true,
            search: false,
            columns: [
                {
                    field: 'goodsId',
                    title: '物料编码',
                    sortable: true
                },
                {
                    field: 'goodsName',
                    title: '物料描述',
                    sortable: true,
                    formatter: function (value, row, index) {
                        return $.table.tooltip(value);
                    }
                },
                {
                    field: 'produclotid',
                    title: '批次',
                    sortable: true
                },
                {
                    field: 'productionDate',
                    title: '生产日期',
                    sortable: true
                },
                {
                    field: 'expirationDate',
                    title: '有效日期',
                    sortable: true
                },
                {
                    field: 'shelvesNum',
                    title: '数量',
                    sortable: true
                },
                {
                    field: 'ctl',
                    title: '托盘号',
                    sortable: true
                },
                {
                    field: 'locationId',
                    title: '库位',
                    sortable: true
                },
                {
                    field: 'providerId',
                    title: '供应商编码',
                    sortable: true
                },
                {
                    field: 'sts',
                    title: '状态',
                    formatter: function (value, row, index) {
                        if (value == "0") {// 合格品
                            return "合格"
                        } else if (value == "1") {// 不合格品
                            return "不合格"
                        } else if (value == "2") {// 延期
                            return "延期"
                        } else if (value == "3") {// 报废
                            return "报废"
                        } else if (value == "4") {// 锁定
                            return "锁定"
                        } else if (value == "5") {// 待检
                            return "待检"
                        }
                    },
                    sortable: true
                },
                {
                    title: '操作',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<button id="moveop" class="btn btn-warning btn-xs" onclick="moveStock(\'' + row.ctl + '\', \'' + row.locationId + '\')">移库</button>');
                        return actions.join('');
                    },
                    align: 'center'
                }
            ]
        };
        $.table.init(options);
    });

    /**
     * 更改库存状态
     */
    function moveStock(ctl, locationId) {
        console.log(ctl + "," + locationId);
        let stock = encodeURIComponent(JSON.stringify({
            "ctl": ctl,
            "locationId": locationId
        }));
        var options = {
            width: '400',
            height: '350',
            title: '选择新库位',
            url: prefix + "/selDestinationLocation/" + stock,
            callBack: doSubmit
        };
        $.modal.openOptions(options);
    }

    function doSubmit(index, layero){
        var body = $.modal.getChildFrame(index);
        var vehicleId = body.find('#vehicleId').val();
        var origin = body.find("#origin").val();
        var destination = body.find("#destination").val();
        const requestData = {
            "vehicleId": vehicleId,
            "origin": origin,
            "destination": destination
        }
        $.ajax({
            type: "post",
            url: prefix + "/generateMoveTask",
            data: requestData,
            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');
            }
        });
        $.modal.close(index);
    }
</script>
</body>
</html>
<style>
    .inner_row_style {
        margin-left: 0px;
        margin-right: 0px;
        padding-top: 5px;
    }
</style>