<!DOCTYPE html>
<html>
<meta charset="UTF-8">
<link rel="stylesheet" href="/lib/app/css/app.min.css">
<link rel="stylesheet" href="/lib/simple-line-icons/css/simple-line-icons.css">
<link rel="stylesheet" href="/lib/bootable/bootstrap-table.css">
<link rel="stylesheet" href="/lib/webo/css/ui.css">
<link rel="stylesheet" href="/lib/toastr/toastr.css">
<link rel="stylesheet" href="/static/css/top_page.css">
<body>
<div class="app app-header-fixed app-aside-fixed">
    <header id="header" class="app-header navbar" role="menu">
        {{template "com/purchasetop.tpl" .}}
    </header>

    <div class="row">
        <div class="col-md-10" style="padding-left: 30px">
                <a id="" href="/purchase/ui/print" class="btn btn-primary">同意</a>
                <a id="return" class="btn btn-default" href="javascript:history.go(-1)">取消</a>
        </div>
        <div>
            <ul class="nav navbar-nav active">
                <li class="dropdown">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown"><i class="fa fa-filter"></i>筛选<span class="caret"></span></a>
                    <ul class="dropdown-menu" role="menu">
                        <li><a href="#" data-tab="tab-chrome">任务管理</a></li>
                        <li><a href="#" data-tab="tab-firefox">信息管理</a></li>
                        <li><a href="#" data-tab="tab-safari">工时管理</a></li>
                        <li><a href="#" data-tab="tab-opera">合同管理</a></li>
                        <li><a href="#" data-tab="tab-ie">产品管理</a></li>
                    </ul>
                </li>
                <li class="dropdown">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown"><i class="fa fa-bars"></i>分组<span class="caret"></span></a>
                    <ul class="dropdown-menu" role="menu">
                        <li><a href="#" data-tab="tab-chrome">任务管理</a></li>
                        <li><a href="#" data-tab="tab-firefox">信息管理</a></li>
                        <li><a href="#" data-tab="tab-safari">工时管理</a></li>
                        <li><a href="#" data-tab="tab-opera">合同管理</a></li>
                        <li><a href="#" data-tab="tab-ie">产品管理</a></li>
                    </ul>
                </li>
                <li class="dropdown">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown"><i class="fa fa-star"></i>收藏<span class="caret"></span></a>
                    <ul class="dropdown-menu" role="menu">
                        <li><a href="#" data-tab="tab-chrome">任务管理</a></li>
                        <li><a href="#" data-tab="tab-firefox">信息管理</a></li>
                        <li><a href="#" data-tab="tab-safari">工时管理</a></li>
                        <li><a href="#" data-tab="tab-opera">合同管理</a></li>
                        <li><a href="#" data-tab="tab-ie">产品管理</a></li>
                    </ul>
                </li>

            </ul>
        </div>
        <div>


        <div>
            <table id="item_table"
                   data-show-refresh="false"
                   data-show-columns="false"
                   data-show-export="false"
                   data-search="false"
                   data-page-size="100"
                   data-row-style="rowStyleOvertime"
                   data-filter-control="false"
                   data-query-params="queryParams"
                   data-show-footer="false"
                   data-toolbar=".toolbar">
                <thead>
                <tr>
                    <th data-field="action"
                        data-align="center"
                        data-formatter="actionFormatter"
                        data-events="actionEvents"
                        data-sortable="false"
                        data-width="10px"> [ 操作 ]
                    </th>
                    <th data-field="state" data-checkbox="true" data-sortable="false" width="15px;"></th>
                    <th data-field="number" data-filter-control="input" >编号</th>
                    <th data-field="buyersn" data-filter-control="input">供应商</th>
                    <th data-field="product" data-filter-control="input">产品</th>
                    <th data-field="unit" data-filter-control="input">单位</th>
                    <th data-field="num" data-filter-control="input">数量</th>
                    <th data-field="requisitioner" data-filter-control="input" data-extend-label="name">请购人</th>
                    <th data-field="purchaser" data-filter-control="input" data-extend-label="name">采购员</th>
                    <th data-field="bill" data-filter-control="input">源单据</th>
                    <th data-field="status" data-filter-control="input">状态</th>
                </tr>
                </thead>
            </table>
        </div>
    </div>
