<%@ page import="com.lightinit.hsdataplatform.dictionary.DicResourceCatelogType" %>
<%@ page import="com.lightinit.hsdataplatform.dictionary.DicResourceState" %>
<%@ page language="java" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>
<%@ page isELIgnored="false" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
    String basePath = request.getContextPath();
%>
<jsp:include page="../../../common/admin/modal_content_pre.jsp"><jsp:param name="modal_title" value="新增资讯"/></jsp:include>
<form id="formAdd" action="<%=basePath%>/admin/consult_mgr/consult.action" method="post" class="form-horizontal">
    <div class="form-group">
        <label for="newsTitle" class="col-md-2 col-sm-2 control-label"><span style="color: red;">*</span>资讯标题：</label>
        <input type="hidden" id="id" name="id" value="${outputModel.id}"/>
        <div class="col-md-9 col-sm-9">
            <input type="text" id="newsTitle" name="newsTitle" class="form-control" value="${outputModel.newsTitle}" />
            <span class="help-block"></span>
        </div>
    </div>
    <div class="form-group">
        <label for="subTitle" class="col-md-2 col-sm-2 control-label"><span style="color: red;">*</span>副标题：</label>
        <div class="col-md-9 col-sm-9">
            <input type="text" id="subTitle" name="subTitle" class="form-control" value="${outputModel.subTitle}"/>
            <span class="help-block"></span>
        </div>
    </div>
    <div class="form-group">
        <label for="newsCategory" class="col-md-2 col-sm-2 control-label"><span style="color: red;">*</span>资讯类别：</label>
        <div class="col-md-9 col-sm-9">
            <select id="newsCategory" name="newsCategory" class="form-control">
                <c:forEach items="${dicNewsCategory}" var="item" >
                    <c:choose>
                        <c:when test="${outputModel.newsCategory == item.value}">
                            <option value="${item.key}"  selected="selected" >${item.value}</option>
                        </c:when>
                        <c:otherwise>
                            <option value="${item.key}">${item.value}</option>
                        </c:otherwise>
                    </c:choose>
                </c:forEach>
            </select>
            <span class="field-validation-valid help-block"></span>
        </div>
        <%--<div class="col-md-9 col-sm-9">        &lt;%&ndash;处需要从后台查数据显示，待完善&ndash;%&gt;
            <select id="newsCategory" name="newsCategory" class="form-control">
                <option value="0"  selected="selected">信息资源提供方1</option>
                <option value="1" ${outputModel.newsCategory}>信息资源提供方2</option>
            </select>
            <span class="field-validation-valid help-block"></span>
        </div>--%>
       <%-- <div class="col-md-9 col-sm-9">
            <input type="text" id="newsCategory" name="newsCategory" class="form-control" value="${outputModel.newsCategory}"/>
            <span class="help-block"></span>
        </div>--%>
    </div>
    <div class="form-group">
        <label for="videoUrl" class="col-md-2 col-sm-2 control-label">视频URL：</label>
        <div class="col-md-9 col-sm-9">
            <input type="text" id="videoUrl" name="videoUrl" class="form-control" value="${outputModel.videoUrl}"/>
            <span class="help-block"></span>
        </div>
    </div>
    <div class="form-group">
        <label  class="col-md-2 col-sm-2 control-label"><span style="color: red;">*</span>资讯内容：</label>
        <div class="col-md-9 col-sm-9">
            <textarea id="summernote" name="newsContent" >${outputModel.newsContent}</textarea>
            <span class="help-block"></span>
        </div>
    </div>
</form>
<jsp:include page="../../../common/admin/modal_content_post.jsp"></jsp:include>
<jsp:include page="../../../common/admin/modal_footer_pre.jsp"></jsp:include>
<button type="button" id="btnCancel" class="btn btn-default" ><i class="fa fa-close"></i>取消</button>
<button type="button" id="btnSave" class="btn btn-primary"><i class="fa fa-check"></i>提交</button>
<jsp:include page="../../../common/admin/modal_footer_post.jsp"></jsp:include>
<script type="text/javascript">
    //初始化多文本编辑器
    $('#summernote').summernote({
        placeholder: '请输入内容',
        height: 150,                 // set editor height
        minHeight: 100,             // set minimum height of editor
        maxHeight: 190,             // set maximum height of editor
        focus: true,                  // set focus to editable area after initializing sum
        lang:'zh-CN',
        callbacks: {
            onImageUpload: function(files) {
                $(files).each(function(i,element){
                    sendFile(element);
                });
            }
        }
    });

    //上传图片
    function  sendFile(file){
        //console.info(file);
        var data=new FormData();
        data.append("file",file);
        $.ajax({
            url:'<%=basePath%>/admin/consult_mgr/upload.action',
            type:'post',
            data:data,
            async:false,
            cache:false,
            processData:false,
            contentType:false,
            success:function(result){
                if(result.stateCode==200){
                    $('#summernote').summernote('insertImage', result.data);
                }
            }
        });
    }
    //表单验证
    $("#formAdd").validate({
        rules: {
            newsTitle: "required",
            subTitle: "required",
            newsCategory: "required",
            newsContent:"required",
        }
    });
    //提交表单
    $("#btnSave").click(function() {
        $('#formAdd').ajaxSubmitCloseRefresh({closeRefreshOptions:{afterAction: destroySummernote}});
    });
  function fnSubmit() {
        $.post('<%=basePath%>/admin/consult_mgr/consult.action', $('#formAdd').serialize(),function(result){
            if(result.stateCode==200){
                alert(result.msg);

            }else{
                alert(result.msg);
            }
        });
    }

    function destroySummernote() {
        $('#summernote').summernote('destroy');
    }
    function closeModal() {
        destroySummernote();
        modal.modal('hide');
    }

    var modal = $(wysharpDefaultModalContainerSelector);
    modal.attr("data-backdrop", false).attr("data-keyboard", false);
    var closeModalButton = modal.find("button.close");
    closeModalButton.removeAttr("data-dismiss");
    closeModalButton.click(function () {
        closeModal();
    });
    $("#btnCancel").click(function () {
        closeModal();
    });


    //销毁多文本
    // $(wysharpDefaultModalContainerSelector).on('show.bs.modal', function (e) {
    //     $('#summernote').summernote('destroy');
    // })
</script>
