publishArticle.html 13 KB
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8" />
    <title>Yoho!Buy运营平台</title>
    <script src="/pfcms/js/include.js"></script>
    <script src="/pfcms/js/ajaxfileupload.js"></script>
    <style>
        .btn-long {
            width: 120px;
            height: 37px;
            line-height: 37px;
            font-size: 15px;
            color: white;
            border-radius: 5px;
            display: inline-block;
            cursor: pointer;
            text-align: center;
        }
        .btn-long:hover {
            opacity: 0.9;
        }

    </style>
</head>
<body class="easyui-layout" >
<div  region="north" style="height: 100px;">
    <script>
        document.write(addHead('运营管理', '种草内容发布'));
    </script>

</div>
<div region="center" id="labelGroupList" style="margin-left: 20px">
    <div id="tt" class="easyui-layout" fit="true" style="overflow-y: scroll">
        <form name="publishArticleForm" id="publishArticleForm" method="post"   >
            <div style="margin-top: 20px;margin-left: 30px">
                <table border="0" style="width:95%;margin-top:5px;line-height:30px;" id="tab">

                    <tr style="height: 60px">
                        <td >
                            <span style="color:red">*</span><label>选择用户</label>  <br>
                            <input id="articleUid" name="authorUid" style="width:60% "  class="easyui-combobox" />
                        </td>
                    </tr>

                    <tr style="height: 60px">
                        <td>
                            <span style="color:red">*</span><label>文字内容</label> <br>
                            <textarea rows="2" id="content" style="width:60% " name = "content" class="form-control" placeholder="" required="" maxlength="145"></textarea>                        </td>
                    </tr>

                    <tr style="height: 60px">
                        <td>
                            <span style="color:red">*</span><label>选择话题</label> <br>
                            <input id="topic" name="topicId" class="easyui-combobox" style="width:60% "/>
                        </td>
                    </tr>
                    <tr style="height: 20px">
                        <td >
                            <span style="color:red">*</span><label>选择图片</label>
                            <a id="addImage" class="btn-default" >选择图片+</a>
                            <input id="imgs" name="articleImages" hidden="hidden"/>
                        </td>
                    </tr>
                    <tr style="height: 60px">
                        <td id="imgTd">
                            <div id="imageUpload1">
                            </div>
                        </td>
                    </tr>
                    <tr style="height: 60px">
                        <td>
                            <span style="color:red">*</span><label>关联商品</label> <br>
                            <a id="addSkn" class="btn-primary"  onclick="getEditDialog()" style="font-size: 15px">新增商品+</a>
                            <input id="skns" name="articleSkns" hidden="hidden"/>
                        </td>

                    </tr>
                    <tr style="height: 60px">
                        <td id="goodstd">
                            <div id="good0" style="float: left;margin-left: 30px;width: 150px;">

                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td  valign="bottom">
                            <input  id="subBotton" class="btn-primary" type="button"  style="font-size: 20px; margin-top: 0px;margin-bottom: 0px;" value="保存"/>
                        </td>
                    </tr>
                </table>
            </div>
        </form>

    </div>

</div>



