@using PageAdmin.Common;
@using PageAdmin.BLL;
@{
    User user = (User)ViewBag.CurrentUser;
    string guid = SysHelper.NewGuid();
    dynamic infoData = ViewBag.InfoData;
    string infoTable = ViewBag.InfoTable;
    string replyTable = new SubTableBLL().GetReplyTable(infoTable);
    byte replyState = infoData.reply_state;
}
<div class="main">

    <table class="table table-bordered">
        <tr>
            <td width="100px">标题：</td>
            <td>
                @infoData.title
            </td>
        </tr>
        <tr>
            <td width="100px">内容：</td>
            <td class="clearfix">
                <div>
                    @Html.Raw(infoData.content)
                </div>
                <div class="right">
                    <span>发布时间：@infoData.thedate</span>&nbsp;/&nbsp;<span>发布人：</span><span class="lb_username">@infoData.username</span>
                </div>
            </td>
        </tr>
        <tr>
            <td width="100px">状态：</td>
            <td>
                @{ string[] stateName = new string[] { "待回复", "处理中","转办中", "已回复", "已结束" };}
                @stateName[infoData.reply_state]
            </td>
        </tr>
    </table>
    <style type="text/css">
        .item .sp_delete {
            display: none;
        }

        .item:hover .sp_delete {
            display: inline;
        }
    </style>
    <div id="replyList" class="replyList">
        <div class="item template-item clearfix" id="item_{id}">
            <table class="table table-bordered">
                <tr>
                    <td width="100px">回复：</td>
                    <td class="clearfix">
                        <div style="padding:3px 0px">{content}</div>
                        <div style="padding:3px 0px" class="replyAttachmentsBox" data-custom-params="parentTable:'@replyTable',parentField:'attachments',parentGuid:'{guid}',parentId:{id}"></div>
                        <div class="clearfix">
                            <ul>
                                <li class="left"><span class="sp_delete" data-uid="{uid}" data-id="{id}" data-guid="{guid}"><button type="button" class="btn btn-xs btn-default btnDelete" title="删除"><span class="glyphicon glyphicon-trash" style="color:#999999"></span></button></span></li>
                                <li class="right">
                                    <span>发布时间：{thedate}</span> &nbsp;/&nbsp;<span>发布人：</span><span class="lb_username lb_replyUserName">{username}</span>
                                </li>
                            </ul>
                        </div>
                    </td>
                </tr>
                @*<tr>
                        <td width="100px">回复时间：</td>
                        <td>{thedate}</td>
                    </tr>
                    <tr>
                        <td width="100px">回复人：</td>
                        <td>{username}</td>
                    </tr>*@
            </table>

        </div>
    </div>


    <script type="text/javascript">
        var currentUid = "@user.Uid";
        function LoadData() {
            var url = "/api/SubData/GetList?parentTable=@ViewBag.InfoTable&parentField=reply&parentGuid=@infoData.guid&parentId=@infoData.id&order=id asc"
            $("#replyList").ListBind(url, { callBack: "LoadedInit", showFooter: false });
        }
        LoadData();

        function LoadedInit() {
            var $attachmentsBox = $(".replyAttachmentsBox");
            var $lbUsername = $(".lb_username");
            var $spDelete = $(".sp_delete");
            $attachmentsBox.each(function () {
                var $this = $(this);
                var thisParam = $this.attr("data-custom-params");
                thisParam = ExtendObject(thisParam);
                ListAttachments($this, thisParam);
            });
            $lbUsername.each(function () {
                var $this = $(this);
                if ($this.text() == "") {
                    $this.text("游客发布");
                }
            });
            $spDelete.each(function () {
                var $this = $(this);
                var uid = $this.attr("data-uid");
                var id = $this.attr("data-id")
                var guid = $this.attr("data-guid")
                if (uid == currentUid) {
                    $this.children(".btnDelete").click(function () {
                        Confirm("是否确定删除？", function () { Delete(guid, id); });

                    });
                }
                else {
                    $this.empty();
                }
            });
        }

        //载入附件
        function ListAttachments(jqObj, param) {

            $.get("/api/AttachmentData/getlist", param, function (dataList) {
                dataList = JsonParse(dataList);
                var html = "<ul>";
                $.each(dataList, function (idx, obj) {
                    var name = obj.title;
                    var path = obj.path;
                    var thumbnail = obj.thumbnail;
                    html += "<li><a href=\"" + path + "\" target=_blank><span class=\"glyphicon glyphicon-paperclip\">" + name + "</span></a></li>";
                    html += "</ul>";
                    jqObj.html(html);
                });

            });
        }

        //删除回复，只能删除自己发布的回复
        function Delete(guid, id) {
            var ajaxUrl = "/api/SubData/Delete";
            var param = { table: "@replyTable", guid: guid, id: id }
            Loading();
            $.post(ajaxUrl, param, function (data) {
                data = JsonParse(data);
                CloseLoading();
                if (data.State == 1) {
                    Msg("删除成功!");
                    LoadData();
                }
                else {
                    Msg(data.Msg);
                }
            }, "json");

        }
    </script>



    <text>
        <div class="panel panel-default">
            <div class="panel-body">
                <form method="post" class="form-horizontal form form-group-sm ui-validForm" action="@Url.Action()" data-custom-params="beforeSubmit:'OnBeforeSubmit'">

                    <div class="control-group">
                        <label class="control-label" for="content">选择操作类型</label>
                        <div class="controls">
                            <select id="_reply_state" name="_reply_state" class="form-control form-control-sm ui-show-hide">
                                <option value="1" hideObjs=".turnUidsBox">状态设为处理中</option>
                                <option value="2" showObjs=".turnUidsBox">转给其他用户处理</option>
                                <option value="3" showObjs=".replyBox" hideObjs=".turnUidsBox" selected>回复信息</option>
                                <option value="4" hideObjs=".replyBox,.turnUidsBox">状态设为已结束</option>
                            </select>
                            <span class="help-block"></span>
                        </div>
                    </div>

                    <div class="control-group turnUidsBox">
                        <label class="control-label">选择转办用户</label>
                        <div class="controls form-inline form-group-sm">
                            <select id="_turn_uids" name="_turn_uids" class="form-control form-control-sm ui-convertSelect" multiple style="display:block;height:100px;" data-custom-params="url:'@Url.Action("LoadListByIds","Member")',textField: 'username'"></select>
                            <div class="btn-group btn-group-sm" style="margin-top:5px;">
                                <a href="javascript:void(0)" class="btn btn-default btn-sm ui-dialog" data-custom-params="title:'选择用户',url:'@Url.Action("Select","Member")?objname=#_turn_uids',width:'800px',height:'90%',target:'_self'">选择用户</a>
                                <a href="javascript:void(0)" class="btn btn-default btn-sm ui-removeSelectedOptions" title="按住Ctrl键可实现多选" data-custom-params="obj:'#_turn_uids'">删除选中</a>
                            </div>
                            <span class="help-block">请选择要转办的用户，可以多选！</span>
                        </div>
                    </div>

                    <div class="replyBox">
                        @{
                            IEnumerable<dynamic> fieldList = new FieldBLL().GetFieldList(replyTable, "add", user);
                            string beforeSubmitJs = "";
                            var data = new ViewDataDictionary();
                            data.Add("from", "admin");
                            data.Add("table", replyTable); //对应的表
                            data.Add("detailId", 0); //当前信息id
                            data.Add("siteId", ViewBag.SiteId);  //当前站点id
                            data.Add("guid", guid);
                            data.Add("currentUser", user);
                            data.Add("i", 0);
                            int i = 0;
                            if (fieldList != null)
                            {
                                foreach (var row in fieldList)
                                {
                                    data["i"] = i;
                                    beforeSubmitJs += row.before_submit_js;
                                    Html.RenderPartial("~/Views/CustomForm/FormPartial.cshtml", (object)row, data);
                                    i++;
                                }
                            }

                        }
                    </div>
                    <script type="text/javascript">
                        function BeforeSubmit() {
                            @beforeSubmitJs
                            return true;
                        }
                        function PostBack() {
                            var win = Parent();
                            if (win != null) {
                                win.LoadData();
                            }
                            location.href = location.href;
                        }
                        function OnBeforeSubmit()
                        {
                            if($("#_reply_state").val()=="2" && $("#_turn_uids").children("option").length==0)
                            {
                                Msg("请选择转办用户！")
                                return false;
                            }
                            return true;
                        }
                    </script>
                    <div class="control-group">
                        <div class="controls">
                            @Html.AntiForgeryToken()
                            <input type="hidden" name="_table" id="_table" value="@replyTable" />
                            <input type="hidden" name="id" id="id" value="0" />
                            <input type="hidden" name="guid" id="guid" value="@guid" />
                            <input type="hidden" name="_parent_table" id="_parent_guid" value="@infoTable" />
                            <input type="hidden" name="parent_guid" id="parent_guid" value="@infoData.guid" />
                            <input type="hidden" name="parent_id" id="parent_id" value="@infoData.id" />
                            <button type="button" class="btn btn-primary btn-sm ui-pagePost" data-custom-params="url:'/Api/SubData/Add',callBack:'PostRefreshBack'">提交</button>
                            <button type="button" class="btn btn-default btn-sm ui-closeDialog">关闭</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </text>

</div>
