<%@include file="/WEB-INF/common/layouts/common.jsp" %>
<%@ page language="java" pageEncoding="UTF-8" %>
<html>
<head>
    <title>经纪人评价列表</title>
</head>
<body>
<%-- <div class="row${fluid}">
    <div class="span6">
        <h2 class="page-title">CmBrokerComment列表</h2>
    </div>
    <div class="span6 header_buttons">
        <a href="${ctx}/cmbrokercomment?action=create" class="btn blue pull-right"><i class="icon-plus"></i></a>
    </div>
</div> --%>

<!-- 面包屑 begin -->
<div class="row-fluid">
    <div class="span12">
        <ul class="breadcrumb">
            <!-- <li><a href="/house365-hmc-web/">首页</a> <span class="divider"></span></li> -->
            <li class="active"><span class="divider" style="color:#26a0da;font-weight:bold;">/</span>经纪人评价列表</li>
        </ul>
    </div>
</div>
<!-- 面包屑 begin -->

<div class="page-container">
    <div class="row${fluid}">
        <div class="span12">
            <form id="filterForm" class="form-inline filterForm" action="${ctx}/cmbrokercomment" method="get">
                <select class="span2" style="width:220px;height: 20px" name="search_EQ_cityKey"
                        onchange="changeCity(this)" id="citySelect">
                    <c:forEach items="${cityList}" var="city">
                        <option value="<c:out value="${city.code}" />"><c:out value="${city.name}"/></option>
                    </c:forEach>
                </select>
                <select class="span2" style="width:220px;height: 20px" name="search_searchType">
                    <option value="1" <c:if test="${param['search_searchType'] eq 1 }">selected="selected"</c:if>>用户名
                    </option>
                    <option value="2" <c:if test="${param['search_searchType'] eq 2 }">selected="selected"</c:if>>手机号
                    </option>
                </select>
                <!-- search_LIKE_criticPhone -->
                <input type="text" name="search_searchContent" value="${param['search_searchContent']}"
                       class="m-wrap small" placeholder="" style="height: 20px">
                <input type="text" name="search_LIKE_brokerCompanyName"
                       value="${param['search_LIKE_brokerCompanyName']}"
                       class="m-wrap small" placeholder="中介公司" style="height: 20px">
                <input type="text" name="search_LIKE_brokerName" value="${param['search_LIKE_brokerName']}"
                       class="m-wrap small" placeholder="经纪人" style="height: 20px">
                <input type="text" name="search_LIKE_criticContent" value="${param['search_LIKE_criticContent']}"
                       class="m-wrap small" placeholder="评论关键字" style="height: 20px">
                <input type="text"
                       class="datetime-picker span3" id="startTime" name="search_GTE_publishTimeStart"
                       value="${param['search_GTE_publishTimeStart']}" dateLte="#endTime"
                       date-format="yyyy-mm-dd" date-minView="month"
                       placeholder="点评开始时间">
                <input type="text"
                       class="datetime-picker span3" id="endTime" name="search_LTE_publishTimeEnd" dateGte="#startTime"
                       value="${param['search_LTE_publishTimeEnd']}" date-format="yyyy-mm-dd"
                       date-minView="month" placeholder="点评结束时间" class="input-large">
                <br/>
                状态:&nbsp;&nbsp;&nbsp;&nbsp;<select class="span2" name="search_EQ_isReaded"
                                                   data-placeholder="状态" style="width:220px;height: 40px">
                <option value="">全部</option>
                <option value="0"
                        <c:if test="${param['search_EQ_isReaded'] eq 0 && param['search_EQ_isReaded'] ne ''}">selected="selected"</c:if>>
                    未读
                </option>
                <option value="1" <c:if test="${param['search_EQ_isReaded'] eq 1 }">selected="selected"</c:if>>已读
                </option>
            </select>
                评分:&nbsp;&nbsp;&nbsp;&nbsp;<select class="span2" name="search_LIKE_criticScore"
                                                   data-placeholder="评分" style="width:220px;height: 40px">
                <option value="">全部</option>
                <option value="1" <c:if test="${param['search_LIKE_criticScore'] eq '1' }">selected="selected"</c:if>>
                    1星
                </option>
                <option value="2" <c:if test="${param['search_LIKE_criticScore'] eq '2' }">selected="selected"</c:if>>
                    2星
                </option>
                <option value="3" <c:if test="${param['search_LIKE_criticScore'] eq '3' }">selected="selected"</c:if>>
                    3星
                </option>
                <option value="4" <c:if test="${param['search_LIKE_criticScore'] eq '4' }">selected="selected"</c:if>>
                    4星
                </option>
                <option value="5" <c:if test="${param['search_LIKE_criticScore'] eq '5' }">selected="selected"</c:if>>
                    5星
                </option>
            </select>
                其他:&nbsp;&nbsp;&nbsp;&nbsp;<select class="span2" name="search_EQ_other"
                                                   data-placeholder="其他" style="width:220px;height: 40px">
                <option value="">不限</option>
                <option value="1" <c:if test="${param['search_EQ_other'] eq 1 }">selected="selected"</c:if>>置顶</option>
                <option value="2" <c:if test="${param['search_EQ_other'] eq 2 }">selected="selected"</c:if>>举报</option>
            </select>
                评论来源:&nbsp;&nbsp;&nbsp;&nbsp;<select class="span2" name="search_EQ_source"
                                                     data-placeholder="评论来源" style="width:220px;height: 40px">
                <option value="">不限</option>
                <option value="1" <c:if test="${param['search_EQ_source'] eq 1 }">selected="selected"</c:if>>APP
                </option>
                <option value="2" <c:if test="${param['search_EQ_source'] eq 2 }">selected="selected"</c:if>>WEB
                </option>
            </select>
                <%-- <div class="buttons pull-right"  style="margin-left:15px;">
                    <a href="${ctx}/cmbrokercomment?action=create" class="btn blue pull-right" title="新增"><i class="icon-plus"></i></a>
                </div>
                <div class="buttons pull-right" >
                    <a href="javascript:void(0);" onclick="deleteById('')" class="btn blue pull-right" title="删除"><i class="icon-minus"></i></a>
                </div> --%>
                <div class="buttons pull-right" style="margin:3px 30px 0 0;">
                    <i class="icon-search icon-2x pointer" onclick="$('#filterForm').submit();" title="搜索"></i>
                </div>
            </form>
        </div>
    </div>
    <table class="table table-striped table-advance table-hover">
        <thead>
        <tr>
            <th width="40" style="text-align:center">
                <input id="commentCheckAll" type="checkbox" onclick="checkAll(this)"/>
            </th>
            <th width="100">点评ID</th>
            <th width="100">经纪人</th>
            <th width="100">点评内容</th>
            <th width="100">点评标签</th>
            <th width="100">评分</th>
            <th width="100">点评人</th>
            <th width="100">中介公司</th>
            <th width="100">是否被举报</th>
            <th width="100">来源</th>
            <th width="100">时间</th>
            <th width="150">操作</th>
        </tr>
        </thead>
        <button class="btn blue" type="button" onclick="deleteById('',false)"><i
                class="icon"></i>&nbsp;批量删除
        </button>&nbsp;
        <button class="btn blue" type="button" onclick="setReaded()"><i
                class="icon"></i>&nbsp;批量标记已读
            <div id="reloadDiv">
                <c:forEach items="${cmBrokerComments}" var="cmBrokerComment">
                <tr>
                    <td nowrap="nowrap" style="text-align:center">
                        <input type="checkbox" name="commentCheck" value="${cmBrokerComment.id}"
                               onclick="checkComment(this)"/>
                    </td>
                    <td nowrap="nowrap">
                        <c:if test="${null ne cmBrokerComment.id && '' ne cmBrokerComment.id}">
                            <c:out value="${cmBrokerComment.id}"/>
                        </c:if>
                        <c:if test="${null eq cmBrokerComment.id || '' eq cmBrokerComment.id}">
                            &nbsp;
                        </c:if>
                    </td>
                    <td nowrap="nowrap">
                        <c:if test="${null ne cmBrokerComment.brokerName && '' ne cmBrokerComment.brokerName}">
                            <c:out value="${cmBrokerComment.brokerName}"/>
                        </c:if>
                        <c:if test="${null eq cmBrokerComment.brokerName || '' eq cmBrokerComment.brokerName}">
                            &nbsp;
                        </c:if>
                        <br/>
                        <c:if test="${null ne cmBrokerComment.brokerPhone && '' ne cmBrokerComment.brokerPhone}">
                            <c:out value="${cmBrokerComment.brokerPhone}"/>
                        </c:if>
                        <c:if test="${null eq cmBrokerComment.brokerPhone || '' eq cmBrokerComment.brokerPhone}">
                            &nbsp;
                        </c:if>
                    </td>
                    <td width="20%">
                            ${cmBrokerComment.criticContent}
                    </td>
                    <td>
                        <c:if test="${null ne cmBrokerComment.labels && '' ne cmBrokerComment.labels}">
                            <c:out value="${cmBrokerComment.labels}"/>
                        </c:if>
                        <c:if test="${null eq cmBrokerComment.labels || '' eq cmBrokerComment.labels}">
                            &nbsp;
                        </c:if>
                    </td>
                    <td nowrap="nowrap">
                        <c:if test="${null ne cmBrokerComment.criticScore && '' ne cmBrokerComment.criticScore}">
                            <c:out value="${cmBrokerComment.criticScore}"/>
                        </c:if>
                        <c:if test="${null eq cmBrokerComment.criticScore || '' eq cmBrokerComment.criticScore}">
                            &nbsp;
                        </c:if>
                        分
                    </td>
                    <td nowrap="nowrap">
                        <c:if test="${null ne cmBrokerComment.criticName && '' ne cmBrokerComment.criticName}">
                            <c:out value="${cmBrokerComment.criticName}"/>
                        </c:if>
                        <c:if test="${null eq cmBrokerComment.criticName || '' eq cmBrokerComment.criticName}">
                            &nbsp;
                        </c:if>
                        <br>
                        <c:if test="${null ne cmBrokerComment.criticPhone && '' ne cmBrokerComment.criticPhone}">
                            <c:out value="${cmBrokerComment.criticPhone}"/>
                        </c:if>
                        <c:if test="${null eq cmBrokerComment.criticPhone || '' eq cmBrokerComment.criticPhone}">
                            &nbsp;
                        </c:if>
                    </td>
                    <td nowrap="nowrap">
                        <c:if test="${null ne cmBrokerComment.brokerCompanyName && '' ne cmBrokerComment.brokerCompanyName}">
                            <c:out value="${cmBrokerComment.brokerCompanyName}"/>
                        </c:if>
                        <c:if test="${null eq cmBrokerComment.brokerCompanyName || '' eq cmBrokerComment.brokerCompanyName}">
                            &nbsp;
                        </c:if>
                    </td>
                    <td nowrap="nowrap">
                        <c:if test="${1 eq cmBrokerComment.isReported}">
                            是
                        </c:if>
                        <c:if test="${0 eq cmBrokerComment.isReported || '' eq cmBrokerComment.isReported || empty cmBrokerComment.isReported}">
                            否
                        </c:if>
                    </td>
                    <td nowrap="nowrap">
                        <c:if test="${1 eq cmBrokerComment.source}">
                            APP
                        </c:if>
                        <c:if test="${2 eq cmBrokerComment.source}">
                            WEB
                        </c:if>
                    </td>
                    <td nowrap="nowrap">
                        <c:if test="${null ne cmBrokerComment.publishTime && '' ne cmBrokerComment.publishTime}">
                            <f:formatDate value='${cmBrokerComment.publishTime}' pattern='yyyy-MM-dd HH:mm:ss'/>
                        </c:if>
                        <c:if test="${null eq cmBrokerComment.publishTime || '' eq cmBrokerComment.publishTime}">
                            &nbsp;
                        </c:if>
                    </td>
                    <td nowrap="nowrap">
                        <c:if test="${1 eq cmBrokerComment.isKicked}">
                            <a href="javascript:void(0);"
                               onclick="updateComment('${cmBrokerComment.id}','${cmBrokerComment.isKicked }','')">取消置顶</a>
                        </c:if>
                        <c:if test="${0 eq cmBrokerComment.isKicked || '' eq cmBrokerComment.isKicked || empty cmBrokerComment.isKicked}">
                            <a href="javascript:void(0);"
                               onclick="updateComment('${cmBrokerComment.id}','${cmBrokerComment.isKicked }','')">置顶</a>
                        </c:if>

                        <br/>
                        <c:if test="${1 eq cmBrokerComment.isReaded}">
                            已读
                        </c:if>
                        <c:if test="${0 eq cmBrokerComment.isReaded || '' eq cmBrokerComment.isReaded || empty cmBrokerComment.isReaded}">
                            <a href="javascript:void(0);"
                               onclick="updateComment('${cmBrokerComment.id}','','${cmBrokerComment.isReaded }')">标记已读</a>
                        </c:if>
                        <br/>
                        <a href="javascript:void(0);" onclick="deleteById('${cmBrokerComment.id}',false)">删除</a>
                        <br/>
                        <a href="javascript:void(0);" onclick="deleteById('${cmBrokerComment.id}',true)">删除并禁言48小时</a>
                    </td>
                </tr>
                </c:forEach>
    </table>
