<!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="col-sm-12 search-collapse" style="margin-bottom: -30px">
                        <form id="formId">
                            <div class="select-list">
                                <ul>
                                    <li>
                                        <label>物料编码：</label>
                                        <input type="text" name="goodsId"/>
                                    </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>
                        <a class="btn btn-danger single disabled" onclick="stsOut()">
                            <i class="fa fa-check"></i>设为合格
                        </a>
                    </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 editFlag = [[${@permission.hasPermi('business:onlineInspection:edit')}]];
    var prefix = ctx + "business/comingInspection";
    var statusDatas = [[${@dict.getType('stock_sts')}]];

    /**
     * 表格初始化
     */
    $(function () {
        var options = {
            url: prefix + "/list",
            modalName: "库存表",
            showSearch: false,
            showToggle: false,
            showRefresh: false,
            showColumns: false,
            search: false,
            // TODO
            columns: [
                {
                    checkbox: true
                },
                {
                    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: '当前位置',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value.substr(0, 2) + "排" + value.substr(2, 2) + "列" + value.substr(4, 2) + "层";
                        }
                    },
                    sortable: true
                },
                {
                    field: 'providerId',
                    title: '供应商编码',
                    sortable: true
                },
                {
                    field: 'sts',
                    title: '状态',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(statusDatas, value);
                    },
                    sortable: true
                }
            ]
        };
        $.table.init(options);
    });

    /**
     * 在线检验
     */
    function edit(goodsId, produclotid, ctl) {
        console.log(goodsId)
        console.log(produclotid)
        console.log(ctl)
        let data = encodeURIComponent(JSON.stringify({
            "goodsId": goodsId,
            "produclotid": produclotid,
            "ctl": ctl
        }));
        console.log(data)
        var options = {
            width: '500',
            height: '320',
            title: '在线不合格检验',
            url: prefix + "/edit/" + data,
            callBack: doSubmit
        };
        $.modal.openOptions(options);
    }

    function doSubmit(index, layero){
        var body = $.modal.getChildFrame(index);
        var mark = body.find('#mark').val();
        var goodsId = body.find('#goodsId').val();
        var produclotid = body.find('#produclotid').val();
        var ctl = body.find('#ctl').val();
        console.log(ctl)
        $.ajax({
            type: "post",
            url: prefix + "/update",
            data: {
                "goodsId": goodsId,
                "produclotid": produclotid,
                "ctl": ctl,
                "mark": mark
            },
            success: function (data) {
                console.log(data)
                $.table.search('formId');
            },
            error: function () {
                $.modal.msgError('状态更新错误')
                $.table.search('formId');
            }
        });
        $.modal.close(index);
    }

    // 更改当前来料状态为已检验
    function stsOut() {
        var rows = $.table.selectColumns("locationId");
        if (rows.length == 0) {
            $.modal.alertWarning("请至少选择一条记录");
            return;
        }
        var url = prefix + "/stsChange";
        var data = { "locationIds": rows.join() };
        $.operate.post(url, data, function (res) {
            if (res.code == "0") {
                $.modal.msgSuccess(res.msg)
            } else if (res.code = "500") {
                $.modal.msgError(res.msg)
            }
            $.table.refresh();
        });
    }
</script>
</body>
</html>
<style>
    .inner_row_style {
        margin-left: 0px;
        margin-right: 0px;
        padding-top: 5px;
    }
</style>