</body>
<script>
    var count = 1;
    var checkedItems = [];
    var checkedItemsObj = {};
    $(function () {

        $("#articleUid").combobox({
            required: true,
            missingMessage: "发布用户不能为空",
            prompt: "请输入发布用户",
            selectOnNavigation : true,
            valueField: 'text',
            textField: 'value',
            url : serverContextPath + "/grassArticle/platPublishUser",
            loadFilter: function (data) {
                var list = [];
                var obj = {};
                debugger;
                for (var i = 0; i < data.data.length; i++) {
                    obj['text'] = data.data[i];
                    obj['value']  = data.data[i];
                    list.push(obj);
                }
                return list;
            }
        });

        $("#topic").combobox({
            prompt: "请选择话题",
            required: true,
            selectOnNavigation : true,
            valueField: 'id',
            textField: 'topicName',
            url : serverContextPath + "/grassTopicManage/getAllTopic",
            loadFilter: function (data) {
                return defaultLoadFilter(data);
            }
        });
        initimg();

        $("#subBotton").linkbutton({
            iconCls: "icon-save",
            onClick: function () {
                $("#publishArticleForm").form("submit",{
                    url : serverContextPath+"/grassArticle/publishArticle",
                    onSubmit : function(param) {
                        debugger;
                        if (!$("#publishArticleForm").form("validate")) {
                            return false;

                        }
                        if($("#articleUid").combobox("getValue") == ''){
                            return false;
                        }
                        var imgs = '';
                        $("input[name='url']").each(function(j,item){
                            debugger
                            var url = item.value;
                            if(imgs == ''){
                                imgs = url;
                            }else{
                                imgs = imgs + ","+url;
                            }
                        });
                        $("#imgs").val(imgs);
                        return true;
                    },
                    success : function(data) {
                        if (data) {
                            data = $.parseJSON(data);
                            if (data.code == 200) {
                                alert('保存成功');
                                window.location.reload();

                            } else {
                                $.messager.alert("保存失败", data.message, "error");
                            }
                        } else {
                            $.messager.alert("保存失败", data.message, "error");
                        }
                    }
                });

            }
        });
    });




    // 编辑分组
    function getEditDialog(data){
        var labelGroupList = $("<div id='labelGroupList'>").appendTo($(document.body));
        var title =  "新增商品";
        var textVar = "确认";
        var msgVar =  "确认新增吗?";

        window.self.paramObject.mkData = data;
        $(labelGroupList).myDialog({
            title: title,
            width: "70%",
            height: "80%",
            resizable:false,
            buttons:[{
                id : "saveBtn",
                text:textVar,
                iconCls : "icon-save",
                handler:function(){
                    debugger;
                    $("#goodstd").html("<div id=\"good0\" style=\"float: left;margin-left: 30px;width: 300px\">\n" +
                        "                            </div>");
                    var skns = '';
                    for (var i = 0; i < checkedItems.length; i++) {
                        buildgood(i,checkedItems[i]);
                        if( i == checkedItems.length -1){
                            skns = skns+ checkedItems[i]
                        }else{
                            skns = skns+ checkedItems[i] +","
                        }
                    }
                    $("#skns").val(skns);
                    $(labelGroupList).dialog("close");
                }
            }, {
                text: "关闭",
                iconCls: "icon-cancel",
                handler: function () {
                    $.messager.confirm("确认", "确认关闭吗?", function (flag) {
                        if(flag){
                            $(labelGroupList).dialog("close");
                        }
                    });
                }
            }],
            modal: true,
            href: contextPath + "/html/grass/article/chooseSkns.html"
        });
    }

    function oo(num){
        // debugger
        if(num >9){
            return
        }
        $("#imageUpload"+num).imageUpload({
            width: 171,
            height: 120,
            realInputName: "url",
            url: serverContextPath + '/fileupload/uploadFile',
            queryParams: {
                bucket: "grassImg"
            },
            onBeforeSubmit: function () {
                $.messager.progress({
                    title: "正在执行",
                    msg: "正在执行,请稍后...",
                    interval: 500,
                    text: ""
                });
            },
            filterFileName: function (data) {
                debugger;
                if (!data || data.code != 200) {
                    $.messager.progress("close");
                    $.messager.alert("错误",data.message);
                    return "";
                }
                return data.data.url;
            },
            onLoadSuccess: function (data) {
                debugger;
                $.messager.progress("close");
                return false;
            }
        });
    }
    function initimg() {
        for (var i =1 ; i<=9; i++){
            var nnum = i+1;
            $("#imageUpload"+i).after('<div id="imageUpload'+nnum+'">  </div>');
            count = count+1;
            oo(i);
        }
    }

    function buildgood(index,obj) {
        debugger;
        var data = checkedItemsObj[obj];
        $("#good"+index).html(gooddiv(data));
        $div = $("#good"+(index+1));
            $("#good"+index).after('<div id="good'+(index+1)+'"style="float: left;margin-left: 30px;width: 300px">  </div>');
    }
    function gooddiv(data) {

        return "  <span>商品图:<img width=\"120\" height=\"60\" src="+getImageUrl(data.default_images)+
            "                               /> </span>" +
            "<h5 style=\"margin-top: 0px;margin-bottom: 0px\">商品名:"+ data.product_name +"</h5>\n" +
            "<h5 style=\"margin-top: 0px;margin-bottom: 0px\">价格:"+data.sales_price+"</h5>"
    }

    function getImageUrl(image) {
        var result='';
        if (image) {
            if(image.indexOf('http://') == 0){
                result = image.split("?")[0];
            }else{
                var fileMode = image.substring(15, 17);
                if(fileMode=='01'){
                    result= "http://"+"img11.static.yhbimg.com"+"/goodsimg"+image;
                }
                if(fileMode=='02'){
                    result= "http://"+"img12.static.yhbimg.com"+"/goodsimg"+image;
                }
            }
        }
        else {
            result = ""
        }
        if (result) {
            return result + "?imageMogr2/thumbnail/320x320/extent/320x320/background/d2hpdGU=/position/center/quality/90";
        } else {
            return "";
        }
    }
    function findCheckedItem(ID) {
        for (var i = 0; i < checkedItems.length; i++) {
            if (checkedItems[i] == ID) return i;
        }
        return -1;
    }
    function addcheckItem() {
        var i=0;
        $("input[type='checkbox'][name='product_skn']:checked").each(function () {
            if(i > 7){
                alert("最多只能选择八个商品");
                return false;
            }
            var k = findCheckedItem($(this).val());
            if (k == -1) {
                checkedItems.push($(this).val());
            }
            i++;

        });
    }

    function removeAllItem(rows) {
        $("input[type='checkbox'][name='product_skn']").each(function () {
            if (!this.checked) {
                var k = findCheckedItem($(this).val());
                if (k != -1) {
                    checkedItems.splice(k, 1);
                }
            }
        });
    }
    function resetSelectedCheckBox(data){
        $("input[type='checkbox'][name='product_skn']").each(function () {
            var cb=$(this);
            $.each(checkedItems,function(index,value){
                if(value==cb.val()){
                    cb.attr("checked",true);
                    return false;
                }
            });
        });
    }
    function removeSingleItem(rowIndex, rowData) {
        var k = findCheckedItem(rowData.product_skn);
        if (k != -1) {
            checkedItems.splice(k, 1);
        }
    }
</script>
</html>