<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="HistoryData.aspx.cs" Inherits="RM.Web.WeiXin.HistoryData" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title><%=RM.Common.DotNetConfig.LanguageHelper.GetKey("HistoryData_xxltxx")%></title>
    <link href="../Training/Exam/Themes/Css/ExamGlobal.css" rel="stylesheet" type="text/css" />
    <script src="../Themes/Scripts/jquery-1.8.2.min.js" type="text/javascript"></script>
    <style type="text/css">
        .contentTitle{ text-align:center; width:350px;}
        .pageContainer{ padding-left:12px;}
        .infomationList { border: 1px solid #CCC; padding:10px 20px 10px 10px; background-image: url("/WeiXin/Images/WeiXinbg_body.jpg"); height: 400px; font-size: 13px;  overflow:scroll; overflow-y:scroll; overflow-x:hidden; }
        .infomationList, .infomationList li { width: 320px; }
        .infomationList li { padding: 10px 0; }
        .if_Context img{ width:200px!important; height:200px!important;}
        .if_Right { text-align: right; }
        .if_Name, .if_Context { vertical-align: top; display: inline-block; zoom:1;#display:inline;word-wrap: break-word; word-break:break-all; }
        .if_Name { border: 1px solid #CCC; height: 50px; width: 50px; text-align: center; padding:1px; border:1px solid #CCC; }
        .if_Name img{ height:50px; width:50px;}
        .if_Context { max-width: 230px;padding: 5px 8px; border-radius: 5px; background-color: #bae94b; margin: 0 5px;  background-image: linear-gradient(to bottom, #bae94b 0px, #a8d244 100%); border: 1px solid #CCC; text-align: left; }
        .if_MeContext { background-color: White; background-image: linear-gradient(to bottom, White 0px, #e8eaec 100%); }
        .contextDate { font-size: 11px; text-align: right; color: #666; }
        .answerBar{ padding-top:3px;}
        .answer { width: 260px; height:50px; padding:5px; }
        .answerOK { width:74px; border: 1px solid #CCC; display:inline-block; zoom:1; #display:inline; height:60px; vertical-align:top; line-height:60px; text-align:center; color:White; background-color:#39a9ff; }
        .answerOK:hover{ color:White;}
        .answerOK:active{ background-color:#2f95e3;}
        .weixin_More{ text-align:center;}
        .notData{ text-align:center; color:Red;}
        .nowDeliveryRed{ border:1px dashed #dd1b61;}
        .nowDeliveryBlue{border:1px dashed #6fb4e7;}
        .dataError{ border:1px solid red;}
        .dataErrorPrompt{ color:Red;}
        .reloadData{ cursor:pointer; color:Red;}
    </style>
    <script type="text/javascript">
        function nofind(img) {//图片加载异常
            img.src = "/WeiXin/Images/defualtUserImg.gif";
            img.onerror = null; //控制不要一直跳动
        } 
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div class="pageContainer">
        <h3 class="contentTitle">
            <%=RM.Common.DotNetConfig.LanguageHelper.GetKey("HistoryData_Title")%>
        </h3>
        <ul class="infomationList" id="ifm_List">
            <%=pageHtml.ToString() %>
        </ul>
        <div class="answerBar">
            <div>
                <textarea class="textarea_Txt answer" id="answer"></textarea>
                <a href="javascript:;" id="answerOk" class="answerOK" token="<%=token %>" touser="<%=toUser %>">
                     <%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Custom_List_huifu")%></a>
            </div>
        </div>
        <div class="weixin_More">
            <%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Custom_List_gdmxqfwwx")%>&nbsp;&nbsp;<a href="https://mp.weixin.qq.com/" target="_blank"><%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Custom_List_wxgzpt")%></a>
        </div>
    </div>
    </form>
    <script type="text/javascript">
        function CurentTime() {
            //获取当前时间方法
            var now = new Date();
            var year = now.getFullYear();       //年
            var month = now.getMonth() + 1;     //月
            var day = now.getDate();            //日
            var hh = now.getHours();            //时
            var mm = now.getMinutes();          //分
            var clock = year + "-";
            if (month < 10)
                clock += "0";
            clock += month + "-";
            if (day < 10)
                clock += "0";
            clock += day + " ";
            if (hh < 10)
                clock += "0";
            clock += hh + ":";
            if (mm < 10) clock += '0';
            clock += mm;
            return (clock);
        }
        $(function () {
            var ifm_Obj = $("#answerOk");
            if (!ifm_Obj.attr('token') || !ifm_Obj.attr('touser')) {
                $('#answer').attr('disabled', "disabled");
            } else { //可以回复，绑定事件
                ifm_Obj.click(setData);
                //重新发送事件
                $('.reloadData').live('click', function (e) {
                    setData(e, $(this).parent().prev().text());
                });
                //Ctrl+Enter提交
                $("#answer").keydown(function (e) {
                    var event = e || window.event; //兼容性处理
                    var key = e.keyCode || e.which || e.charCode; //获取键盘码
                    if (key == 13 && e.ctrlKey) {
                        setData(e);
                    }
                });
            }
            function setData(e, dataContext) {
                var asObj = $("#answer");
                var infomationContext = dataContext ? dataContext : jQuery.trim(asObj.val());
                if (infomationContext.length < 1) {
                    asObj.focus();
                    top.showTipsMsg('<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("AnswerInfomation_hfnrbyxwk")%>', 2000, 3);
                    return false;
                }
                //改变样式
                var lastObj = $('<li class="if_Right"><div class="if_Context if_MeContext"><div>' + infomationContext + '</div><div class="contextDate"><span class="dataState"><%=RM.Common.DotNetConfig.LanguageHelper.GetKey("HistoryData_zzfs")%>...</span>&nbsp;&nbsp;&nbsp;&nbsp;' + CurentTime() + '</div></div><div class="if_Name" title="我"><img src="/WeiXin/Images/defaultIconTwo.png" alt="" onerror="nofind(this)" /><p><%=RM.Common.DotNetConfig.LanguageHelper.GetKey("HistoryData_Me")%></p></div></li>');
                $("#ifm_List").append(lastObj);
                var infomationObj = lastObj.children('.if_Context');
                infomationObj.get(0).scrollIntoView(); //滚动到最下面
                infomationObj.addClass('nowDeliveryRed')
                var stateInfo = setInterval(function () {
                    infomationObj.toggleClass('nowDeliveryBlue');
                }, 500);
                asObj.val('');
                //异步操作
                $.ajax({
                    url: "/WeiXin/AnswerInfomationByUser.ashx",
                    type: "post",
                    data: { "dI": ifm_Obj.attr('touser'), "tK": ifm_Obj.attr('token'), "aS": infomationContext },
                    dataType: "text",
                    success: function (data) {
                        clearInterval(stateInfo);
                        var dataState = infomationObj.removeClass('nowDeliveryRed nowDeliveryBlue').find('.dataState');
                        if (data == 0) {
                            top.showTipsMsg('<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Int_hfsucc")%>', 2000, 4);
                            dataState.text('<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("HistoryData_sd")%>');
                        } else if (data == -2)//超过发送时间约定
                        {
                            infomationObj.addClass('dataError');
                            dataState.addClass('dataErrorPrompt').text('<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("HistoryData_fssb")%>');
                            top.showTipsMsg('<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("HistoryData_byxjxhfgjwxjkydzyxgesxsnhn")%>', 4000, 5);
                        } else {//回复失败
                            infomationObj.addClass('dataError');
                            infomationObj.find('.dataState').addClass('reloadData').text("<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("HistoryData_cxfs")%>");
                            top.showTipsMsg(data, 4000, 5);
                        }
                    },
                    error: function () {
                        showTipsMsg('<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("File_Exam")%>', 2000, 3);
                    }
                });
            }
        });
    </script>
</body>
</html>
