@{
    ViewData["Title"] = "配置物流供应商往来统计配置";
    Layout = "~/Pages/Shared/_MainLayout.cshtml";
}

<div class="row">
    <div class="col-sm-12">
        <div class="ibox-content m-b-sm border-bottom">
            <form id="toolbar">
                <div class="form-inline" style="line-height:40px;">
                    <div class="form-group">
                        <label>类型：</label>
                        <select id="type" name="type" class="form-control" style="width:150px">
                            <option value="1">需要合并的</option>
                            <option value="2">需删除不显示的</option>
                        </select>
                    </div>
                    <div class="form-group">
                        <label>供应商名称：</label>
                        <input type="text" class="form-control" id="supplier" name="supplier" style="width:180px;" placeholder="请输入供应商名称" />
                    </div>
                    <div class="form-group">
                        <button type="button" class="btn btn-primary" onclick="init();"><i class="fa fa-search"></i>&nbsp;查询</button>
                        <button type="button" class="btn btn-success" onclick="addparent();">新增合并供应商</button>
                        <button type="button" class="btn btn-warning" onclick="adddelete();">新增需删除供应商</button>
                    </div>
                </div>
            </form>
        </div>

        <div class="ibox-content m-b-sm border-bottom">
            <table id="roletable" style="table-layout:fixed;"></table>
        </div>
    </div>
</div>

@section scripts{

    <script src="~/css/Layer-2.1/extend/layer.ext.js"></script>
    <script type="text/javascript">
        var tb;
        $(document).ready(function () {
            init();
        })

        function init() {
            var columns = [
                { field: 'suppliername', title: '供应商名称', width: '180' },
                { field: 'parentsuppliername', title: '合并后的供应商名称', width: '180' },
                { field: 'type', title: '类型', width: '100'},
                { field: 'lastupdatetime', title: '更新时间', width: '130' },
                { field: 'lastupdateusername', title: '更新人名称', width: '130' },
                {
                    field: '', title: '操作', width: '100', formatter: function (v, rows) {
                        return '<a href="javascript:;" class="btn btn-sm btn-danger" onclick="del('+rows.id+')">删除</a>';
                    }
                }
            ];

            var url = '@Url.Content("~/Supplier/Home/ListLogisticsSupplierConfigJson")' + '?' + $("#toolbar").serialize();

            if (tb == undefined) {
                tb = OnlyTable("roletable", columns, url, "",);
            }
            else {
                tb.bootstrapTable('refresh', { url: url });
            }
        }

        function addparent() {
            layer_show('新增合并的供应商配置', '@Url.Content("~/Supplier/Home/AddLogisticsSupplierConfig")', '90%', '90%');
        }

        function Save() {
            var name = $('#suppliername').val();
            var parent = $('#supplierparent').val();

            if (name == '' || parent == '') {
                alert('供应商名称、合并后的供应商都不能为空');
                return;
            }

            $.submit({
                url: '@Url.Content("~/Supplier/Home/SetLogisticsSupplierConfigJson")',
                paramData: 'suppliername=' + name + '&supplierparent=' + parent+'&type=1',
                type:'POST',
                func: function (result) {
                    if (result.success) {
                        layer.msg('提交成功');
                    }
                    else {
                        layer.msg(result.msg);
                    }
                }
            })

        }

        function adddelete() {
            layer.prompt({ title: '新增需删除的供应商' }, function (value, index, elem) {
                if (value == '') {
                    alert('请输入供应商名称');
                    return;
                }

                $.submit({
                    url: '@Url.Content("~/Supplier/Home/SetLogisticsSupplierConfigJson")',
                    paramData: 'suppliername=' + value + '&supplierparent=&type=2',
                    type:'POST',
                    func: function (result) {
                        if (result.success) {
                            layer.msg('提交成功');
                            layer.close(index);
                        }
                        else {
                            layer.msg(result.msg);
                        }
                    }
                })


            });
        }

        function del(id) {
            $.submit({
                    url: '@Url.Content("~/Supplier/Home/DelLogisticsSupplierConfig")',
                    paramData: 'id=' + id,
                    type:'POST',
                    func: function (result) {
                        if (result.success) {
                            layer.msg('提交成功');

                            init();
                        }
                        else {
                            layer.msg(result.msg);
                        }
                    }
                })
        }

    </script>


}




