@{
    ViewBag.Title = "拜访规划";
    Layout = "~/Views/Shared/_LayoutTable.cshtml";
}
<body>
    <div class="container-fluid">
        <div class="row-fluid" style="margin-top:15px;">
            <div class="col-lg-4 col-md-4 col-sm-4 col-xs-12">
                <div class="form-group">
                    <div class="form-inline">
                        <label>业务员:</label>
                        <select id="ddlSalesman">
                            <option value=""></option>
                            @{
                                if (@ViewBag.ulist != null && @ViewBag.ulist.Rows.Count > 0)
                                {
                                    for (int i = 0; i < @ViewBag.ulist.Rows.Count; i++)
                                    {
                                        <option @(@ViewBag.ulist.Rows[i]["TypeID_"].ToString() == @ViewBag.ETypeId ? "selected" : "") value=@ViewBag.ulist.Rows[i]["TypeID_"].ToString()>@ViewBag.ulist.Rows[i]["FullName"].ToString()</option>
                                    }
                                }
                            }
                        </select>
                    </div>
                </div>
            </div>
            <div class="col-lg-7 col-md-7  col-sm-7">
                <div class="form-group">
                    <div class="form-inline">
                        <lable>日期：</lable>
                        <input type="text"  onFocus="WdatePicker({isShowClear:true,readOnly:true})" id="txtDate" />
                        <input type="text"  onFocus="WdatePicker({isShowClear:true,readOnly:true})" id="txtEndDate" />
                    </div>
                </div>
            </div>
            <div class="col-lg-1 col-md-1  col-sm-1">
                <div class="form-group">
                    <div class="form-inline">
                        <button id="btnSeach" onclick="Search()" class="btn-default btn"><i class="glyphicon glyphicon-zoom-in"></i> 查询</button>&nbsp;
                        </div>
                    </div>
            </div>
                </div>
        <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
            <input type="hidden" id="state" />
            <input type="hidden" id="save" />
            <input type="hidden" id="nosaveid" />
            <input type="hidden" id="etypeid" />
            <input type="hidden" id="btypeid" />
            <input type="hidden" id="bnum" />
            <input type="hidden" id="strbtypeids" />
            <input type="hidden" id="isornosave" />
            <input type="hidden" id="isornodel" />
            <input type="hidden" id="isornomove" />
            <button id="btnNew" class="btn-default btn"><i class="glyphicon glyphicon-plus-sign"></i> 新增</button>
            <table id="CallPlanningTable" data-mobile-responsive="true"></table>
        </div>
            </div>
    <script type="text/javascript">
    function today() {//取当前时间
        var today = new Date();
        var h = today.getFullYear();
        var m = today.getMonth() + 1;
        var d = today.getDate();
        if (m < 10) {
            m = "0" + m;
        }
        if (d < 10) {
            d = "0" + d;
        }
        return h + "-" + m + "-" + d;
    }
    function Search() {
        $('#CallPlanningTable').bootstrapTable('refresh', { url: '../Shop/GetCallPlanningTableList?loginid=' + $.trim($("#ddlSalesman").val()) + '&date=' + $.trim($("#txtDate").val()) + '&endDate=' + $.trim($("#txtEndDate").val()) });
    }
    function EditCallPlanning(billid, etypeid, billdate) {//编辑
        $("#isornosave").val("");
        $("#isornodel").val("");
        $("#isornomove").val("");
        layer.open({
            type: 2,
            title: '<i class="glyphicon glyphicon-edit"></i> 编辑',
            shadeClose: false,
            shade: 0.5,
            area: ['90%', '95%'],
            content: '../Shop/V_NewCallPlanning?billid=' + billid + '&etypeid=' + etypeid + '&date=' + billdate,
            cancel: function (index) {
                if ($("#isornosave").val() == "yes" || $("#isornodel").val() == "yes" || $("#isornomove").val() == "yes") {
                    layer.confirm("信息<span style='color:red;'>未保存</span>,确定关闭？", { titli: "警告", closeBtn: 2, }, function (idx) {
                        layer.close(idx);
                        layer.close(index);
                    })
                    return false;
                }
            }
        })
    }
    function CallPlanningDetail(billid, etypeid, billdate) {//详情
        layer.open({
            type: 2,
            title: '<i class="glyphicon glyphicon-list"></i> 详情',
            shadeClose: false,
            shade: 0.5,
            area: ['90%', '95%'],
            content: '../Shop/V_CallPlanningDetail?etypeid=' + etypeid + '&billdate=' + billdate
        })
    }
    function DelCallPlanning(billid) {//删除
        layer.confirm("确认删除？", function (enter) {//删除前提示
            if (enter) {
                $.ajax({
                    url: "../Shop/DelCallPlanning",
                    dataType: "text",
                    data: { billid: billid},
                    type: "post",
                    success: function (data) {//删除成功后刷新table
                        layer.msg(data, { time: 2000 });
                        $('#CallPlanningTable').bootstrapTable("refresh");
                    },
                    error: function (data) {
                        layer.msg(data, { icon: 2, time: 2000 });
                    },
                })
            }
        })
    }
    $(function () {
        $("#txtDate").val(today());
        $("#txtEndDate").val(today());
        $('#CallPlanningTable').bootstrapTable({//线路信息
            url: '../Shop/GetCallPlanningTableList',         //请求后台的URL（*）
            method: 'post',                      //请求方式（*）
            toolbar: '#btnNew',                //工具按钮用哪个容器
            striped: true,                      //是否显示行间隔色
            pagination: true,                   //是否显示分页（*）
            sortOrder: "asc",                   //排序方式
            singleSelect: true,
            sidePagination: "server",           //分页方式：client客户端分页，server服务端分页（*）
            pageNumber: 1,                       //初始化加载第一页，默认第一页
            pageSize: 10,                       //每页的记录行数（*）
            pageList: [10, 30, 50],        //可供选择的每页的行数（*）
            minimumCountColumns: 2,  //最少允许的列数
            //height: $(".centerdiv").height()-15,               //行高，如果没有设置height属性，表格自动根据记录条数觉得表格高度
            uniqueId: "",            //每一行的唯一标识，一般为主键列
            clickToSelect: true,              //是否启用点击选中行
            sortable: true,                     //是否启用排序
            maintainSelected: true,
            silentSort: true,
            cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
            undefinedText:' ',                   //当数据为空时显示的字符
            search: false,                       //是否显示表格搜索，此搜索是客户端搜索，不会进服务端，所以，个人感觉意义不大
            strictSearch: false,
            paginationFirstText: '首页',
            paginationLastText: '末页',
            paginationPreText: '上一页',
            paginationNextText: '下一页',
            showHeader: true,
            showColumns: false,            //是否显示所有的列
            showRefresh: false,              //是否显示刷新按钮
            showToggle: false,                     //是否显示详细视图和列表视图的切换按钮
             cardView: false,                    //是否显示详细视图
            detailView: false,                   //是否显示父子表
            queryParams: function (params) {
                return {
                    pagesize: params.limit,//页面大小
                    page: params.offset, //页码
                    date: $("#txtDate").val(),
                    endDate: $("#txtEndDate").val()
                };
            },//传递参数（*）
            columns: [
                {
                    title: '序号', width: '5%', align: 'center',
                    formatter: function (value, row, index) {
                        var pageNumber = $('#CallPlanningTable').bootstrapTable('getOptions').pageNumber;
                        var pageSize = $('#CallPlanningTable').bootstrapTable('getOptions').pageSize;
                        return (pageNumber - 1) * pageSize + index + 1;
                    }
                },
                { field: "ETYPEID", title: "ETYPEID" },
                { field: "BILLID", title: "BILLID" },
                { field: "BILLDATE", title: "日期" },
                { field: "ETYPENAME", title: "业务员" },
                {
                    field: "Edit", title: "编辑", width: '25%', formatter: function (value, row, index) {//选择业务员
                        var strHtml = '<button id="btnEdit" class="btn" onclick="EditCallPlanning(\'' + row.BILLID + '\',\'' + row.ETYPEID + '\',\'' + row.BILLDATE + '\')"><i class="glyphicon glyphicon-edit"></i> 编辑</button> <button id="btnEdit" class="btn" onclick="CallPlanningDetail(\'' + row.BILLID + '\',\'' + row.ETYPEID + '\',\'' + row.BILLDATE + '\')"><i class="glyphicon glyphicon-list"></i> 详情</button> <button id="btnDel" class="btn" onclick="DelCallPlanning(\'' + row.BILLID + '\')"><i class="glyphicon glyphicon-trash"></i> 删除</button>';
                        return strHtml;
                    }
                }
            ]
        });
        $(window).resize(function () {
            $('#CallPlanningTable').bootstrapTable('resetView');
        });
        //隐藏列
        $('#CallPlanningTable').bootstrapTable('hideColumn', 'ETYPEID');
        $('#CallPlanningTable').bootstrapTable('hideColumn', 'BILLID');
        $("#btnNew").on("click", function () {//新增拜访规划
            $("#isornosave").val("");
            $("#isornodel").val("");
            $("#isornomove").val("");
            layer.open({
                type: 2,
                title: '<i class="glyphicon glyphicon-plus-sign"></i> 新增拜访规划',
                shadeClose: false,
                shade: 0.5,
                area: ['90%', '95%'],
                content: '../Shop/V_NewCallPlanning?dt=' + "@ViewBag.dt",
                end: function () {//关闭弹窗后
                    
                },
                cancel: function (index) {
                    if ($("#isornosave").val() == "yes" || $("#isornodel").val() == "yes" || $("#isornomove").val() == "yes") {
                        layer.confirm("信息<span style='color:red;'>未保存</span>,确定关闭？", { titli: "警告", closeBtn: 2, }, function (idx) {
                            layer.close(idx);
                            layer.close(index);
                        })
                        return false;
                    }
                }
            });
        });
    });
    </script>
</body>