@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@using MES.Production.Service;
@using Central.Control.Domain;
@using Ant.Service.Common;
@using Ant.Service.Common.Enums;
@using CommonToolHelper;

@model PageInfo
<div class="row col-lg-12">
    <div class="wrapper wrapper-content animated fadeInUp">
        <div class="ibox">
            <div class="ibox-title">
                <h5>发消息</h5>
                <div class="ibox-tools rboor">
                    <a class="btn btn-primary btn-xs p310" id="insert" action="add"><i class="im-plus"></i>发送消息</a>
                </div>
            </div>
            <div class="ibox-content">
                <!-- search star -->
                @using (Ajax.BeginForm("Index", null, new AjaxOptions() { }, new { @id = "form1", @class = "form-horizontal", @method = "get" }))
                {
                    <div class="form-horizontal clearfix">
                        <div class="col-lg-4 col-sm-3 pl0" style="width:50%;">
                            <div class="form-group">
                                <label class="control-label" style="width:100px; float:left;">消息类型:</label>
                                <div class="col-lg-8 col-sm-7">
                                    <select id="msgtype" name="msgtype" class="input-sm form-control input-s-sm inline" style="width:180px;" onchange="submit()">
                                        <option value="" @(ViewData["msgtype"].ToString() == "" ? "selected" : "")>全部</option>
                                        @{
                                        foreach (var item in ViewData["msgtypelist"] as List<SYS_CODE>)
                                        {
                                            <option value="@item.CODEVALUE" @(item.CODEVALUE == ViewData["msgtype"].ToString() ? "selected" : "")>@item.NAMETEXT</option>
                                        }
                                        }
                                    </select>
                                </div>
                            </div>
                        </div>

                        <div class="form-group col-sm-4" style="float:right;">
                            <div class="col-sm-12 input-group">
                                @Html.TextBox("Search", null, new { @class = "input-sm form-control", @placeholder = "请输入查询关键词" })
                                <span class="input-group-btn">
                                    <button type="submit" class="btn btn-sm btn-primary" onclick="submit()"> 搜索</button>
                                </span>
                            </div>
                        </div>
                    </div>
                <!-- search end -->
                    <div id="example_wrapper" class="dataTables_wrapper form-inline dt-bootstrap no-footer">
                        <table id="example" class="table table-striped table-bordered table-hover dataTables-example dataTable" cellspacing="0" width="100%">
                            <thead>
                                <tr>
                                    <th style="width:100px !important;">消息类型</th>
                                    <th>标题</th>
                                    <th style="width:200px !important;">接收人</th>
                                    <th style="width:150px !important;">发送时间</th>
                                    <th style="width:70px !important;">操作</th>
                                </tr>
                            </thead>
                            <tbody>
                                @{foreach (var item in Model.List)
                                {
                                <tr>
                                    <td>@item.MSGTYPE</td>
                                    <td style="text-align:left" title="@item.MSGNAME"><a href="javascript:show('@item.ID')">  @item.MSGNAME</a></td>
                                    <td style="text-align:left;">
                                        @{
                                            string per = item.READUSER;
                                            string res = string.Empty;
                                            if (!string.IsNullOrEmpty(per))
                                            {
                                                for (int i = 0; i < per.Split(',').Length; i++)
                                                {
                                                    if (per.Split(',')[i].ToString().Split('|')[0] == "0")
                                                    {
                                                        res += " <i class=\"im-envelop3\" style=\"color:#f0ad4e;\"></i>";
                                                    }
                                                    else
                                                    {
                                                        res += " <i class=\"im-envelop-opened\" style=\"color:#1ab394;\"></i>";
                                                    }
                                                    res += per.Split(',')[i].ToString().Split('|')[1];
                                                }
                                            }
                                        @Html.Raw(res);
                                        }
                                    </td>
                                    <td>@item.CREATEDATE</td>
                                    <td><a href="javascript:transpond('@item.ID')"> [转发]</a></td>
                                </tr>
                                }
                                }
                            </tbody>
                        </table>
                        <!-- page -->
                        <div class="bottom">
                            <div class="dataTables_info" id="example_info" post="status" aria-live="polite">显示第 @Model.BeginPage 至 @Model.EndPage 项结果,共 @Model.Count 项</div>
                            <div class="dataTables_length" id="example_length">
                                <label>
                                    显示
                                    <select name="example_length" onchange="submit()" aria-controls="example" class="form-control input-sm">
                                        <option value="10" @(Model.PageSize == 10 ? "selected" : "")>10</option>
                                        <option value="25" @(Model.PageSize == 25 ? "selected" : "")>25</option>
                                        <option value="50" @(Model.PageSize == 50 ? "selected" : "")>50</option>
                                        <option value="100" @(Model.PageSize == 100 ? "selected" : "")>100</option>
                                    </select> 项结果
                                </label>
                            </div>
                            @CommonHtmlHelper.PaginationPager(Model.Index, Model.PageSize, Model.Count, 7, Model.Url)
                            <div class="clear"></div>
                        </div>
                        <!-- page -->
                    </div>
                }
            </div>
            </div>
    </div>
</div>
@section scripts{
    <script type="text/javascript">
        //点击详情
        function show(n) {
            dig.addModel('消息详情', '/Sys/Msg/Show/' + n, 900, 500, function () { });
        }

        //点击转发
        function transpond(n) {
            window.location.href = "/Sys/Msg/Transpond/" + n;
        }
        $(function () {
            //添加
            $('#insert').click(function () {
                dig.addModel('发送消息', '/Sys/Msg/Detail/', 900, 500, function () {
                    var retval = this.returnValue;
                    if (retval!='' && retval!='no') {
                        window.location.reload();
                    }
                });
            });
        });
    </script>
}