unionShareMessageEdit.html 8.81 KB
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8" />
    <title>Yoho!Buy运营平台</title>
    <script src="/union/js/include.js"></script>
    <style>
        .sub-title {
            height: 60px;
            align-items: left;
            vertical-align: middle;
            padding-left: 20px;
            font-size: 20px;
            line-height: 60px;
            border: 1px solid #D7D7D7;
            color: #666666;
            background-color: #F7F7F7;
        }

        .row-input {
            width:95%;
            heigth: 40px;
            line-height: 40px;
            margin-top:15px;
            font-size: 16px;
            display: block;
        }

        .row-input .row-left {
            padding-left: 22px;
            width: 100px;
            display: block;
            float: left;
        }

        .row-input .row-right {
            width: auto;
            display: inline-block;
        }

        .red-must-edit {
            color: red;
        }

        .genderradio {
            margin: 0px 5px 5px 35px;
        }

        .btn-short {
            width: 80px;
            height: 40px;
            line-height: 40px;
            font-size: 20px;
            color: white;
            border-radius: 5px;
            display: inline-block;
            cursor: pointer;
            text-align: center;
        }
        .btn-short:hover {
            opacity: 0.9;
        }

    </style>
<script>
function getQueryString(url,name) {
	    var i=url.lastIndexOf('?');
	    if(i==-1)return;
	    var querystr=url.substr(i+1);
	    var arr1=querystr.split('&');
	    var arr2=new Object();
	    for  (i in arr1){
	        var ta=arr1[i].split('=');
	        arr2[ta[0]]=ta[1];
	    }
	    return arr2[name];
}
</script>
</head>
<body class="easyui-layout" fit="true">
    <div region="north" style="height: 100px; border-bottom: 0;">
        <script>
            document.write(addHead('CPS联盟管理', 'CPS消息管理'));
        </script>
    </div>
    <div region="center" style="margin: 10px;border: 1px solid #D7D7D7;">
        <form id="activityEditForm" name="activityEditForm" method="post">
            <div class="row-input">
                <div class="row-left">
                    消息内容<span class="red-must-edit">*</span>
                </div>
                <div class="row-right">
                    <input class="easyui-textbox" id="content" name="content" style="width:500px">
                </div>
            </div>
            <div class="row-input">
                <div class="row-left">
                    消息图片<span class="red-must-edit">*</span>
                </div>
                <div class="row-right">
                    <div id="messageImage" style='position: relative;top:15px;'></div>
                </div>
            </div>
            <div class="row-input">
                <div class="row-left">
                    链接url<span class="red-must-edit">*</span>
                </div>
                <div class="row-right">
                    <input id="url" name="url" class="easyui-textbox" style="width:500px">
                </div>
            </div>
            <div class="row-input">
                <div class="row-left">
                    优先级<span class="red-must-edit">*</span>
                </div>
                <div class="row-right">
                    <input id="priority" name="priority" class="easyui-textbox" style="width:100px"><font color="gray">数字越大,优先级越高</font>
                </div>
            </div>
            <div class="row-input">
                <div class="row-left">
                    有效时间<span class="red-must-edit">*</span>
                </div>
                <div class="row-right">
                    <input id="startTime" name="startTime" class="easyui-datetimebox" style="width:180px">
                    ~&nbsp;&nbsp;<input id="endTime" name="endTime" class="easyui-datetimebox" style="width:180px">
                </div>
            </div>

            <div id="el"></div>

            <div class="sub-title" style="border-left: 0px; border-right: 0; height: 80px; line-height:80px;margin-top: 30px;margin-bottom: 10px;text-align: center;">
                <div id="cancelBtn" class="btn-short" style="background-color: #42A9CA;">取消</div>
                <div id="submitBtn" class="btn-short" style="background-color: #5CB85C;margin-left: 20px;">提交</div>
            </div>

        </form>

    </div>
<script>
    function initForm(){
    	var param=window.location.search;
        var id = getQueryString(param, "id");
    	$.post(contextPath + "/UnionShareRest/getMessageById", {
            id : id
        }, function(data) {
            if (data.code == 200) {
                $("#content").textbox("setValue",data.data.content);
                $("#url").textbox("setValue", data.data.url);
                $("#priority").textbox("setValue", data.data.priority);
                $("#startTime").datetimebox("setValue", data.data.startTimeStr);
                $("#endTime").datetimebox("setValue", data.data.endTimeStr);
                $("#messageImage").imageUpload({
                	width:500,
        			heigth:50,
        			realInputName : "unionShareMessagePic",
        			value: data.data.image,
        			url:contextPath + '/fileupload/upload',
        			queryParams : {
        				bucket : "unionimg"
        			},
        			filterFileName : function(data) {
        				if (!data || data.code != 200) {
        					$.messager.alert("失败", data.message, "error");
        				}
        				return data.data;
        			}
                });
            }else {
            	window.self.$.messager.alert("失败", "失败!", "error");
            }
        });
    }
    
    $(function () {
    	initForm();
    	
    	$("#cancelBtn").click(function () {
            $.messager.confirm("确认", "您确定要取消更新信息吗?", function(flag) {
                if (flag) {
                    window.location.href = contextPath + "/html/unionshare/unionShareMessageList.html";
                }
            });
        });
        
        $("#submitBtn").click(function () {
        	var param=window.location.search;
            var id = getQueryString(param, "id");
            var requestObj = {};
            requestObj.id = id;
            var content = $("#content").val();
            if (content == "") {
                alert("消息内容不能为空");
                $("#content").focus();
                return;
            } 

            requestObj.content = content;

            var arr = document.getElementsByName("unionShareMessagePic");
            if(undefined != arr[0]){
            	var image = arr[0].value;
                if (image == "") {
                    alert("请上传消息图片");
                    return;
                }
                requestObj.image = image; 
            }
            
            var url = $("#url").val();
            if (url == "") {
                alert("链接url不能为空");
                $("#url").focus();
                return;
            } 

            requestObj.url = url;
            
            var priority = $("#priority").val();
            if (priority == "") {
                alert("优先级不能为空");
                $("#priority").focus();
                return;
            } 

            requestObj.priority = priority;

            var startTime = $("#startTime").datetimebox("getValue");
            if (startTime == "") {
                alert("有效开始时间不能为空");
                $("#startTime").click();
                return;
            }
            requestObj.startTime = parseInt(new Date($("#startTime").datetimebox('getValue')).getTime() / 1000);

            var endTime = $("#endTime").datetimebox("getValue");
            if (endTime == "") {
                alert("有效结束时间不能为空");
                $("#endTime").click();
                return;
            }
            requestObj.endTime = parseInt(new Date($("#endTime").datetimebox('getValue')).getTime() / 1000)

            if (requestObj.startTime > requestObj.endTime) {
                alert("开始时间不能大于结束时间");
                return;
            }

            $.ajax({
                url: contextPath + '/UnionShareRest/updateMessage',
                type: "POST",
                contentType: "application/json",
                async: false,
                data: JSON.stringify(requestObj),
                success: function (data) {
                	if(data.code==200){
                		alert('保存成功');
                        window.location.href = contextPath + "/html/unionshare/unionShareMessageList.html";
                	}else{
                		alert('保存失败');
                	}
                    
                }
            });
        });
    	
    });
    
    
</script>
</body>

</html>