@{
    ViewBag.Title = "配货协议";
    Layout = "~/Views/Shared/_LayoutTable.cshtml";
}
<body>
    <div class="container-fluid">
        <div class="row-fluid">
            <div class="col-lg-4 col-md-4 col-sm-12" style="margin-top:5px">
                <table id="toptable" class="table table-bordered table-striped table-hover" style="overflow:scroll">
                    <tr>
                        <td style="text-align:right">客户名称:</td>
                        <td><input type="text" class="form-control" id="rsNum" value="" readonly="true" /></td>
                        <td>
                            <span onclick="ClientName()" class="glyphicon glyphicon-plus btn btn-default"></span>
                            <span class="glyphicon glyphicon-minus btn btn-default" onclick="Clear()"></span>
                        </td>
                    </tr>
                </table>
            </div>
            <div class="col-lg-4 col-md-4 col-sm-12" style="margin-top:5px">
                <table id="toptable" class="table table-bordered table-striped table-hover" style="overflow:scroll">
                    <tr>
                        <td style="text-align:right">生效时间:</td>
                        <td>
                            <input type="text" class="form-control" onfocus="WdatePicker({isShowClear:false,readOnly:true})" id="pmStartDate" value="@ViewBag.pmStartDate" />
                        </td>
                        <td>
                            <input type="text" class="form-control" onfocus="WdatePicker({isShowClear:false,readOnly:true})" id="pmEndDate" value="@ViewBag.pmEndDate" />
                        </td>
                    </tr>
                </table>
            </div>
            <div class="col-lg-4 col-md-4 col-sm-12" style="margin-top:5px">
                <table id="toptable" class="table table-bordered table-striped table-hover">
                    <tr>
                        <td style="text-align:right;height:55px">
                            <button class="btn btn-default" onclick="Search()"><i class="fa fa-search"></i> 查询</button>
                            <button class="btn btn-default" onclick="AddOrEditHttpBill('Add')"><i class="glyphicon glyphicon-plus"></i> 新增</button>
                        </td>
                    </tr>
                </table>
            </div>
            <div class="col-lg-12 col-md-12 col-sm-12">
                <table id="configurationTable"></table>
            </div>
        </div>
    </div>
    <input id="uploadliginid" type="hidden" />
    <input id="pagtype" type="hidden" />
    <input id="rowIndex" type="hidden" />
    <input id="ClientBtypeid" type="hidden" />
    <script type="text/javascript">
    $(function () {
        $("#pmStartDate").val($.GetToday());
        $("#pmEndDate").val($.GetToday())
        $('#configurationTable').bootstrapTable({
            url: "../Shop/GetHttpBillindex",         //请求后台的URL（*）
            method: 'post',                      //请求方式（*）
            toolbar: '#toolbar',                //工具按钮用哪个容器
            striped: true,                      //是否显示行间隔色
            pagination: true,                   //是否显示分页（*）
            sidePagination: "server",           //分页方式：client客户端分页，server服务端分页（*）
            pageNumber: 1,                       //初始化加载第一页，默认第一页
            pageSize: 15,                       //每页的记录行数（*）
            pageList: [15, 30, 50],        //可供选择的每页的行数（*）
            minimumCountColumns: 2,  //最少允许的列数
            //height: $(".centerdiv").height()-20,               //行高，如果没有设置height属性，表格自动根据记录条数觉得表格高度
            uniqueId: "btypeid",            //每一行的唯一标识，一般为主键列
            clickToSelect: true,              //是否启用点击选中行
            sortable: true,                     //是否启用排序
            silentSort: true,
            cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
            search: false,                       //是否显示表格搜索，此搜索是客户端搜索，不会进服务端，所以，个人感觉意义不大
            strictSearch: false,
            paginationFirstText: '首页',
            paginationLastText: '末页',
            paginationPreText: '上一页',
            paginationNextText: '下一页',
            showColumns: false,            //是否显示所有的列
            showRefresh: false,              //是否显示刷新按钮
            showToggle: false,                     //是否显示详细视图和列表视图的切换按钮
             cardView: false,                    //是否显示详细视图
            detailView: false,                   //是否显示父子表
            queryParams: function (params) {
                return {
                    pagesize: params.limit,//页面大小
                    page: params.offset, //页码
                    date: $("#pmStartDate").val(),
                    endate: $("#pmEndDate").val()
                };
            },//传递参数（*）
            columns: [
                {
                    field: 'index', title: '序号', formatter: function (value, row, index) {
                        return index + 1;
                    }
                },
                { field: 'Billhttpname', title: '协议名称', width: 160 },
                { field: 'UserCode', title: '客户编号', width: 260 },
                { field: 'FullName', title: '客户名称' },
                { field: 'BillDate', title: '生效时间' },
                { field: 'BillArriveDate', title: '失效时间' },
                {
                    field: 'isstop', title: '状态', formatter: function (value, row, index) {
                        if (value == "1") {
                            return "失效";
                        } else {
                            return "生效";
                        }
                    }
                },
                {
                    field: 'see', title: '查看', width: 60, formatter: function (value, row, index) {
                        return "<buttton class='btn btn-default' onclick='javascript:indexset(" + index + ")'><i class='glyphicon glyphicon-search'></i></buttton>"
                    }
                },
                {
                    field: 'edit', title: '编辑', width: 60, formatter: function (value, row, index) {
                        return "<buttton  class='btn btn-default' onclick='javascript:indexset("+index+")'><i class='glyphicon glyphicon-edit'></i></buttton>"
                    }
                },
                {
                    field: 'del', title: '删除', width: 60, formatter: function (value, row, index) {
                        return "<buttton  class='btn btn-default'><i class='glyphicon glyphicon-trash' style='color:red'></i></buttton>"
                    }
                },
                {
                    field: 'copy', title: '复制协议', width: 60, formatter: function (value, row, index) {
                        return "<buttton  class='btn btn-default'><i class='glyphicon glyphicon-copy'></i></buttton>"
                    }
                }, {
                    field: 'Nid', visible: false
                }
            ], onClickCell: function (field, value, row, td) {
                if (field == "edit") {
                    AddOrEditHttpBill("Edit");
                } else if (field == "see") {
                    layer.open({
                        type: 2,
                        title: '配货协议',
                        shadeClose: false,
                        shade: 0.5,
                        area: ['95%', '95%'],
                        content: '../Shop/HttpBillSee',
                        cancel: function (index) {
                            ClearHttp();
                            layer.close(index);
                            return false;
                        }
                    });
                } else if (field == "del") {
                    layer.confirm('确定删除?', { icon: 3, title: '提示' }, function (index) {
                        $.ajax({
                            url: "../Shop/DelHttpBill",
                            data: {
                                billNid: row["billid"]
                            },
                            datatype: "text",
                            type: "post",
                            async: false,
                            success: function (data) {
                                if (data == "ok") {
                                    $('#configurationTable').bootstrapTable("refresh")
                                }
                            }
                        });
                        layer.close(index);
                    });
                } else if (field == "copy") {
                    layer.open({
                        type: 2,
                        title: '复制协议 -> 当前权限用户协议(<span style="color:red">' + row["Billhttpname"] + '</span>)',
                        shadeClose: false,
                        shade: 0.5,
                        area: ['95%', '95%'],
                        content: '../CommonSelector/ClientSelectorMore',
                        end: function (index) {
                            if ($("#ClientBtypeid").val().trim()) {
                                $.ajax({
                                    url: "../Shop/CopyHttpbill",
                                    data: {
                                        btypeid: $("#ClientBtypeid").val(),
                                        billNid: row["billid"]
                                    },
                                    datatype: "text",
                                    type: "post",
                                    success: function (data) {
                                        if (data == "ok") {
                                            $("#ClientBtypeid").val("");
                                            $('#configurationTable').bootstrapTable("refresh")
                                        }
                                    }
                                })
                            }
                            layer.close(index);
                            return false;
                        }
                    });

                }
            }
        });
        $(window).resize(function () {
            $('#configurationTable').bootstrapTable('resetView');
        });
    });
    function indexset(index) {
        $("#rowIndex").val(index);
    }
    function Clear() {
        $("#rsNum").val("");
        $("#uploadliginid").val("");
    }
    /*选择客户*/
    function ClientName() {
        layer.open({
            type: 2,
            title: '客户信息',
            shadeClose: false,
            shade: 0.5,
            area: ['85%', '85%'],
            content: '../CommonSelector/ClientSelector'
        });
    }
    /*新增配货协议*/
    function AddOrEditHttpBill(type) {
        $("#pagtype").val(type);
        layer.open({
            type: 2,
            title: '配货协议',
            shadeClose: false,
            shade: 0.5,
            area: ['95%', '95%'],
            content: 'AddHttpBill',
            cancel: function (index) {
                layer.confirm("配货协议信息<span style='color:red;'>未保存</span>,确定关闭？", { titli: "提示"}, function (idx) {
                    ClearHttp();
                    layer.close(idx);
                    layer.close(index);
                })
                return false;
            }
        });
    }
    /*清空临时表*/
    function ClearHttp() {
        $.ajax({
            url: "../Shop/ClearHttpPromoPtype",
            data: {},
            datatype: "text",
            type: "post"
        })
    }
    /*查询*/
    function Search() {
        var uploadliginid = $("#uploadliginid").val();
        var stadate = $("#pmStartDate").val();
        var endate = $("#pmEndDate").val();
        $('#configurationTable').bootstrapTable("refresh", {
            url: "../Shop/GetHttpBillindex?btypeid=" + uploadliginid + "&date=" + stadate + "&endate=" + endate
        })
    }
    </script>
</body>
