@{
    ViewBag.Title = "照片查询";
    Layout = "~/Views/Shared/_LayoutTable.cshtml";
}
<body>
    <div class="container-fluid">
            <div class="row-fluid" style="margin-top:20px">
                <div class="col-lg-12">
                    <button class="btn btn-default" id="btnPhotoManger"><i class="glyphicon glyphicon-plus"></i>照片类型管理</button>
                </div>
            </div>
            <div class="container-fluid" style="margin-top:15px">
                <div class="row-fluid">
                    <div class="col-lg-3 col-md-3 col-sm-6 col-xs-12" style="padding:0;">
                        <div class="form-group">
                            <div class="form-inline">
                                <lable>日期：</lable>
                                <input type="text" style="width:100px" onfocus="WdatePicker({isShowClear:false,readOnly:true})" value="@ViewBag.pmStartDate" name="strdate" id="strdate" />
                                <input type="text" style="width:100px" onfocus="WdatePicker({isShowClear:false,readOnly:true})" value="@ViewBag.pmEndDate" name="strdate" id="enddate" />
                            </div>
                        </div>
                    </div>
                    <div class="col-lg-3 col-md-3 col-sm-6 col-xs-12" style="padding:0">
                        <div class="form-group">
                            <div class="form-inline">
                                <input type="text" readonly="true" id="fullname" placeholder="请选择客户" />
                                <input type="hidden" id="clientTypeID" />
                                <button onclick="ClientName()" class="glyphicon glyphicon-plus btn btn-default"></button>
                                <button class="glyphicon glyphicon-minus btn btn-default" onclick="ClearClient()"></button>
                            </div>
                        </div>
                    </div>
                    <div class="col-lg-3 col-md-3 col-sm-6 col-xs-12" style="padding:0">
                        <div class="form-group">
                            <div class="form-inline">
                                <input type="text" readonly="true" id="salesmanFullName" placeholder="请选择业务员" />
                                <input type="hidden" id="salesmanBtypeid" />
                                <button onclick="Salesman()" class="glyphicon glyphicon-plus btn btn-default"></button>
                                <button class="glyphicon glyphicon-minus btn btn-default" onclick="ClearSalesman()"></button>
                            </div>
                        </div>
                    </div>
                    <div class="col-lg-3 col-md-3  col-sm-6 col-xs-12" style="padding:0px;">
                        <div class="form-group">
                            <div class="form-inline">
                                <input type="checkbox" class="i-checks" value="a" name="chk1" id="chk1" />已删除照片
                                <button class="btn btn-default" onclick="Search()" id="btnSearch"><i class="glyphicon glyphicon-search"></i>查询</button>
                                <button onclick="DownImg()" class="btn btn-default">图片打包</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row-fluid">
                <div class="col-lg-12">
                    <table id="businessTable"></table>
                    <input type="hidden" id="hidBillid" />
                </div>
            </div>
        </div>