</div>
<div class="row${fluid}">
    <house365:pagination page="${page}"/>
</div>
</div>
<script type="text/javascript">

    $(function () {
        //默认选择城市
        $("#citySelect").val("${param['search_EQ_cityKey']}");
        $('#citySelect').trigger("chosen:updated");
    });

    //全选
    function checkAll(btn) {
        if (btn.checked) {
            if (document.all("commentCheck").length != undefined) {
                for (i = 0; i < document.all("commentCheck").length; i++) {
                    document.all("commentCheck")[i].checked = "checked";
                }
            }
            else {
                document.all("commentCheck").checked = "checked";
            }
        }
        else {
            if (document.all("commentCheck").length != undefined) {
                for (i = 0; i < document.all("commentCheck").length; i++) {
                    document.all("commentCheck")[i].checked = "";
                }
            }
            else {
                document.all("commentCheck").checked = "";
            }
        }
    }

    //单选
    function checkComment(btn) {
        if (btn.checked) {
            var checkAll = true;
            for (i = 0; i < document.all("commentCheck").length; i++) {
                if (document.all("commentCheck")[i].checked == false) {
                    checkAll = false;
                }
            }

            if (checkAll) {
                document.getElementById("commentCheckAll").checked = true;
            }
        }
        else {
            document.getElementById("commentCheckAll").checked = false;
        }
    }

    var deleteById = function (selectedId, isNoTalk) {
        /*
         id为空则是多选  判断是否为空
         为空 提示选择
         不为空 确认后删除
         不为空单选确认后删除
         */
        if (selectedId == "") {
            for (i = 0; i < document.getElementsByName('commentCheck').length; i++) {
                if (document.getElementsByName('commentCheck')[i].checked) {
                    selectedId += document.getElementsByName('commentCheck')[i].value + ",";
                }
            }

            var str = "";
            if (selectedId != "") {
                str = selectedId.split(",");

                if (str[str.length - 1] == "") {
                    selectedId = selectedId.substring(0, selectedId.length - 1);
                }
            }
        }

        if (selectedId == "") {
            House365Util.createModal("删除点评", "请至少选择一条点评!", function () {
            });
        }
        else {
            House365Util.createModal("删除点评", "确定要删除这些点评吗？", function () {
                $.ajax({
                    url: '${ctx}/cmbrokercomment/' + selectedId + "?isNoTalk=" + isNoTalk,
                    type: "DELETE",
                    success: function () {
                        window.location.reload();
                    }
                });
            });
        }

    };

    //修改评论属性(置顶，已读)
    function updateComment(commentId, isKicked, isReaded) {
        debugger;
        var readHtml = "";
        var kickHtml = "";
        if (isKicked == 0 && isKicked != "")//置顶
        {
            isKicked = 1;
            kickHtml = "<a href='javascript:void(0);' onclick='updateComment('${cmBrokerComment.id}','${cmBrokerComment.isKicked }','')'>取消置顶</a>";
        }
        else if (isKicked == 1)//取消置顶
        {
            isKicked = 0;
            kickHtml = "<a href='javascript:void(0);' onclick='updateComment('${cmBrokerComment.id}','${cmBrokerComment.isKicked }','')'>置顶</a>";
        }

        if (isReaded == 0 && isReaded != "")//已读
        {
            isReaded = 1;
            readHtml = "已读";
        }
        else {
            readHtml = "<a href='javascript:void(0);' onclick='updateComment('${cmBrokerComment.id}','','${cmBrokerComment.isReaded }')'>未读</a>";
        }

        $.ajax({
            url: '${ctx}/cmbrokercomment/' + commentId + '?action=updateComment&isKicked=' + isKicked + '&isReaded=' + isReaded,
            type: "POST",
            success: function () {
                window.location.reload();
                //$("#reloadDiv").reload();

                //$("#readLab"+commentId).html(readHtml);
                //$("#kickLab"+commentId).html(kickHtml);
            }
        });
    }

    //批量标记已读
    function setReaded() {

        debugger;
        var selectedId = "";

        if (document.all("commentCheck").length != undefined) {
            for (i = 0; i < document.all("commentCheck").length; i++) {
                if (document.all("commentCheck")[i].checked) {
                    selectedId += document.all("commentCheck")[i].value + ",";
                }
            }
            /* for(i=0;i<document.getElementsByName('commentCheck').length;i++)
             {
             if(document.getElementsByName('commentCheck')[i].checked)
             {
             selectedId += document.getElementsByName('commentCheck')[i].value + ",";
             }
             }    */
        }
        else {
            selectedId = document.all("commentCheck").value;
        }


        var str = "";
        if (selectedId != "") {
            str = selectedId.split(",");

            if (str[str.length - 1] == "") {
                selectedId = selectedId.substring(0, selectedId.length - 1);
            }
        }

        if (selectedId == "") {
            House365Util.createModal("标记已读", "请至少选择一条点评!", function () {
            });
        }
        else {
            House365Util.createModal("标记已读", "确定要标记已读这些点评吗？", function () {
                $.ajax({
                    url: '${ctx}/cmbrokercomment/' + selectedId + '?action=updateComment&isReaded=1',
                    type: "POST",
                    success: function () {
                        window.location.reload();
                    }
                });
            });
        }
    }

</script>
</body>
</html>
