@{
    ViewBag.Title = "简单拜访";
    Layout = "~/Views/Shared/_LayoutTable.cshtml";
}
<body>
    <div class="container-fluid">
        <div class="row-fluid" style="padding:10px;margin-top:10px;border-radius:10px;">
            <div class="col-lg-4 col-md-6 col-sm-6 col-xs-12">
                <div class="form-inline">
                    <div class="form-group">
                            <lable>时间段：</lable><input type="text" class="form-control" style="width:100px" onFocus="WdatePicker({ isShowClear: true, readOnly: true })" id="strdate" /> <input type="text" style="width:100px" onFocus="    WdatePicker({ isShowClear: true, readOnly: true })" id="endate" />
                    </div>
                </div>
            </div>
            <div class="col-lg-3 col-md-6  col-sm-6 col-xs-12">
                <div class="form-inline">
                    <div class="form-group">
                            <lable>业务员：</lable>
                            <select id="ddlSalesman" style="width:110px" class="chosen-select">
                                @{
                                    if (@ViewBag.ulist != null && @ViewBag.ulist.Rows.Count > 0)
                                    {
                                        for (int i = 0; i < @ViewBag.ulist.Rows.Count; i++)
                                        {
                                            <option value=@ViewBag.ulist.Rows[i]["TypeID_"].ToString()>@ViewBag.ulist.Rows[i]["FullName"].ToString()</option>
                                        }
                                    }
                                }
                            </select>
                    </div>
                </div>
            </div>
            <div class="col-lg-3 col-md-6  col-sm-6 col-xs-12">
                <div class="form-inline">
                    <div class="form-group">
                            <lable>客户名称：</lable><input type="text" class="form-control" style="width:100px" id="fullname" readonly="readonly" />
                            <button class="glyphicon glyphicon-plus btn btn-default" onclick="ShowCustomer()"></button>
                            <button class="glyphicon glyphicon-minus btn btn-default" onclick="ClearCustomer()"></button>
                    </div>
                </div>
            </div>
            <div class="col-lg-1 col-md-6  col-sm-6 col-xs-12">
                <div class="form-inline">
                    <div class="form-group">
                        <button id="btnSeach" onclick="Search()" class="btn btn-default"><i class="glyphicon glyphicon-zoom-in"></i> 查询</button>
                    </div>
                </div>
            </div>
        </div>
        <div class="row-fluid" style="margin-top:5px;">
            <duv class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                <input type="hidden" id="count" value="0" />
                <input type="hidden" id="issave" />
                <input type="hidden" id="clientTypeID" />
                <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 btn-default"><i class="glyphicon glyphicon-plus-sign"></i> 新增</button>
                <table id="SimpleCallPlanningTable" data-mobile-responsive="true"></table>
            </duv>
        </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 ShowCustomer() {//选择客户
            layer.open({
                type: 2,
                title: '<i class="glyphicon glyphicon-eye-open"></i> 选择客户',
                shadeClose: false,
                shade: 0.5,
                area: ['80%', '80%'],
                content: '../CommonSelector/ClientSelector'
            })
        }
        function ClearCustomer() {//清除选择客户
            $("#fullname").val("");
            $("#clientTypeID").val("");
        }
        function Search() {
            $('#SimpleCallPlanningTable').bootstrapTable('refresh', { url: '../Shop/GetSimpleCallPlanningTableList?begindate=' + $("#strdate").val() + '&enddate=' + $("#endate").val() + '&etypeid=' + $.trim($("#ddlSalesman").val()) + '&customerid=' + $("#clientTypeID").val() });
        }
        function Edit(billid, billdate, enddate, etypeid) {//编辑
            $("#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_NewSimpleCallPlanning?billid=' + billid + '&startDate=' + billdate + '&endDate=' + enddate + '&etypeid=' + etypeid,
                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;
                    }
                }
            })
        }
        function SimpleCallPlanningDetail(billid) {//详情
            layer.open({
                type: 2,
                title: '<i class="glyphicon glyphicon-list"></i> 详情',
                shadeClose: false,
                shade: 0.5,
                area: ['90%', '95%'],
                content: '../Shop/V_SimpleCallPlanningDetail?billid=' + billid
            })
        }
        function Del(billid) {//删除
            layer.confirm("确认删除？", function (enter) {//删除前提示
                if (enter) {
                    $.ajax({
                        url: "../Shop/DelSimpleCallPlanning",
                        dataType: "text",
                        data: { billid: billid },
                        type: "post",
                        success: function (data) {//删除成功后刷新table
                            layer.msg(data, { time: 2000 });
                            $('#SimpleCallPlanningTable').bootstrapTable("refresh");
                        },
                        error: function (data) {
                            layer.msg(data, { time: 2000 });
                        },
                    })
                }
            })
        }
        $(function () {
            $("#strdate").val(today());
            $("#endate").val(today());
            $('#SimpleCallPlanningTable').bootstrapTable({//线路信息
                url: '../Shop/GetSimpleCallPlanningTableList',         //请求后台的URL（*）
                method: 'post',                      //请求方式（*）
                toolbar: '#btnNew',                //工具按钮用哪个容器
                striped: true,                      //是否显示行间隔色
                pagination: true,                   //是否显示分页（*）
                sortOrder: "asc",                   //排序方式
                singleSelect: true,
                undefinedText: ' ',
                sidePagination: "server",           //分页方式：client客户端分页，server服务端分页（*）
                pageNumber: 1,                       //初始化加载第一页，默认第一页
                pageSize: 10,                       //每页的记录行数（*）
                pageList: [10, 30, 50],        //可供选择的每页的行数（*）
                minimumCountColumns: 2,  //最少允许的列数
                //height: $(".centerdiv").height()-45,               //行高，如果没有设置height属性，表格自动根据记录条数觉得表格高度
                uniqueId: "",            //每一行的唯一标识，一般为主键列
                clickToSelect: true,              //是否启用点击选中行
                sortable: true,                     //是否启用排序
                maintainSelected: true,
                silentSort: true,
                cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
                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, //页码
                        begindate: $("#strdate").val(),
                        enddate: $("#endate").val()
                    };
                },//传递参数（*）
                columns: [
                    {
                        title: '序号', width: '5%', align: 'center',
                        formatter: function (value, row, index) {
                            var pageNumber = $('#SimpleCallPlanningTable').bootstrapTable('getOptions').pageNumber;
                            var pageSize = $('#SimpleCallPlanningTable').bootstrapTable('getOptions').pageSize;
                            return (pageNumber - 1) * pageSize + index + 1;
                        }
                    },
                    { field: "BILLID", title: "BILLID" },
                    {
                        field: "TIMESLOT", title: "时间段", formatter: function (value, row, index) {
                            return row.BILLDATE + " 至 " + row.ENDDATE;
                        }
                    },
                    { field: "BILLDATE", title: "开始时间" },
                    { field: "ENDDATE", title: "结束时间" },
                    {
                        field: "DAYS", title: "天数", formatter: function (value, row, index) {
                            if (value == null) {
                                return 0;
                            } else {
                                return value;
                            }
                        }
                    },
                    {
                        field: "CUSCOUNT", title: "客户数", formatter: function (value, row, index) {
                            if (value == null) {
                                return 0;
                            } else {
                                return value;
                            }
                        }
                    },
                    { field: "ETYPENAME", title: "业务员" },
                    { field: "ETYPEID", title: "ETYPEID" },
                    {
                        field: "XIWAMAXTIME", title: "创建时间"
                    },
                    {
                        field: "EDIT", title: "操作", width: '20%', formatter: function (value, row, index) {//选择业务员
                            var strHtml = '<button id="btnDetail" class="btn btn-default" onclick="SimpleCallPlanningDetail(\'' + row.BILLID + '\')"><i class="glyphicon glyphicon-list"></i> 客户详情</button> <button id="btnEdit" class="btn btn-default" onclick="Edit(\'' + row.BILLID + '\',\'' + row.BILLDATE + '\',\'' + row.ENDDATE + '\',\'' + row.ETYPEID + '\')"><i class="glyphicon glyphicon-edit"></i> 编辑</button> <button id="btnDelete" class="btn btn-default" onclick="Del(\'' + row.BILLID + '\')"><i class="glyphicon glyphicon-trash"></i> 删除</button>';
                            return strHtml;
                        }
                    }
                ]
            });
            $(window).resize(function () {
                $('#SimpleCallPlanningTable').bootstrapTable('resetView');
            });
            //隐藏列
            $('#SimpleCallPlanningTable').bootstrapTable('hideColumn', 'BILLDATE');
            $('#SimpleCallPlanningTable').bootstrapTable('hideColumn', 'ETYPEID');
            $('#SimpleCallPlanningTable').bootstrapTable('hideColumn', 'ENDDATE');
            $('#SimpleCallPlanningTable').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: ['95%', '95%'],
                    content: '../Shop/V_NewSimpleCallPlanning',
                    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>