</body>
<script type="text/javascript">
    function DownImg() {
        var index = layer.open({
            content: '图片正在打包压缩生成下载地址,请稍候···',
            closeBtn: 0,
            btn: "",
            title: "",
        })
        var str1;
        $("input:checkbox[name='chk1']:checked").each(function () { // 已删除照片
            str1 = $(this).val();  // 每一个被选中项的值
        });
        var etypeid = $("#salesmanBtypeid").val();
        var btypeid = $("#clientTypeID").val();
        var bdate = $("#strdate").val();
        var edate = $("#enddate").val();
        $.ajax({
            url: "../DataQuery/GetPhotoQueryUrl",
            data: {
                btypeid: $("#clientTypeID").val(),
                etypeid: $("#salesmanBtypeid").val(),
                edate: $("#enddate").val(),
                bdate: $("#strdate").val(),
                str1: str1
            },
            datatype: "text",
            type: "post",
            success: function (data) {
                layer.close(index);
                if (data=="err") {
                    layer.msg("图片打包失败！");
                }
                else {
                    var url = new Array()
                    url = data.split(";");
                    if (url.length==1) {
                        location = "../DataQuery/down?filePath=" + url[0]+"&type=del";
                        return;
                    }
                    var html = "<table class=\"table table-striped\"><tr>";
                    var z = 0;
                    for (var i = 0; i < url.length; i++) {
                        z++;
                        html += "<td><a href=\"../DataQuery/down?filePath=" + url[i] + "&type=no\">压缩包" + (i + 1) + "</a></td>";
                        if (z==5) {
                            html += "</tr><tr>";
                            z = 0;
                        }
                    }
                    html += "</tr></table>";
                    layer.open({
                        type: 1,
                        title:"下载地址",
                        content: html,
                        end: function () {
                            $.ajax({
                                url: "../DataQuery/DelZip",
                                data: {
                                    url:data
                                },
                                datatype: "text",
                                type: "post",
                            })
                        }
                    })
                }
            }, error: function () {
                layer.close(index);
                layer.msg("连接超时！")
            }
        })
    }
    function ShowMap(longitude, latitude) {//查看地图
        layer.open({
            type: 2,
            title: '<i class="glyphicon glyphicon-map-marker"></i> 查看地图',
            shadeClose: false,
            shade: 0.5,
            area: ['70%', '80%'],
            content: '../WLTManage/ShowMap?longitude=' + longitude + '&latitude=' + latitude
        });
    }
    $(function () {
        $('#businessTable').bootstrapTable({
            url: '../DataQuery/GetPhotoQueryList',         //请求后台的URL（*）
            method: 'post',                      //请求方式（*）
            toolbar: '#toolbar',                //工具按钮用哪个容器
            striped: true,                      //是否显示行间隔色
            pagination: true,                   //是否显示分页（*）
            sortOrder: "asc",                   //排序方式
            sidePagination: "server",           //分页方式：client客户端分页，server服务端分页（*）
            pageNumber: 1,                       //初始化加载第一页，默认第一页
            pageSize: 15,                       //每页的记录行数（*）
            pageList: [15, 30, 50],        //可供选择的每页的行数（*）
            minimumCountColumns: 2,  //最少允许的列数
            undefinedText: "",
            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, //页码
                    bdate: $("#strdate").val(),
                    edate: $("#enddate").val(),
                };
            },//传递参数（*）
            columns: [
                {
                    field: "index", title: "序号", align: "center", width: 50, edit: false, formatter: function (value, row, index) {
                        return row.index = index + 1; //返回行号
                    }
                },
                    { field: 'FullName', title: '业务员' },
                    { field: 'CusName', title: '客户' },
                    { field: 'BillDate', title: '日期' },
                    { field: 'Typename', title: '照片类型' },
                    { field: 'Address', title: '地址' },
                    { field: 'DeviceID', title: '机器号' },
                    { field: 'Comment', title: '备注' },
                    { field: 'Num', title: '照片数' },
                    {
                        field: "showImg", title: "图片详情", align: "center", formatter: function (value, row, index) {
                            return '<button class="btn btn-default"><i class="glyphicon glyphicon-picture"></i> 查看</button>';
                        }
                    },
                    {
                        field: 'showMap', title: '显示地图', formatter: function (value, row, index) {
                            return '<button class="btn btn-default"><i class="glyphicon glyphicon-map-marker"></i> 地址</button>';
                        }
                    },
                    {
                        field: 'del', title: '操作', formatter: function (value, row, index) {
                            return '<button class="btn btn-default"><i class="glyphicon glyphicon-remove"></i> 删除</button>';
                        }
                    }
            ], onClickCell: function (field, value, row, e) {
                if (field == "showImg") {
                    $.ajax({
                        url: "../DataQuery/ImageViewShow",
                        dataType: "json",
                        data: { Billid: row["BillId"], typeName: row["Typename"] },
                        type: "post",
                        success: function (data) {
                            layer.photos({
                                photos: data,
                                shift: 0,
                                area: ['400px']
                            });
                        },
                        error: function (data) {
                            layer.msg(data, { icon: 5, time: 2000 });
                        },
                    })
                } else if (field == "showMap") {
                    var gps = row["GPS"].split(',');
                    ShowMap(gps[0], gps[1]);
                } else if (field == "del") {
                    layer.confirm("确定删除", { icon: 3, title: '提示' }, function (index) {
                        $.ajax({
                            url: "../DataQuery/DeleteImgData",
                            data: {
                                BillId: row["BillId"],
                                typeid: row["ImageTypeID"]
                            },
                            datatype: "text",
                            type: "post",
                            success: function (data) {
                                if (data == "ok") {
                                    layer.msg("删除成功")
                                    $('#businessTable').bootstrapTable("refresh");
                                }
                            }
                        })
                        layer.close(index);
                    })
                }
            }
        });
        //照片类型管理
        $("#btnPhotoManger").on("click", function () {
            layer.open({
                type: 2,
                title: '照片类型',
                shadeClose: false,
                shade: 0.5,
                area: ['80%', '90%'],
                content: '../DataQuery/PhotoTypeManger'
            });
        });
        $("#chk1").iCheck({ checkboxClass: "icheckbox_square-green" });
    });
    function next() {
        $("#imgDiv").children().remove();
        $("#imgDiv").append('<img src="././Content/img/login-background.jpg" />');
    }
    //选择客户名称
    function ClientName() {
        layer.open({
            type: 2,
            title: '客户信息',
            shadeClose: false,
            shade: 0.5,
            area: ['80%', '90%'],
            content: '../CommonSelector/ClientSelector'
        });
    }
    //选择业务员
    function Salesman() {
        layer.open({
            type: 2,
            title: '业务员信息',
            shadeClose: false,
            shade: 0.5,
            area: ['80%', '90%'],
            content: '../CommonSelector/SalesmanSelector'
        });
    }
    //查询
    function Search() {
        var str1;
        $("input:checkbox[name='chk1']:checked").each(function () { // 已删除照片
            str1 = $(this).val();  // 每一个被选中项的值
        });
        var etypeid = $("#salesmanBtypeid").val();
        var btypeid = $("#clientTypeID").val();
        var bdate = $("#strdate").val();
        var edate = $("#enddate").val();
        $("#businessTable").bootstrapTable('refresh', {
            url: '../DataQuery/GetPhotoQueryList?btypeid=' + btypeid + '&etypeid=' + etypeid + '&edate=' + edate + '&bdate=' + bdate + "&chk1=" + str1,
            queryParams: function (params) {
                return {
                    pagesize: params.limit,//页面大小
                    page: params.offset, //页码
                };
            }
        });
    }
    //清空选择器
    function ClearClient() {
        $("#fullname").val("");
        $("#clientTypeID").val("");
    }
    function ClearSalesman() {
        $("#salesmanFullName").val("");
        $("#salesmanBtypeid").val("");
    }
</script>