<div id="RejectModel" class="modal fade">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">拒绝</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal padder-md" id="AgreeForm" enctype="multipart/form-data">
                    <div class="form-group">
                        <label class="col-sm-3 control-label">拒绝原因</label>
                        <div class="col-sm-7">
                            <textarea class="form-control" class="input-block-level form-control"
                                      name="rejectson" id="rejectson" autocomplete="off" ></textarea>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button id="btnReject" type="button" class="btn btn-primary">确定</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div>
    </div>
</div>
<script src="/lib/app/js/app.min.js"></script>
<script src="/lib/bootable/bootstrap-table.js"></script>
<script src="/lib/webo/js/ui.js"></script>
<script src="/lib/toastr/toastr.js"></script>
<script src="/lib/jquery/jquery/validate/jquery.metadata.js"></script>
<script src="/lib/jquery/jquery/jquery.form.js"></script>
<script src="/lib/jquery/jquery-ui/jquery-ui.min.js"></script>
<script src="/lib/webo/js/validate.js"></script>
<script>
    var $table = $("#item_table");
    $(function () {
        $table.bootstrapTable({
            url: "/item/list/purchase",
            method: "post",
            sidePagination: "server",
            pagination: true,
            height: getTableHeight(),
            fixedColumns: true,
            fixedNumber: 1
        });
        $(window).resize(function () {
            $table.bootstrapTable('resetView', {
                height: getTableHeight()
            });
        });
    });
    function getTableHeight() {
        return 800;
    }
    function refreshContent(options) {
        $table.bootstrapTable("refresh")
    }
    function actionFormatter(value, row) {
        str ='<a class ="approval text-primary" href="javascript:" title="同意" style="margin-right: 5px;">同意</a>'+
            '<a class ="reject text-primary" href="javascript:" title="拒绝" style="margin-right: 5px;">拒绝</a>';
        return str
    }

    let oldChecks = [];
    function stateFormatter(value, row) {
        if ($.inArray(row.sn, oldChecks) !== -1) {
            return {
                checked: true
            }
        }
    }

    $(function () {
        $("#app_item").on("click", function () {
            let sels = $table.bootstrapTable('getAllSelections');
            if (sels.length <= 0) {
                toastr.error("请至少选择一个")
                return;
            }
            let sns = []
            for (let i = 0; i < sels.length; i++) {
                sns.push(sels[i].sn);
            }
            $.ajax({
                url: "",
                type: 'post',
                data: {
                    "sn": sns.join(","),
                },
                success: function () {
                    toastr.success("一键同意操作成功!")
                },
                error: function () {
                    toastr.error("一键同意操作失败!")
                }
            })
        });
    })

    window.actionEvents = {
        'click .approval': function (e, value, row) {
            $.ajax({
                url:"",
                type:"post",
                data: {

                },
                success:function () {
                    toastr.success("审核通过")
                },
                error:function () {
                    toastr.error("审核失败")
                }
            })
        },
        'click .reject': function (e, value, row) {
            $('#RejectModel').modal({backdrop:"static"});
            $("#btnReject").off("click").on("click", function () {
                var rejectson =$("#rejectson").val()
                $.ajax({
                    url:"/item/update/purchase",
                    type:"post",
                    data:{
                        sn:row.sn,
                        "rejectson":rejectson
                    },
                    success: function () {
                        $('#RejectModel').modal("hide");
                        $table.bootstrapTable("refresh")
                    }
                })
            })
        }
    }



</script>
</body>
</html>