@{
    ViewBag.Title = "照片查看";
    Layout = "~/Views/Shared/_LayoutTable.cshtml";
}

<div class="wrapper wrapper-content">
    <div class="ibox float-e-margins">
        <div class="ibox-content">
            <input type="hidden" id="strWhere" value="@TempData["strWhere"]" />
            <div class="form-horizontal m-t">
                <table class="table table-bordered table-striped table-hover" style="margin: 0px;">
                    <tr>
                        <td>
                            <div class="radio i-checks inline">
                                <label>
                                    <input type="radio" value="today" name="radios" checked="checked" id="today" />按天
                                </label>
                            </div>
                            <div class="radio i-checks inline">
                                <label>
                                    <input type="radio" value="month" name="radios" id="month" />按月
                                </label>
                            </div>
                            <button id="btnSeach" class="btn btn-default">查询</button>
                        </td>
                        <td>
                             <button onclick="DownImg()" class="btn btn-default ">图片打包</button>
                        </td>
                    </tr>
                </table>
                <div id="photoDetialList" style="cursor:pointer"></div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(function () {
        $(".i-checks").iCheck({ checkboxClass: "icheckbox_square-green", radioClass: "iradio_square-green", });
        var btnType = parent.$("#hidBtnType").val();
        var pid = parent.$("#hidPid").val();
        GetTablePhoto(pid, btnType, "today");
    });

    //弹出照片页面
    function GetImgDetialList(pid, pageType) {
        var chkObjs = null;
        var obj = document.getElementsByName("radios")
        for (var i = 0; i < obj.length; i++) { //遍历Radio 
            if (obj[i].checked) {
                chkObjs = obj[i].value;
            }
        }
        $.ajax({
            url: "../DataQuery/DetailImageViewShow",
            dataType: "json",
            data: { dateType: chkObjs, pid: pid, pageType: pageType },
            type: "post",
            success: function (data) {
                layer.photos({
                    photos: data,
                    shift: 0,
                    area: ['400px']
                });
            },
            error: function (data) {
                layer.msg(data, { icon: 5, time: 2000 });
            },
        })
    }

    //列表查询
    $("#btnSeach").on("click", function () {
        var btnType = parent.$("#hidBtnType").val();
        var pid = parent.$(" #hidPid").val();
        var chkObjs = null;
        var obj = document.getElementsByName("radios")
        for (var i = 0; i < obj.length; i++) { //遍历Radio 
            if (obj[i].checked) {
                chkObjs = obj[i].value;
            }
        }
        GetTablePhoto(pid, btnType, chkObjs);
    });

    function GetTablePhoto(pid, btnType, chkObjs) {
        $.ajax({
            url: "../DataQuery/PhotoDetailList",
            data: {
                pid: pid,
                btnType: btnType,
                dateType: chkObjs
            },
            datatype: "text",
            type: "post",
            success: function (data) {
                document.getElementById("photoDetialList").innerHTML = data;
                layer.photos({
                    photos: '#view',
                    shift: 5,
                    area: ['400px']
                });
            }
        })
    }

    function DownImg() {
        var index = layer.open({
            content: '图片正在打包压缩生成下载地址,请稍候···',
            closeBtn: 0,
            btn: "",
            title: "",
        })
        var btnType = parent.$("#hidBtnType").val();
        var pid = parent.$(" #hidPid").val();
        var chkObjs = null;
        var obj = document.getElementsByName("radios")
        for (var i = 0; i < obj.length; i++) { //遍历Radio 
            if (obj[i].checked) {
                chkObjs = obj[i].value;
            }
        }
        $.ajax({
            url: "../DataQuery/PhotoDetailListUrl",
            data: {
                pid: pid,
                btnType: btnType,
                dateType: chkObjs
            },
            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("图片包压缩失败！")
            }
        })

    }
</script>
