@{
    Layout = null;
}
<head>
    <link href="~/Content/css/bootstrap.css" rel="stylesheet" />
    <link href="~/BootStrap/css/bootstrap-responsive.css" rel="stylesheet" />
    <link href="~/Scripts/calendar/skin/WdatePicker.css" rel="stylesheet" />
    <link href="~/Scripts/layui/css/layui.css" rel="stylesheet" />
    <link href="~/Scripts/ImagesUpload/css/fileinput.css" rel="stylesheet" />
</head>
<body>
    <input id="noticeid" type="hidden" value="@ViewBag.noticeid"/>
    <input id="delimage" type="hidden"/>
    <table id="contain" class="table table-bordered">
        <tr>
            <td width="15%">
                标题：
            </td>
            <td  colspan="3">
                <input id="title" type="text" class="form-control" placeholder="在此此处输入新标题" value="@ViewBag.title" @(ViewBag.see == true ? "readonly='true'" : "")/>
            </td>
        </tr>
        <tr>
            <td width="15%">
                生效时间：
            </td>
            <td>
                <input id="BEGINDATE" type="text" style="width:150px" class="form-control" onFocus="WdatePicker({isShowClear:true,readOnly:true})"  @(ViewBag.see == true ? "disabled='disabled'" : "") />
            </td>
            <td width="15%">
                失效时间：
            </td>
            <td width="60%">
                <input id="ENDDATE" type="text" style="width:150px" onFocus="WdatePicker({ isShowClear: true, readOnly: true })" class="form-control" @(ViewBag.see == true ? "disabled='disabled'" : "") />
            </td>
        </tr>
        <tr>
            <td width="15%">
                详细内容：
            </td>
            <td colspan="3">
                <textarea id="content" class="form-control" style="height:250px" placeholder="在此输入详细内容" @(ViewBag.see == true ? "readonly='true'" : "")>@ViewBag.content</textarea>
            </td>
        </tr>
        @{
            if (ViewBag.see == false)
            {
                <tr>
                    <td width="10%">
                        图片上传：
                    </td>
                    <td colspan="3">
                        <input id="file-zh" type="file" multiple/>
                    </td>
                </tr>
            }
        }
        @{
            if (ViewBag.image == true)
            {
                <tr id="seetr">
                    <td width="10%">
                        图片预览：
                    </td>
                    <td colspan="3">
                        <div style="float:left;position:relative;">
                            <img src="@ViewBag.url" style="width:200px;height:200px;float:left" id="nim" />
                            @{
                                if (ViewBag.edit == true)
                                {
                                    <a id="deli" onclick="Delimage()">
                                        <div style="float:left;cursor:pointer;height:30px;position:absolute;width:30px;margin-left:170px;background-image:url(../../icon/删除.png);background-size:30px 30px;background-repeat:no-repeat;"></div>
                                    </a>
                                }
                            }
                        </div>
                    </td>
                </tr>
            }
        }
        @{
            if (ViewBag.see == false)
            {
                <tr>
                    <td></td>
                    <td colspan="3"><button id="noticeSave" onclick="Save()" class="btn btn-default"><i class="glyphicon glyphicon-ok"></i> 保存</button></td>
                </tr>
            }
        }

    </table>
    <script src="~/Scripts/js/jquery.js"></script>
    <script src="~/Scripts/fileinput.js"></script>
    <script src="~/Scripts/zh.js"></script>
    <script src="~/Scripts/calendar/WdatePicker.js"></script>
    <script src="~/Scripts/layui/layui.js"></script>
    <script src="~/Scripts/layui/lay/modules/tree.js"></script>
    <script src="~/Scripts/layui/lay/modules/layer.js"></script>
    <script type="text/javascript">
        var enddate = document.getElementById("ENDDATE"),
            begindate = document.getElementById("BEGINDATE"),
            title = document.getElementById("title"),
            content = document.getElementById("content")
        // 获取元素到文档区域的坐标
        function getPosition(element) {
            var actualLeft = element.offsetLeft,
            actualTop = element.offsetTop,
            current = element.offsetParent; // 取得元素的offsetParent
            // 一直循环直到根元素
            while (current !== null) {
                actualLeft += current.offsetLeft;
                actualTop += current.offsetTop;
                current = current.offsetParent;
            }
            // 返回包含left、top坐标的对象
            return {
                left: actualLeft,
                top: actualTop
            };
        }

        function today() {//取当前时间
            var today = new Date();
            var h = today.getFullYear();
            var m = today.getMonth() + 1;
            var d = today.getDate();
            if (m < 10) {
                m = "0" + m;
            }
            if (d < 10) {
                d = "0" + d;
            }
            return h + "-" + m + "-" + d;
        }
        layer.ready(function () { //为了layer.ext.js加载完毕再执行
            layer.photos({
                photos: '#seetr',
                shift: 5 //0-6的选择，指定弹出图片动画类型，默认随机
            });
        });
        $('#file-zh').fileinput({
            language: 'zh',
            maxFileSize: 300,//上传文件最大的尺寸
            uploadUrl: '../Uploader/ImagesUploader?operation=notices',
            browseClass: "btn btn-default", //按钮样式
            allowedFileExtensions: ['jpg', 'png', 'gif'],
            previewFileIcon: "<i class='glyphicon glyphicon-king'></i>",
            maxFileCount: 1,
            validateInitialCount: true
        });
        $("#file-zh").on("fileuploaded", function (event, data, previewId, index) {
            parent.$('#NoticeTable').bootstrapTable('refresh');
            parent.layer.msg("保存成功！", { time: 2000 })
            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
            parent.layer.close(index); //再执行关闭
        });
        $(document).ready(function () {
            $("#BEGINDATE").val(today());
            $("#ENDDATE").val(today());
            if ('@ViewBag.begindate' != "") {
                $("#BEGINDATE").val('@ViewBag.begindate');
            }
            if ('@ViewBag.enddate' != "") {
                $("#ENDDATE").val('@ViewBag.enddate');
            }
            @*if ('@ViewBag.image' ==false) {
                document.getElementById("seetr").style.display = "none";
            }*@
            @*if ('@ViewBag.edit' == false) {
                document.getElementById("deli").style.display = "none";
            }*@

        })
        function Save() {
            if ($("#ENDDATE").val() < $("#BEGINDATE").val()) {
                layer.tips('失效日期必须大于生效日期！', '#ENDDATE', { shift: 0, tips: [1, '#c00'] });
                window.scrollTo(getPosition(ENDDATE).left, getPosition(ENDDATE).top);
                return false;
            }
            if ($.trim($("#title").val()).length <= 0) {
                layer.tips('标题不能为空！', '#title', { shift: 0, tips: [1, '#c00'] });
                window.scrollTo(getPosition(title).left, getPosition(title).top);
                return false;
            }
            if ($.trim($("#content").val()).length <= 0) {
                layer.tips('详细内容不能为空！', '#content', { shift: 0, tips: [1, '#c00'] });
                window.scrollTo(getPosition(content).left, getPosition(content).top);
                return false;
            }
            if (document.getElementById("file-zh").files.length <= 0) {
                $.ajax({
                    url: "../DealerEdition/UpdateNoticeFunction",
                    dataType: "text",
                    data: { noticeid: $("#noticeid").val(), begindate: $("#BEGINDATE").val(), enddate: $("#ENDDATE").val(), title: $("#title").val(), content: $("#content").val(), delimage: $("#delimage").val() },
                    type: "post",
                    success: function (data) {//
                        parent.$('#NoticeTable').bootstrapTable('refresh');
                        parent.layer.msg("保存成功！", { time: 2000 })
                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.layer.close(index); //再执行关闭
                    },
                    error: function (data) {
                        parent.$('#NoticeTable').bootstrapTable('refresh');
                        parent.layer.msg("保存失败！", { time: 2000 })
                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.layer.close(index); //再执行关闭
                    },
                });
            }
        }
        function Delimage() {
            layer.confirm("确认移除？", function (index) {//删除前提示
                if (index) {
                    document.getElementById("seetr").style.display = "none";
                    $("#delimage").val("yes");
                    layer.close(index);
                }
            })
        }
    </script>
</body>