@model string
<div class="current-location">
    <ul>
        <li class="left"><i class="glyphicon glyphicon-home"></i><a href="javascript:void(0)" onclick="location.href=location.href">信息群发</a></li>
        <li class="right"><a href="javascript:void(0)" onclick="LoadData()" title="刷新"><span class="glyphicon glyphicon-refresh"></span></a></li>
    </ul>
</div>
<div class="main">
    <form class="form-horizontal form ui-validForm" action="@Url.Action()" method="post">
        <div class="control-group">
            <label class="control-label">发件方式</label>
            <div class="controls">
                <label class="radio-inline">
                    <input type="radio" name="hairmode" id="hairmode" class="ui-show-hide" showobjs=".title,.content1" hideobjs=".email,.mobile,.content2" checked value="0" >站内信息
                </label>
                <label class="radio-inline">	    
                    <input type="radio" name="hairmode" id="hairmode" class="ui-show-hide" showobjs=".email,.title,.content1" hideobjs=".mobile,.content2" value="1">发送邮件
                </label>
                <label class="radio-inline">
                    <input type="radio" name="hairmode" id="hairmode" class="ui-show-hide" showobjs=".mobile,.content2" hideobjs=".email,.title,.content1" value="2">手机短信
                </label>
                <span class="help-block"></span>
            </div>
        </div>
        <div class="control-group username">
            <label class="control-label">接收用户</label>
            <div class="controls">
                <select id="username" name="username" class="form-control form-control-sm ui-convertSelect" multiple style="display:block;height:100px;width:95%;"></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")?objid=username',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:'#username'">删除选中用户</a>
                </div>
                <span class="help-block">按住Ctrl键可多选</span>
            </div>
        </div>
        <div class="control-group group">
            <label class="control-label">收件组</label>
            <div class="controls">
                <select id="group" name="group" class="form-control form-control-sm ui-convertSelect" multiple style="display:block;height:100px;width:95%;"></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","MemberType")?objid=group',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:'#group'">删除选中类别</a>
                </div>
                <span class="help-block">按住Ctrl键可多选</span>
            </div>
        </div>
        <div class="control-group department">
            <label class="control-label">收件部门</label>
            <div class="controls">
                <select id="department" name="department" class="form-control form-control-sm ui-convertSelect" multiple style="display:block;height:100px;width:95%;"></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","Department")?objid=department',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:'#department'">删除选中部门</a>
                </div>
                <span class="help-block">按住Ctrl键可多选</span>
            </div>
        </div>
        <div class="control-group email">
            <label class="control-label">接收邮箱</label>
            <div class="controls form-inline form-group-sm">
                <textarea type="text" value="" class="form-control" id="email" name="email" style="width:95%;height:100px;"></textarea>
                <span class="help-block">可导出用户邮箱资料，也可以直接输入邮箱地址(多个地址之间用半角逗号隔开)</span>
            </div>
        </div>
        <div class="control-group mobile">
            <label class="control-label">接收手机</label>
            <div class="controls form-inline form-group-sm">
                <textarea type="text" value="" class="form-control" id="mobile" name="mobile" style="width:95%;height:100px;"></textarea>
                <span class="help-block">可导出手机号码，也可以直接输入手机号码(多个号码之间用半角逗号隔开)</span>
            </div>
        </div>
        <div class="control-group title">
            <label class="control-label">标题</label>
            <div class="controls form-inline form-group-sm">
                <input type="text" value="" class="form-control" id="directory" name="directory" data-validate="dataType:'*" datatype1="*" nullMsg:'请填写标题！" style="width:60%" />
                <span class="help-block"></span>
            </div>
        </div>
        <div class="control-group content1">
            <label class="control-label">内容</label>
            <div class="controls">
                <textarea name="content1" rows="2" cols="20" id="content1" data-validate="dataType:'*" nullMsg:'请填写内容！" style="width:95%;height:290px;"></textarea>
                <script charset="utf-8" src="/e/incs/kindeditor/kindeditor.js"></script>
                <script>
                    KindEditor.ready(function (K) {
                        editor = K.create('#content1',
                                {
                                    uploadJson: kindeditor_uploadJson,
                                    fileManagerJson: kindeditor_fileManagerJson,
                                    allowFileManager: true,
                                    items: SimpleEditor,
                                    newlineTag: "br",
                                    filterMode: false,
                                    extraFileUploadParams: { siteid: '@ViewBag.siteId', table: '', field: 'content', username: '@ViewBag.userName' },
                                    afterBlur: function () { this.sync(); }
                                }
                            );
                    });
                </script>
                <span class="help-block"></span>
            </div>
        </div>
        <div class="control-group content2">
            <label class="control-label">内容</label>
            <div class="controls">
                <textarea name="content2" rows="2" class="form-control" cols="20" id="content2" data-validate="dataType:'*" datatype1="*" nullMsg:'请填写内容！" style="width:95%;height:290px;"></textarea>
                <span class="help-block"></span>
            </div>
        </div>

        <div class="control-group">
            <label class="control-label"></label>
            <div class="controls form-inline">
                <input type="hidden" name="remarks" id="remarks" value=""/>
                <input type="hidden" id="guid" name="guid" value="@Guid.NewGuid().ToString("N")" />
                <button type="button" class="btn btn-primary btn-sm ui-pagePost" data-custom-params="url:'@Url.Action("SendMsg")',failCallBack:'FailCallBack',beforeExecute:'BeforeExecute'" id="bt_submit">发送</button>
                <span class="help-block"></span>
            </div>
        </div>
    </form>
</div>
<script>
    function FailCallBack(data)
    {
        Data = eval("(" + JSON.stringify(data) + ")");
        if ($("#hairmode:checked").val() == "1") {
            $(".email").find(".help-block").text(Data.Msg).css({ "color": "red" });
        } else if ($("#hairmode:checked").val() == "2") {
            $(".mobile").find(".help-block").text(Data.Msg).css({ "color": "red" });
        }
    }
    function BeforeExecute() {
        var TotalText;
        var sendType = $("input[name='hairmode']:checked").val();
        var username = ConstructText("#username");
        var group = ConstructText("#group");
        var department = ConstructText("#department");
        TotalText = "收件用户：" + username + "<br>收件会员组：" + group + "<br>收件部门：" + department
        switch (sendType) {
            case "0":
                $("#remarks").val(TotalText);
                if ($("#content1").val() == "")
                {
                    Msg("内容不能为空！")
                    return false
                }
                break;
            case "1":
                var email = ConstructText("#email");
                TotalText += "<br>收件邮箱：" + email
                $("#remarks").val(TotalText);
                if ($("#content1").val() == "") {
                    Msg("内容不能为空！")
                    return false
                }
                break;
            case "2":
                var mobile = ConstructText("#mobile");
                TotalText += "<br>收件手机号码：" + mobile
                $("#remarks").val(TotalText);
                break;
        }
        return true;
    }
    $(function () {

    })
    function ConstructText(objname)
    {
        var TotalText="";
        $(objname).children("option").each(function (i) {
            var $this = $(this);
            TotalText += $this.text() + ",";
        });
        return TotalText.substring(0, TotalText.length-1);
    }
</script>

