<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/12/4/004
 * Time: 11:01
 */
?>
<div class="modal-header">
    <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
    <h4 class="modal-title">添加邮件</h4>
</div>
<form id="form" class="form-horizontal">
    <div class="modal-body">

        <div class="input-group">
            <span class="input-group-addon">类型</span>
            <select class="form-control" name="type">
                <option value="0">会员</option>
                <option value="1">代理商</option>
                <option value="2">会员+代理商</option>
                <option value="3">自定义</option>
            </select>
        </div>
        <div class="hr-line-dashed"></div>
        <div class="input-group">
            <span class="input-group-addon">标题</span>
            <input id="subject" name="subject" type="text" class="form-control" placeholder="邮件标题">
        </div>
        <div class="hr-line-dashed"></div>

        <div class="input-group">
            <span class="input-group-addon">内容</span>
            <textarea id="kindeditor" name="content" type="text" class="form-control"></textarea>
        </div>
        <div class="hr-line-dashed"></div>
        <div class="input-group">
            <span class="input-group-addon">地址</span>
            <input id="other" name="other" type="text" class="form-control" placeholder="自定义邮件接收列表，多个请用“,”号分割">
        </div>


    </div>
    <div class="modal-footer">
        <button type="button" class="btn btn-white" data-dismiss="modal">取消</button>
        <button id="submit" type="button" class="btn btn-primary">提交</button>
    </div>
</form>


<script type="text/javascript">
    var editor;
    KindEditor.ready(function(K) {
        editor=K.create('#kindeditor', {
            uploadJson: '/admin/kindeditor/upload',
            fileManagerJson: '/admin/kindeditor/file-manager',
            allowFileManager: true,
            urlType: 'domain',
            width : '100%',
            height: '200px',
            items: ['fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline', 'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist', 'insertunorderedlist', '|', 'image','insertfile', 'link','source'],
        });
    });
    $("#submit").on("click",function(){
        editor.sync();
        $.ajax({
            type: "POST",
            url: "/admin/mail/save",
            data: $('#form').serialize(),
            dataType: "json",
            beforeSend: function() {},
            success: function(data) {

                if(data.code == 1){
                    $("#modal").modal("hide");
                    table.ajax.reload();
                }else{
                    toastr.error(data.message, "提示");
                }

            },
            complete: function(XMLHttpRequest, textStatus) {},
            error: function() {}
        });
    });

</script>
