@{
    ViewBag.Title = "";
    Layout = "~/Views/Shared/_LayoutTable.cshtml";
}
<body>
    <div class="container-fluid">
        <div class="row-fluid">
            <div class="col-md-6">
                <table class="table table-bordered table-striped table-hover" style="margin-top:10px">
                    <tr>
                        <td style="width:50px;">时间:</td>
                        <td>
                            <input type="text" class="form-control" onfocus="WdatePicker({isShowClear:false,readOnly:true})" id="pmStartDate" value="" />
                        </td>
                        <td>
                            <input type="text" class="form-control" onfocus="WdatePicker({isShowClear:false,readOnly:true})" id="pmEndDate" value="" />
                        </td>
                        <td>
                            <select class="chosen-select form-control" style="width:130px" data-placeholder="提交状态" id="dropTJ">
                                <option value=""></option>
                                <option value="0">未提交 </option>
                                <option value="1">已提交 </option>
                            </select>
                        </td>
                        <td>
                            <select data-placeholder="审核状态" style="width:130px;" class="chosen-select form-control" id="ddlStatus">
                                <option value=""></option>
                                <option value="0">未审核 </option>
                                <option value="1">已审核 </option>
                            </select>
                        </td>
                    </tr>
                </table>
            </div>
            <div class="col-md-6">
                <table class="table table-bordered table-striped table-hover" style="margin-top:10px">
                    <tr>
                        <td>
                            <select data-placeholder="提交人" style="width:130px" class="chosen-select form-control" id="logionUser">
                                <option value=""></option>
                                @{
                                    if (@ViewBag.ddluser != null && @ViewBag.ddluser.Rows.Count > 0)
                                    {
                                        for (int i = 0; i < @ViewBag.ddluser.Rows.Count; i++)
                                        {
                                            <option value='@ViewBag.ddluser.Rows[i]["TypeID_"]'>@ViewBag.ddluser.Rows[i]["FullName"] </option>
                                        }
                                    }
                                }
                            </select>
                        </td>
                        <td style="width:80px;">客户名称:</td>
                        <td>
                            <input type="text" class="form-control" id="rsNum" value="" readonly="true" />
                        </td>
                        <td>
                            <button onclick="ClientName()" class="glyphicon glyphicon-plus btn btn-default"></button>
                        </td>
                        <td>
                            <button class="glyphicon glyphicon-minus btn btn-default" onclick="Clear()"></button>
                        </td>
                        <td>
                            <button class="btn btn-default" id="btnSearch"><i class="glyphicon glyphicon-search"></i> 查 询</button>
                        </td>
                    </tr>
                </table>
            </div>
            <div class="col-md-12">
                <div id="toolbar">
                    <button id="btnPLSH" class="btn btn-default" onclick="reviewedList()"><i class="glyphicon glyphicon-cog"></i> 批量审核</button>
                    <button id="btnPLTJ" class="btn btn-default" onclick="BatchCommit()"><i class="glyphicon glyphicon-cog"></i> 批量提交</button>
                    <button id="btnPLDel" class="btn btn-default" onclick="delectList()"><i class="glyphicon glyphicon-cog"></i> 批量删除</button>
                </div>
                <table id="ModifyBtypeTable"></table>
            </div>
        </div>
    </div>
    <input id="uploadliginid" type="hidden" />
    <script type="text/javascript">
    $(function () {
        var tj = document.getElementById("dropTJ").value;
        var status = document.getElementById("ddlStatus").value;
        var params = { uploadzt: tj, shnehezt: status };
        $("#pmStartDate").val($.GetToday());
        $("#pmEndDate").val($.GetToday());
        $('#ModifyBtypeTable').bootstrapTable({
            url: '../WLTManage/GetModifyCustomerList',         //请求后台的URL（*）
            method: 'post',                      //请求方式（*）
            toolbar: '#toolbar',                //工具按钮用哪个容器
            striped: true,                      //是否显示行间隔色
            pagination: true,                   //是否显示分页（*）
            sortOrder: "asc",                   //排序方式
            sidePagination: "server",           //分页方式：client客户端分页，server服务端分页（*）
            pageNumber: 1,                       //初始化加载第一页，默认第一页
            pageSize: 10,                       //每页的记录行数（*）
            pageList: [10, 30, 50],        //可供选择的每页的行数（*）
            minimumCountColumns: 2,  //最少允许的列数
            //height: $(".centerdiv").height()-45,               //行高，如果没有设置height属性，表格自动根据记录条数觉得表格高度
            uniqueId: "Num",            //每一行的唯一标识，一般为主键列
            clickToSelect: true,              //是否启用点击选中行
            sortable: true,                     //是否启用排序
            silentSort: true,
            cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
            search: false,                       //是否显示表格搜索，此搜索是客户端搜索，不会进服务端，所以，个人感觉意义不大
            strictSearch: false,
            undefinedText:"",
            paginationFirstText: '首页',
            paginationLastText: '末页',
            paginationPreText: '上一页',
            paginationNextText: '下一页',
            showColumns: false,            //是否显示所有的列
            showRefresh: false,              //是否显示刷新按钮
            showToggle: false,                     //是否显示详细视图和列表视图的切换按钮
             cardView: false,                    //是否显示详细视图
            detailView: false,                   //是否显示父子表
            queryParams: function (params) {
                return {
                    pagesize: params.limit,//页面大小
                    page: params.offset, //页码
                    stardate:$("#pmStartDate").val(),
                    enddate: $("#pmEndDate").val()
                };
            },//传递参数（*）
            columns: [
                { field: 'ck', checkbox: true }, //选择
                 {
                     field: "index", title: "序号", align: "center", width: 50, edit: false, formatter: function (value, row, index) {
                         return row.index = index + 1; //返回行号
                     }
                 },
                   { field: 'CheckDate', title: '时间' },
                {
                    field: 'Checkzt', title: '审核', formatter: function (value, row, index) {
                        if (row.Checkzt == 0) {
                            return '<a ><i class="glyphicon glyphicon-edit"></i>未审核</a>';//onclick="reviewed(\'' + row + '\'
                        } else {
                            return '<a ><i class=\"glyphicon glyphicon-check\"></i>已审核</a>';
                        }
                    }
                },
                 {
                     field: 'Uploadzt', title: '提交状态', formatter: function (value, row, index) {
                         if (row.Uploadzt == 0) {
                             return '<span>未提交</span>';//onclick="reviewed(\'' + row + '\'
                         } else {
                             return '<span>已提交</span>';
                         }
                     }
                 },
                { field: 'busercode', title: '客户编号' },
                { field: 'bfullname', title: '客户名称' },
                { field: 'btypename', title: '新客户名称' },
                { field: 'lodefullname', title: '线路名称' },
                { field: 'Person', title: '新联系人' },
                { field: 'Mobile', title: '新联系电话' },
                { field: 'NewAddress', title: '更新地址' },
                {field: 'UpdateReason', title: '更换原因'},
                { field: 'uploadname', title: '提交人' },
                {
                    field: 'showImg', title: '图片', align: "center", formatter: function (value, row, index) {
                        return '<button class="btn btn-sm"><i class="glyphicon glyphicon-picture"></i> 查看</button>';
                    }
                },
                {
                    field: 'update', title: '详情', align: "center", formatter: function (value, row, index) {
                            var strHtml = '<button id="btnUpdate" class="btn btn-sm" onclick="editRightsUser(\'' + row["Btypeid"] + '\',\'' + row["Uploadzt"] + '\')"><i class="glyphicon glyphicon-edit"></i> 修改</button>';
                            return strHtml;
                      }
                 },
                   {
                       field: "del", title: "删除", align: "center", formatter: function (value, row, index) {
                           var strHtml = '<button id="btnDel" class="btn btn-sm" ><i class="glyphicon glyphicon-trash"></i> 删除</button>';
                           return strHtml;
                       }
                   }
            ], onClickCell: function (field, value, row) {
                if (field == "Checkzt") {
                    if (row["Checkzt"] == "1") {
                        layer.msg("该客户数据已审核", { icon: 6, time: 2000 });
                    } else {
                        reviewed(row);
                    }
                }
                else if (field == "Uploadzt") {
                    if (row["Uploadzt"] == "1") {
                        layer.msg("该客户数据已提交", { icon: 6, time: 2000 });
                    } else {
                        BatchCommitOne(row);
                    }
                }
                else if (field == "del") {
                    if (row["Uploadzt"] == "0") {
                        deleteUser(row["Btypeid"]);
                    } else {
                        layer.msg("该客户数据已提交", { icon: 2, time: 2000 });
                    }
                }
                else if (field == "showImg") {
                    $.ajax({
                        url: "../WLTManage/ImageViewShow",
                        dataType: "json",
                        data: { typeid: row["Btypeid"] },
                        type: "post",
                        success: function (data) {
                            layer.photos({
                                photos: data,
                                shift: 0,
                                area: ['50vw']
                            });
                        },
                        error: function (data) {
                            layer.msg(data, { icon: 5, time: 2000 });
                        },
                    })
                }
            }
        });
        $(window).resize(function () {
            $('#ModifyBtypeTable').bootstrapTable('resetView');
        });
    });

    //列表查询
    $("#btnSearch").on("click", function () {
        var stardate = $("#pmStartDate").val();
        var enddate = $("#pmEndDate").val();
        var tj = $('#dropTJ option:selected').val(); //选中的值
        var status = $('#ddlStatus option:selected').val(); //选中的值
        var rsNum = $("#uploadliginid").val();
        var loginUser = $("#logionUser option:selected").val();
        $('#ModifyBtypeTable').bootstrapTable("refresh", {
            url: "../WLTManage/GetModifyCustomerList?stardate=" + stardate + "&enddate=" + enddate + "&uploadzt=" + tj + "&shnehezt=" + status + "&uploadliginid=" + rsNum + "&loginUser=" + loginUser
        })
    });

    //修改权限用户
    function editRightsUser(btypeid, zt) {
        if (zt == '1') {
            layer.msg("用户已提交，不支持修改！", { time: 2000 });
            return;
        }
        layer.open({
            type: 2,
            title: '<i class="glyphicon glyphicon-edit"></i> 修改权限用户',
            shadeClose: false,
            shade: 0.5,
            area: ['60%', '90%'],
            content: '../WLTManage/UpdateBtypeModify?typeid=' + btypeid
        });
    }

    //行删除按钮
    function deleteUser(btypeid) {
        layer.confirm("确认删除？", function (enter) {
            if (enter) {
                $.ajax({
                    url: "../WLTManage/DeleteModifyBtype",
                    dataType: "text",
                    data: { typeid: btypeid },
                    type: "post",
                    success: function (data) {
                            layer.msg(data, { icon: 1, time: 2000 });
                            //删除成功后刷新table
                            $('#ModifyBtypeTable').bootstrapTable("refresh");
                    },
                    error: function (){
                        layer.msg("连接超时！", { icon: 1, time: 2000 });
                    }
                })
            }
        })
    }
    //批量删除
    function delectList() {
        var selectRows = $('#ModifyBtypeTable').bootstrapTable("getSelections");
        var btypeid = "";
        var num = 0;
        for (var i = 0; i < selectRows.length; i++) {
            if (selectRows[i].Checkzt == "0") {
                num++;
                btypeid += selectRows[i].Btypeid + ",";
            }
        }
        btypeid = btypeid.substring(0, btypeid.lastIndexOf(','));
        if (num < 1) {
            layer.msg("没有可删除数据", { icon: 2, time: 2000 });
            return;
        }
        layer.confirm("确认删除？", function (enter) {
            if (enter) {
                $.ajax({
                    url: "../WLTManage/DeleteModifyBtype",
                    dataType: "text",
                    data: { typeid: btypeid },
                    type: "post",
                    success: function (data) {
                        layer.msg(data, { icon: 1, time: 2000 });
                        //删除成功后刷新table
                        $('#ModifyBtypeTable').bootstrapTable("refresh");
                    },
                    error: function () {
                        layer.msg("连接超时！", { icon: 1, time: 2000 });
                    }
                })
            }
        })
    }
    //批量审核
    function reviewedList() {
        var selectRows = $('#ModifyBtypeTable').bootstrapTable("getSelections");
        var btypeid = "";
        var num = 0;
        for (var i = 0; i < selectRows.length; i++) {
            if (selectRows[i].Checkzt == "0") {
                num++;
                btypeid += selectRows[i].Btypeid + ",";
            }
        }
        btypeid = btypeid.substring(0, btypeid.lastIndexOf(','));
        if (num < 1) {
            layer.msg("数据不需要审核", { icon: 2, time: 2000 });
            return;
        }
        $.ajax({
            url: "../WLTManage/Reviewed",
            type: "post",
            dataType: "text",
            data: {
                btypeid: btypeid
            },
            success: function (data) {
                if (data == "ok") {
                    layer.msg("审核成功", { icon: 1, time: 2000 });
                    for (var i = 0; i < selectRows.length; i++) {
                        selectRows[i].Checkzt = "1";//selectRows[i].Woolinte_UpdateCustomer.Checkzt == "1" ? "0" : "1";
                        $('#ModifyBtypeTable').bootstrapTable("updateRow", { index: selectRows[i].index - 1, row: selectRows[i] });
                    }
                } else {
                    layer.msg("审核失败", { icon: 1, time: 2000 });
                }
            },
            error: function (data) {
                layer.msg("连接超时", { icon: 2, time: 2000 });
            }
        });
    }
    //批量提交
    function BatchCommit() {
        var selectRows = $('#ModifyBtypeTable').bootstrapTable("getSelections");
        var btypeid = "";
        var num = 0;
        for (var i = 0; i < selectRows.length; i++) {
            if (selectRows[i].Uploadzt == 0) {
                num++;
                btypeid += selectRows[i].Btypeid + ",";
            }
        }
        btypeid = btypeid.substring(0, btypeid.lastIndexOf(','));
        if (num < 1) {
            layer.msg("数据不需要提交", { icon: 2, time: 2000 });
            return;
        }
        $.ajax({
            url: "../WLTManage/BatchCommit",
            type: "post",
            dataType: "text",
            data: {btypeid: btypeid},
            success: function (data) {
                if (data == "ok") {
                    layer.msg("操作成功", { icon: 1, time: 2000 });
                    $('#ModifyBtypeTable').bootstrapTable("refresh")
                } else {
                    layer.msg("提交失败", { icon: 1, time: 2000 });
                }
               
            },
            error: function (data) {
                layer.msg("连接超时", { icon: 2, time: 2000 });
            }
        });
    }
    //单条审核
    function reviewed(row) {
        var id = row.Btypeid;
        $.ajax({
            url: "../WLTManage/Reviewed",
            type: "post",
            dataType: "text",
            data: {
                btypeid: id
            },
            success: function (data) {
                if (data == "ok") {
                    layer.msg("审核成功", { icon: 1, time: 2000 });
                    row.Checkzt = row.Checkzt == "1" ? "0" : "1";
                    $('#ModifyBtypeTable').bootstrapTable("updateRow", { index: row.index - 1, row: row });
                } else {
                    layer.msg("审核失败", { icon: 2, time: 2000 });
                }
            },
            error: function () {
                layer.msg("连接超时", { icon: 2, time: 2000 });
            }
        });
    }
    //单条提交
    function BatchCommitOne(row) {
        var id = row.Btypeid;
        $.ajax({
            url: "../WLTManage/BatchCommit",
            type: "post",
            dataType: "text",
            data: {
                btypeid: id
            },
            success: function (data) {
                if (data == "ok") {
                    layer.msg("操作成功", { icon: 1, time: 2000 });
                    row.Uploadzt = "1";
                    $('#ModifyBtypeTable').bootstrapTable("updateRow", { index: row.index - 1, row: row });
                } else {
                    layer.msg("审核失败", { icon: 2, time: 2000 });
                }
            },
            error: function () {
                layer.msg("连接超时", { icon: 2, time: 2000 });
            }
        });
    }
    //选择客户
    function ClientName() {
        layer.open({
            type: 2,
            title: '客户信息',
            shadeClose: false,
            shade: 0.5,
            area: ['80%', '70%'],
            content: '../CommonSelector/ClientSelector'
        });
    }

    function Clear() {
        $("#rsNum").val("");
        $("#uploadliginid").val("");
    }
    </script>
</body>
