码迷,mamicode.com
首页 > 其他好文 > 详细

20150728

时间:2015-07-28 20:34:40      阅读:124      评论:0      收藏:0      [点我收藏+]

标签:

var sg_price_limit; // 报价限制
var selectPicArray = new Array(); //已选择图片列表
/**
* 促销车型-图片弹窗车系列表
* @param manufacturerId 页面存放厂商的select标签的ID
* @param serialGroupId 页面存放车系的select标签的ID
*/

//检测字数
function countTxt(val) {
    var len = val.length;
    var count = 0;
    for (i = 0; i < len; i++) {
        if (isChinese(val.charAt(i))) {
            count++;
        } else if (isSpace(val.charAt(i))) {
            if (!isSpace(val.charAt(i - 1))) {
                count += 0.5;
            }
        } else {
            count += 0.5;
        }
    }
    return count;
}
/**
* 是否空格
* @param str
* @returns {boolean}
*/
function isSpace(str) {
    var regex = /[\s|\u3000]/;
    return regex.test(str);
}
//是否中文字符
function isChinese(str) {
    var regex = /[^\u4E00-\u9FA5]/g;
    return ! regex.test(str);
}
//检查标题输入长度
function checkCount(obj, limit, num_obj) {
    var len = countTxt(obj.value);
    var num_obj = document.getElementById(num_obj);
    if (len > limit) {
        num_obj.innerHTML = len;
        return false;
    } else {
        num_obj.innerHTML = len;
        return true;
    }
}
/**
* 生成弹窗图片车型下拉框
*/
function getPicModelList() {
    var serialGroupId = $("#serialGroupId").val();
    $.getJSON(‘/dealer/admin2013/action/info_center/do_hq_news.jsp?method=_getmodels&source=2&serialGroupId=‘ + serialGroupId,
    function(data) {
        var shtml = ‘<option value="">所有车型</option>‘;
        for (var i = 0; i < data.length; ++i) {
            var o = data[i];
            shtml += ‘<option value="‘ + o.id + ‘">‘ + o.name + ‘</option>‘;
        }
        $("#picModelId").html(shtml);
        getPicList("init");
    });
}
//查询图片列表
function getPicList(method) {
    var modelId = $("#picModelId").val();
    var serialGroupId = $("#serialGroupId2").val();
    if (method == "change") {
        if (selectPicArray.length > 0) {
            //清空已经选择图片
            resetPicList();
        }
    }
    $.getJSON(‘/dealer/admin2013/action/info_center/do_hq_news.jsp?method=_getmodelpics&modelId=‘ + modelId + "&serialGroupId=" + serialGroupId,
    function(data) {
        var ret = data.photoMap;
        if (data.size > 0) {
            for (var p in ret) {
                var photoList = ret[p];
                var shtml = ‘‘;
                if (photoList.length <= 0) {
                    shtml = ‘<p style="margin:30px 240px;font-size:13px;color:#333;">抱歉,该车型暂无可选图片。</p>‘;
                    $("#picBox_" + p).html(replaceAll(shtml));
                }
                for (var i = 0; i < photoList.length; i++) {
                    var pic = photoList[i];
                    var smthumb = ‘‘;
                    if (pic.bigThumb.indexOf(".jpg") > -1) {
                        smthumb = pic.bigThumb.replace(/[.]jpg/i, "_120x90.jpg");
                    } else if (pic.bigThumb.indexOf(".JPG") > -1) {
                        smthumb = pic.bigThumb.replace(/[.]JPG/i, "_120x90.JPG");
                    } else if (pic.bigThumb.indexOf(".png") > -1) {
                        smthumb = pic.bigThumb.replace(/[.]png/i, "_120x90.png");
                    } else if (pic.bigThumb.indexOf(".gif") > -1) {
                        smthumb = pic.bigThumb.replace(/[.]gif/i, "_120x90.gif");
                    }
                    shtml += ‘<li id="choosePic_1_‘ + pic.id + ‘"><a href="javascript:selectPic(‘ + pic.id + ‘,\‘\‘,1);"><img id="pic_1_‘ + pic.id + ‘" src="‘ + smthumb + ‘" width="120" height="90" alt="‘ + pic.name + ‘" /></a></li>‘;
                }
                if (shtml != ‘‘) {
                    $("#picBox_" + p).html(replaceAll(shtml));
                } else {
                    $("#picBox_" + p).html(replaceAll(‘<p style="margin:30px 240px;font-size:13px;color:#333;">抱歉,该车型暂无可选图片。</p>‘));
                }
                if (method == "init") {
                    var defPhotoList = data.defPhotoList;
                    setTimeout(function() {
                        for (var i = 0; i < defPhotoList.length; i++) {
                            var p = defPhotoList[i];
                            selectDefaultPic(p.id, "", 1, i);
                        }
                    },
                    50);
                } else {
                    var defPhotoList = data.defPhotoList;
                    setTimeout(function() {
                        for (var i = 0; i < defPhotoList.length; i++) {
                            var p = defPhotoList[i];
                            selectDefaultPic(p.id, "", 1, i);
                        }
                    },
                    50);
                }
            }
            //选中车型
            setTimeout(function() {
                showTargetPics(0, "confirm");
            },
            50);
        } else {
            if (method == "init") {}
            shtml = ‘<p style="margin:30px 240px;font-size:13px;color:#333;">抱歉,该车型暂无可选图片。</p>‘;
            $("#picBox_31").html(replaceAll(shtml));
            $("#picBox_1").html(replaceAll(shtml));
            $("#picBox_2").html(replaceAll(shtml));
            $("#picBox_8").html(replaceAll(shtml));
            $("#picBox_3").html(replaceAll(shtml));
        }
        //车型图片提示
        $("#picModelId").find("option[value=‘" + data.modelId + "‘]").attr("selected", true);
        $("#picModelTips").html("<i class=‘icon‘></i>当前图示车型为:" + data.modelName + ",如果切换车型将清空所有已选图片。");
        $("#picModelTips").show();
    });
}
/**
* 图片后辍名替换
* @param bigThumb
* @returns {*}
*/
function changePicPath(bigThumb) {
    if (bigThumb.indexOf(".jpg")) {
        bigThumb = bigThumb.replace(".jpg", "_120x90.jpg");
    }
    if (bigThumb.indexOf(".JPG")) {
        bigThumb = bigThumb.replace(".JPG", "_120x90.JPG");
    }
    if (bigThumb.indexOf(".png")) {
        bigThumb = bigThumb.replace(".png", "_120x90.png");
    }
    if (bigThumb.indexOf(".PNG")) {
        bigThumb = bigThumb.replace(".PNG", "_120x90.PNG");
    }
    if (bigThumb.indexOf(".gif")) {
        bigThumb = bigThumb.replace(".gif", "_120x90.gif");
    }
    if (bigThumb.indexOf(".GIF")) {
        bigThumb = bigThumb.replace(".GIF", "_120x90.GIF");
    }
    return bigThumb;
}
/**
* 加载默认5张图片
* @param picId 图片ID
* @param src 图片链接
* @param type 图片来源
* @param seq 图片位置
*/
function selectDefaultPic(picId, src, type, seq) {
    var picSrc = $("#pic_" + type + "_" + picId).attr("src");
    if (typeof(picSrc) == "undefined" || picSrc == "") {
        picSrc = src;
    }
    var pic = new PicInfo(picId, picSrc, seq, type);
    if (typeof(picSrc) != "undefined") {
        selectPicArray[seq] = pic;
    }
}
/**
* 选择图片
* @param picId
* @param type 图片类型(1:图库,2:用户上传)
*/
function selectPic(picId, src, type) {
    //去掉所有打勾样式
    clearChoosePic();
    //选中当前的图片
    setPicSelected(picId, type);
    var picSrc = $("#pic_" + type + "_" + picId).attr("src");
    if (typeof(picSrc) == "undefined" || picSrc == "") {
        picSrc = src;
    }
    var pic = new PicInfo(picId, picSrc, _CURPICINDEX, type);
    if (typeof(picSrc) != "undefined") {
        selectPicArray[_CURPICINDEX] = pic;
    }
}
//将已选图片打勾
function setPicSelected(picId, type) {
    $("#choosePic_" + type + "_" + picId).append(‘<i class="bg"></i><i class="icon"></i>‘);
}
//图片弹窗确认按钮
$("#picSureBtn").click(function() {
    showTargetPics(1, ‘sure‘);
});
$("#uploadSureBtn").click(function() {
    showTargetPics(1, ‘sure‘);
});
//图片弹窗取消按钮
$("#cancelBtn").click(function() {
    showTargetPics(1, ‘cancel‘);
});
$("#uploadCancelBtn").click(function() {
    showTargetPics(1, ‘cancel‘);
});
/**
* 从图片数组中的图片设置在页面5个图片框中展示
* @param isClose 是否要关闭弹窗:1关闭,0:不关闭
*/
function showTargetPics(isClose, method) {
    var length = selectPicArray.length;
    if (isClose == 1) {
        //关闭弹层
        $.unblockUI();
    }
    //去掉所有打勾样式
    clearChoosePic();
    if (length > 0 && length <= 5) {
        var isFull = true; //是否满5张图片
        if (method != ‘cancel‘) {
            for (var i = 0; i < length; i++) {
                var pic = selectPicArray[i];
                if (pic != null) {
                    //插入图片在指定位置
                    var picHtml = ‘<a href="javascript:void(0);" rel="‘ + pic.id + ‘" typ="‘ + pic.type + ‘" onclick="editPic(‘ + pic.id + ‘,‘ + pic.seq + ‘,‘ + pic.type + ‘);"><img width="120" height="90" src="‘ + pic.src + ‘" alt="图片‘ + (i + 1) + ‘"/>‘ + ‘<p class="change"><i>更改图片</i></p></a>‘;
                    $("#targetPic_" + i).html(picHtml);
                }
            }
        } else {
            for (var i = 0; i < length; i++) {
                var pic = selectPicArray[i];
                if (pic == null) {
                    var typ = $("#targetPic_" + i + " a").attr("typ");
                    var picId = $("#targetPic_" + i + " a").attr("rel");
                    var picSrc = $("#targetPic_" + i + " a img").attr("src");
                    if (picId > 0) {
                        pic = new PicInfo(picId, picSrc, i, typ);
                        selectPicArray[i] = pic;
                    } else {
                        isFull = false;
                    }
                }
            }
        }
        //选择图片小于5张要显示提示
        if (!isFull) {
            $("#picWarnMsg").show();
        } else {
            $("#picWarnMsg").hide();
        }
    }
}
var _CURPICINDEX = 0; //当前是第几个图片框
/**
* 更改图片
* @param picId
* @param seq 图片位置顺序
* @param type
*/
function editPic(picId, seq, type) {
    popDialogPic();
    _CURPICINDEX = seq;
    if (picId > 0) {
        //去掉所有打勾样式
        clearChoosePic();
        //添加打勾
        $("#choosePic_" + type + "_" + picId).append(‘<i class="bg"></i><i class="icon"></i>‘);
    }
}
/**
* 清空已选图片列表
*/
function resetPicList() {
    //清空打勾图片样式
    var length = selectPicArray.length;
    for (var i = 0; i < length; i++) {
        var pic = selectPicArray[i];
        if (pic != null) {
            selectPicArray[i] = null;
        }
    }
    //清空已选图片数组
    selectPicArray.length = 0;
    //清空已选图片
    for (var i = 0; i <= 4; i++) {
        $("#targetPic_" + i).html(‘<a href="javascript:void(0);" onclick="editPic(0,‘ + i + ‘,1);"><img width="120" height="90"  src="http://www1.pcauto.com.cn/20130428/houtai/images/addIcon.png"><p class="change"><i>更改图片</i></p></a>‘);
    }
}
/**
* 清除所有打勾样式
*/
function clearChoosePic() {
    $("li[id^=‘choosePic_‘]").each(function() {
        $(this).children("i").remove();
    });
}
//绑定添加图片事件
$("#targetPic_4").click(function() {
    popDialogPic();
});
/**
* 弹出图片弹窗
*/
function popDialogPic() {
    var h = parseInt($("#JuploadPop").height());
    $.blockUI({ //当点击事件发生时调用弹出层
        message: $(‘#JuploadPop‘),
        //要弹出的元素box
        css: { //弹出元素的CSS属性
            textAlign: ‘left‘,
            border: ‘none‘,
            background: ‘none‘,
            top: ($(window).height() - h) / 2 + ‘px‘,
            left: ($(window).width() - 721) / 2 + ‘px‘
        }
    });
}
//修改行情时需初始化数据
//修改时选上已报价车型
function setSelectedModel(num) {
    var selectModelId = 0;
    var typ = 0;
    var discountType = 0;
    var discountPrice = 0;
    var isReplace = 0;
    var carField = $("#serialGroupId").find("option:selected").attr("rel"); //1为海外,其他它视为非海外
}
/**
* 修改时让礼包内容选中
*/
function initGiftPackage() {
    var gifts = "";
    var otherGifts = "";
    if (gifts != ‘‘) {
        var gift = new Array();
        gift = gifts.split("+");
        for (var i = 0; i < gift.length; i++) {
            var all = document.getElementsByName("gift");
            for (var j = 0; j < all.length; j++) {
                var val = all[j].value
                if (gift[i] == val) {
                    all[j].checked = true;
                    break;
                }
            }
        }
    }
    if (otherGifts != ‘‘) {
        var otherGift = new Array();
        otherGift = otherGifts.split("+");
        var otherGiftHtml = ‘‘;
        for (var i = 0; i < otherGift.length; i++) {
            var val = otherGift[i];
            otherGiftHtml += ‘<label><input name="otherGift" type="checkbox" checked="checked" value="‘ + val + ‘"/> ‘ + val + ‘</label>‘;
        }
        $("#giftConfig").append(otherGiftHtml);
    }
}
/**
* 单个操作现车情况重新生成标题
*/
function changeModelStatus(index, modelId) {
    setSelect(index, modelId);
    reBuildDefaultTitle();
}
/**
* 重新生成标题及内容
*/
function reBuildDefaultTitle() {
    if ($("#textType1").attr("checked")) {
        //重新生成标题
        buildDefaultTitle();
    }
    //检查推送功能隐藏显示
    if ($("#luoChe").attr("checked")) {
        var isSelectModel = false;
        $("input[id^=‘chxModel_‘]:checked").each(function() {
            isSelectModel = true;
        });
        if (isSelectModel) {
            $("#tuiSong").show();
        } else {
            $("#tuiSong").hide();
            $("#ts1").attr("checked", false);
        }
    } else {
        $("#tuiSong").hide();
        $("#ts1").attr("checked", false);
    }
}
//促销文案标题-默认模板部分-开始
/**
* 生成默认标题
*/
function buildDefaultTitle() {
    var serialGroupId = $("#serialGroupId").val();
    if (serialGroupId == "") {
        $("#serialGroupTips").show();
        return false;
    }
    var sgName = $("#serialGroupId").find("option:selected").text(); //车系名称
    var carField = $("#serialGroupId").find("option:selected").attr("rel"); //车系产地【0:无(针对概念车、假想车),1:海外,2:进口,3:自主,4:合资】
    var TITLE_TEMPLATE = "[SERIALGROUPNAME][DECLINE][ADDMODEL][MODELSTATUS]"; //车系标题模板 [车系名]+[优惠幅度]+空格+[现车情况] / [车系名]+[售价信息]+[现车情况]
    var modelStatusTxt = "";
    var discountTxt = "";
    if ($("#luoChe").attr("checked")) {
        var highDiscount = 0;
        var minPrice = 10000; //最低价
        var modelStatuss = ""; //现车情况字符串
        var isReplace = false; //是否包含置换购物优惠
        var isSelectReplace = false; //是否选中的车型有勾选置换优惠
        var isAllEqual = true; //是否所有优惠都一致
        var highTypeId = 0; //最高价格的类型ID
        var highModelId = 0; //最高价格的车型ID
        var isSelectedModel = false; //是否有勾选车型
        $("input[id^=‘year_‘]:checked").each(function() {
            var type = $(this).val();
            $("input[id^=‘chxModel_" + type + "_‘]:checked").each(function() {
                isSelectedModel = true;
                var v = $(this).val();
                var mId = v.split(‘_‘)[1];
                if (carField != 1) {
                    var unit = $("#option_" + type + "_" + mId).val();
                    if (unit == "") {
                        unit = 1;
                    }
                    var discount = $("#mDiscount_" + type + "_" + mId).val();
                    if (discount == "") {
                        discount = 0;
                    }
                    var price = $("#mGfPrice_" + type + "_" + mId).val();
                    if (unit == 2) { //折扣时需要换算
                        discount = (Math.floor((price * (10 - discount) * 0.1) * 100) / 100).toFixed(2);
                    }
                    if (highDiscount == 0) { //首次进来最大值肯定是为0的,所以初始化最大值为第1个值
                        highDiscount = discount;
                    }
                    if (parseFloat(highDiscount) != parseFloat(discount)) {
                        isAllEqual = false;
                    }
                    if ($("#replace_" + type + "_" + mId).attr("checked")) { //有选中的车型勾选置换优惠
                        isSelectReplace = true;
                    }
                    if (parseFloat(discount) >= parseFloat(highDiscount)) {
                        highDiscount = discount;
                        highTypeId = type;
                        highModelId = mId;
                    }
                } else { //海外车系
                    var discount = $("#mDiscount_" + type + "_" + mId).val();
                    if (parseFloat(discount) < minPrice) {
                        minPrice = discount;
                    }
                }
                var mStatus = 1;
                if ($("#type2_" + type + "_" + mId).attr("checked")) {
                    mStatus = 2;
                }
                if ($("#type3_" + type + "_" + mId).attr("checked")) {
                    mStatus = 3;
                }
                modelStatuss += mStatus + "_";
            });
        });
        modelStatusTxt = "";
        if (modelStatuss.indexOf("1") > -1) {
            modelStatusTxt = "现车充足";
        } else if (modelStatuss.indexOf("3") > -1) {
            modelStatusTxt = "有少量现车";
        } else if (modelStatuss.indexOf("2") > -1) {
            modelStatusTxt = "接受预订";
        }
        discountTxt = "";
        if (carField == 1) {
            if (minPrice > 0) {
                discountTxt = "现售" + minPrice + "万元起";
            }
        } else {
            if (highDiscount > 0) {
                discountTxt = "最高优惠" + highDiscount + "万 ";
            } else if (highDiscount == 0 && isSelectedModel) {
                discountTxt = "全系平价销售 ";
            }
        }
        if (isSelectReplace && isAllEqual) {
            isReplace = true;
        } else {
            //如果最高优惠的车型ID有选中置换优惠,则需要在文案内容中显示"置换"
            if ($("#replace_" + highTypeId + "_" + highModelId).attr("checked")) {
                isReplace = true;
            }
        }
    }
    var addModelTxt = "";
    var addModelDiscountTxt = "";
    if ($("#addModel").attr("checked")) {
        if (!$("#luoChe").attr("checked")) {
            discountTxt = "";
            addModelTxt = "部分加装车型现正促销中";
            modelStatusTxt = "";
        }
        var minAddModelPrice = 1000;
        var isAddModel = false; //是否有加装车
        $("#addModelMsg tr").each(function() {
            var addModelId = $(this).attr("rel");
            if (parseInt(addModelId) > 0) {
                isAddModel = true;
                var addPrice = parseFloat($("#addModelPrice_" + addModelId).html());
                if (minAddModelPrice > addPrice) {
                    minAddModelPrice = addPrice;
                }
            }
        });
        if (isAddModel) {
            addModelDiscountTxt = "另有部分增加了实用配置的车型低价销售,售价" + minAddModelPrice + "万元起。";
        }
    }
    TITLE_TEMPLATE = TITLE_TEMPLATE.replace("[SERIALGROUPNAME]", sgName);
    TITLE_TEMPLATE = TITLE_TEMPLATE.replace("[DECLINE]", discountTxt);
    TITLE_TEMPLATE = TITLE_TEMPLATE.replace("[MODELSTATUS]", modelStatusTxt);
    TITLE_TEMPLATE = TITLE_TEMPLATE.replace("[ADDMODEL]", addModelTxt);
    $("#defaultTitle").html(TITLE_TEMPLATE);
    $("#defaultTitle2").val(TITLE_TEMPLATE);
    buildDefaultContent(sgName, modelStatusTxt, $.trim(discountTxt), isReplace, addModelDiscountTxt);
}
/**
* 生成促销文案内容模板
* @param sgName 车系名称
* @param modelStatusTxt 现在状况
* @param discountTxt 优惠文本
* @param isReplace 是否有置换购车
* @param addModelDiscountTxt 加装车内容项
*/
function buildDefaultContent(sgName, modelStatusTxt, discountTxt, isReplace, addModelDiscountTxt) {
    var CONTENT_TEMPLATE = "[DEALER_SHORTNAME]店内[SERIALGROUPNAME][MODELSTATUS][RECENT][REPLACE][BUYCAR][DECLINE][GIFTPACKAGE][DOT][ADDMODELDISCOUNTTXT]感兴趣的朋友不妨拨打咨询热线[400PHONE]或到店咨询。相关车型及报价如下表:";
    var dealerShortName = ‘广州皇家锦龙奥迪‘;
    var phone400 = ‘--‘;
    CONTENT_TEMPLATE = CONTENT_TEMPLATE.replace("[400PHONE]", phone400);
    var giftPrice = $("#giftPrice").val();
    var giftPriceTxt = "";
    if (giftPrice != "" && $("#giftBtn").attr("checked")) {
        giftPriceTxt = ",同时赠送价值" + giftPrice + "元的大礼包";
    }
    var replaceTxt = "";
    if (isReplace) {
        replaceTxt = "置换";
    }
    if (replaceTxt == ‘‘ && giftPriceTxt == ‘‘ && discountTxt == ‘‘) {
        CONTENT_TEMPLATE = CONTENT_TEMPLATE.replace("[RECENT]", "");
        CONTENT_TEMPLATE = CONTENT_TEMPLATE.replace("[BUYCAR]", "");
        CONTENT_TEMPLATE = CONTENT_TEMPLATE.replace("[DOT]", "");
    } else {
        CONTENT_TEMPLATE = CONTENT_TEMPLATE.replace("[RECENT]", ",近期");
        CONTENT_TEMPLATE = CONTENT_TEMPLATE.replace("[BUYCAR]", "购车");
        CONTENT_TEMPLATE = CONTENT_TEMPLATE.replace("[DOT]", "。");
    }
    CONTENT_TEMPLATE = CONTENT_TEMPLATE.replace("[DEALER_SHORTNAME]", dealerShortName);
    CONTENT_TEMPLATE = CONTENT_TEMPLATE.replace("[SERIALGROUPNAME]", sgName);
    CONTENT_TEMPLATE = CONTENT_TEMPLATE.replace("[DECLINE]", discountTxt);
    CONTENT_TEMPLATE = CONTENT_TEMPLATE.replace("[REPLACE]", replaceTxt);
    CONTENT_TEMPLATE = CONTENT_TEMPLATE.replace("[GIFTPACKAGE]", giftPriceTxt);
    CONTENT_TEMPLATE = CONTENT_TEMPLATE.replace("[ADDMODELDISCOUNTTXT]", addModelDiscountTxt);
    CONTENT_TEMPLATE = CONTENT_TEMPLATE.replace("[MODELSTATUS]", modelStatusTxt);
    $("#defaultContent").html(CONTENT_TEMPLATE);
    $("#defaultContent2").val(CONTENT_TEMPLATE);
}
/**
* 生成行情短标题
*/
function genShortName() {
    var sgName = $("#serialGroupId").find("option:selected").text(); //车系名称
    var carField = $("#serialGroupId").find("option:selected").attr("rel"); //车系产地【0:无(针对概念车、假想车),1:海外,2:进口,3:自主,4:合资】
    if ($("#luoChe").attr("checked")) {
        var highDiscount = 0;
        var modelStatuss = ""; //现车情况字符串
        var isSelectedModel = false; //是否有勾选车型
        $("input[id^=‘year_‘]:checked").each(function() {
            var type = $(this).val();
            $("input[id^=‘chxModel_" + type + "_‘]:checked").each(function() {
                isSelectedModel = true;
                var v = $(this).val();
                var mId = v.split(‘_‘)[1];
                if (carField != 1) {
                    var unit = $("#option_" + type + "_" + mId).val();
                    if (unit == "") {
                        unit = 1;
                    }
                    var discount = $("#mDiscount_" + type + "_" + mId).val();
                    if (discount == "") {
                        discount = 0;
                    }
                    var price = $("#mGfPrice_" + type + "_" + mId).val();
                    if (unit == 2) { //折扣时需要换算
                        discount = (price * discount * 0.1).toFixed(2);
                        discount = (price - discount).toFixed(2);
                    }
                    if (highDiscount == 0) { //首次进来最大值肯定是为0的,所以初始化最大值为第1个值
                        highDiscount = discount;
                    }
                    if (parseFloat(discount) >= parseFloat(highDiscount)) {
                        highDiscount = discount;
                    }
                }
                var mStatus = 1;
                if ($("#type2_" + type + "_" + mId).attr("checked")) {
                    mStatus = 2;
                }
                if ($("#type3_" + type + "_" + mId).attr("checked")) {
                    mStatus = 3;
                }
                modelStatuss += mStatus + "_";
            });
        });
        modelStatusTxt = "";
        if (modelStatuss.indexOf("1") > -1) {
            modelStatusTxt = "现车充足";
        } else if (modelStatuss.indexOf("3") > -1) {
            modelStatusTxt = "有少量现车";
        } else if (modelStatuss.indexOf("2") > -1) {
            modelStatusTxt = "接受预订";
        }
        discountTxt = "";
        var shortName = sgName;
        if (carField == 1) {
            $("#shortName").val(""); //生成短标题-为空
        } else {
            if (highDiscount > 0) {
                discountTxt = "最高优惠" + highDiscount + "万 ";
                shortName += "优惠" + highDiscount + "万";
            } else if (highDiscount == 0 && isSelectedModel) {
                discountTxt = "全系平价销售 ";
                if (modelStatuss.indexOf("2") > -1) {
                    shortName += "现接受预订";
                } else {
                    shortName += modelStatusTxt;
                }
            }
            $("#shortName").val(shortName); //生成短标题
        }
    }
}
//促销方案-默认模板部分-结束
/**
* 用户自定义上传模板
*/
function uploadCallback() {
    var uploadImg = $("#uploadImg").val(); //上传图片URL,不要随意调换位置
    $("#div_uploadImg").html("");
    var srcHtml = $("#uploadPics").html();
    var manufacturerId = $("#manufacturerId2").find("option:selected").val();
    var serialGroupId = $("#manufacturerId2").find("option:selected").val();
    $.post("/dealer/admin2013/action/info_center/do_dealer_photo.jsp", {
        method: "save",
        imgUrl: uploadImg,
        manufacturerId: manufacturerId,
        serialGroupId: serialGroupId
    },
    function(data) {
        var code = data.code;
        if (code < 0) {
            alert("参数异常");
        } else if (code > 0) {
            var imgId = code;
            var imgHtml = ‘<li id="choosePic_2_‘ + imgId + ‘">‘ + ‘<a href="javascript:selectPic(‘ + imgId + ‘,\‘\‘,2);">‘ + ‘<img id="pic_2_‘ + imgId + ‘" width="120" height="90"  src="‘ + uploadImg + ‘">‘ + ‘</a></li>‘;
            $("#uploadPics").html(imgHtml + srcHtml);
            $("#uploadImg").remove();
        }
    },
    "json");
}
/**
* 过滤特殊字符
*/
function filterSpecialChar(id) {
    var text = $("#" + id).val();
    $.getJSON("/dealer/admin2013/action/info_center/do_hq_news.jsp", {
        method: ‘filterSpecialChar‘,
        content: text
    },
    function(data) {
        if (data != null) {
            var IllegalTxt = data.content;
            if (IllegalTxt != ‘‘) {
                $("#" + id + "Tips").html(‘<i class="icon"></i>抱歉,您输入的内容中含有不允许使用的字符: ‘ + IllegalTxt + ‘ 请删除,谢谢!‘);
                $("#" + id + "Tips").css(‘display‘, ‘inline-block‘);
            } else {
                var len = parseInt(countTxt(text));
                if (len < 50 || len > 300) {
                    $("#" + id + "Tips").html(‘<i class="icon"></i>行情内容请控制在50-300个中文字符内‘);
                    $("#" + id + "Tips").show();
                } else {
                    $("#" + id + "Tips").hide();
                    $("#" + id + "Tips").html(‘<i class="icon"></i>请输入行情内容‘);
                }
            }
        }
    });
}
//执行切换类型操作
$("#luoChe").click(function() {
    if ($(this).attr("checked")) {
        var serialGroupId = $("#serialGroupId").val();
        if (serialGroupId > 0) {
            $("#luoCheTable").show();
        }
        $("#twoModelsTips").hide();
    } else {
        $("#luoCheTable").hide();
    }
    if ($("#tuiSong").is(":hidden")) {
        $("#tuiSong").show();
    }
    reBuildDefaultTitle();
});
//------加装车型模块 start ------
$("#addModel").click(function() {
    if ($(this).attr("checked")) {
        var serialGroupId = $("#serialGroupId").val();
        if (serialGroupId > 0) {
            $("#addModelBox").show();
        }
        $("#twoModelsTips").hide();
    } else {
        $("#addModelBox").hide();
    }
    if ($("#luoChe").attr("checked")) {
        var isSelectModel = false;
        $("input[id^=‘chxModel_‘]:checked").each(function() {
            isSelectModel = true;
        });
        if (isSelectModel) {
            $("#tuiSong").show();
        } else {
            $("#tuiSong").hide();
            $("#ts1").attr("checked", false);
        }
    } else {
        $("#tuiSong").hide();
        $("#ts1").attr("checked", false);
    }
    reBuildDefaultTitle();
});
//添加加装车型
function addAddModel() {
    // $(‘#JaddType‘).unbind().click(function(){ //给box_btn绑定一个鼠标点击的事件
    $("#chooseAddModel").hide();
    initAddModelBox("savedAddModelList", 0); //初始化已保存的加装车型列表
    var serialGroupId = $("#serialGroupId").val();
    var serialGroupName = $("#serialGroupId option[value = " + serialGroupId + "]").html();
    var manufacturerId = $("#manufacturerId").val();
    // $("#createModel").click(function(){
    $.post("add_model_pop.jsp", {
        "method": "create",
        "isShowTitle": "false",
        "isAjax": "true",
        "manufacturerId": manufacturerId,
        "serialGroupId": serialGroupId,
        "serialGroupName": serialGroupName
    },
    function(data) {
        //防止出现ID重复,清除另外一个弹框
        $("#JaddPriPop").empty();
        $("#createModelBox").html(data);
        $(this).attr("class", "toc seleced");
    });
    // });
    var h = parseInt($("#JaddTypePop").height());
    $.blockUI({ //当点击事件发生时调用弹出层
        message: $(‘#JaddTypePop‘),
        //要弹出的元素box
        css: { //弹出元素的CSS属性
            textAlign: ‘left‘,
            border: ‘none‘,
            background: ‘none‘,
            top: ($(window).height() - h) / 2 + ‘px‘,
            left: ($(window).width() - 721) / 2 + ‘px‘
        }
    });
    // });
}
//初始化加装车型列表
function initAddModelBox(boxArea, addMid) {
    var serialGroupId = $("#serialGroupId").val();
    var modelId = 0;
    var manufacturerId = $("#manufacturerId").val();
    if (boxArea == "") {
        serialGroupId = 0;
        manufacturerId = 0;
    }
    $.getJSON("/dealer/admin2013/action/info_center/do_model.jsp", {
        "serialGroupId": serialGroupId,
        "modelId": modelId,
        "emethod": "listAddModel",
        "manufacturerId": manufacturerId,
        "addMid": addMid
    },
    function(data) {
        var addModels = data.addModels;
        var htmlMsg = "";
        var savedHtmlMsg = "";
        for (var i = 0; i < addModels.length; i++) {
            var addModel = addModels[i];
            eval("config=" + addModel.config);
            var addConfig = config.addConfig.split("+");
            var otherConfig = config.otherConfig.split("+");
            var id = addModel.addModelId;
            var htmlMsgCol1 = "<tr id=‘addModelMsg_" + id + "‘ rel=‘" + id + "‘><td class =‘col col1‘><span>" + addModel.modelName + "</span></td>";
            var savedHtmlMsgCol1 = "<tr id=‘savedModelMsg_" + id + "‘><td class=‘col col1‘><span><input type=‘checkbox‘ value=‘" + id + "‘><label for=‘‘>" + addModel.modelName + "</label></span></td>";
            var modelMsg = "<td class=‘col col2‘><span id=‘modelPrice_" + id + "‘>" + addModel.price + "</span></td><td class=‘col col3‘><span id=‘addModelPrice_" + id + "‘>" + addModel.addPrice + "</span></td><td class=‘col col4‘><span class=‘deploy‘>";
            for (var j = 0; j < addConfig.length; j++) {
                var configMsg = " " + addConfig[j];
                modelMsg += configMsg;
            }
            for (var k = 0; k < otherConfig.length; k++) {
                var configMsg = " " + otherConfig[k];
                modelMsg += configMsg;
            }
            modelMsg += "</span></td>";
            var actionHtml = "<td class=‘col col5‘><span class=‘btns‘>" + "<a href = ‘javascript:;void(0);‘ onclick=‘updateAddModel(" + id + ");‘ class=‘editBtn blue‘>修改</a><a href = ‘javascript:;void(0)‘" + " onclick=‘deleteAddModel(" + id + ");‘ class=‘del blue‘>删除</a></span></td>";
            var blankHtml = "<td class=‘col col5‘></td>";
            htmlMsg += htmlMsgCol1 + modelMsg + actionHtml;
            savedHtmlMsg += savedHtmlMsgCol1 + modelMsg + blankHtml;
        }
        if (boxArea == "addModelList") {
            htmlMsg += "<tr id=‘addModelMsgBar‘><td colspan=‘5‘ class=‘addBtn‘><span id=‘JaddType‘>" + "<em class=‘dot‘>+</em>点击添加加装车型</span></td></tr>";
            $("#addModelMsg").empty().append(htmlMsg);
        } else if (boxArea == "savedAddModelList") {
            if (addModels.length == 0) {
                $("#noSavedAddModel").show();
            } else {
                $("#noSavedAddModel").hide();
            }
            $("#savedAddModel").empty().append(savedHtmlMsg);
            $("#chooseSavedModel").unbind().click(function() {
                initAddModelBox("savedAddModelList", 0); //初始化已保存的加装车型列表
                $(this).attr("class", "toc seleced");
            });
        } else {
            //异步刷新加装车型列表单条信息
            deleteAddModel(addMid);
            $("#addModelMsgBar").before(htmlMsg);
        }
        // addAddModel();
        addModelBoxWarn();
        reBuildDefaultTitle();
    });
}
//移除加装车型
function deleteAddModel(addModelId) {
    $("#addModelMsg_" + addModelId).remove();
    addModelBoxWarn();
    //重新生成标题
    reBuildDefaultTitle();
}
//修改加装车型
function updateAddModel(addModelId) {
    $.post("add_model_pop.jsp", {
        "addMid": addModelId,
        "isAjax": "true",
        "method": "update"
    },
    function(data) {
        $("#createModelBox").empty();
        $("#JaddPriPop").html(data);
    });
    showUpdateAddModelBox();
}
//至少添加一款加装车型提示
function addModelBoxWarn() {
    var length = $("#addModelMsg tr").length;
    if (length < 2) {
        //至少添加一款加装车型提示
        $("#addModelBoxWarn").show();
    } else {
        $("#addModelBoxWarn").hide();
    }
}
//保存加装车型信息到页面
function addModelMsg() {
    var checkedModel = $("#savedAddModel input[type=checkbox]:checked");
    if (checkedModel.length == 0) {
        $("#chooseAddModel").show();
        $("#noSavedAddModel").hide();
        return;
    }
    checkedModel.each(function() {
        var modelId = "addModelMsg_" + $(this).val();
        var isThere = $("#" + modelId).length; //如果列表已经存在,则不添加
        if (isThere == 0) {
            var modelName = $(this).next("label").html();
            var nameHtml = "<tr id=‘" + modelId + "‘ rel=‘" + $(this).val() + "‘><td class =‘col col1‘><span>" + modelName + "</span></td>";
            var trId = "savedModelMsg_" + $(this).val();
            var priceHtml = "<td class=‘col col2‘>" + $("#" + trId + " td:eq(1)").html() + "</td>";
            var addPriceHtml = "<td class=‘col col3‘ >" + $("#" + trId + " td:eq(2)").html() + "</td>";
            var configHtml = "<td class=‘col col4‘>" + $("#" + trId + " td:eq(3)").html() + "</td>";
            var actionHtml = "<td class=‘col col5‘><span class=‘btns‘>" + "<a href = ‘javascript:;void(0);‘ onclick=‘updateAddModel(" + $(this).val() + ");‘ class=‘editBtn blue‘>修改</a><a href = ‘javascript:;void(0)‘" + " onclick=‘deleteAddModel(" + $(this).val() + ");‘ class=‘del blue‘>删除</a></span></td>";
            var addModelHtml = nameHtml + priceHtml + addPriceHtml + configHtml + actionHtml;
            $("#addModelMsgBar").before(addModelHtml);
        }
    });
    addModelBoxWarn();
    $.unblockUI();
    reBuildDefaultTitle();
}
//------加装车型模块 end ------
$("#giftBtn").click(function() {
    if ($(this).attr("checked")) {
        $("#giftBox").show();
    } else {
        $("#giftBox").hide();
    }
    reBuildDefaultTitle();
});
$("#beiZhu").click(function() {
    if ($(this).attr("checked")) {
        $("#beiZhuBox").show();
    } else {
        $("#beiZhuBox").hide();
    }
});
//置换购车优惠
$("#inReplace").click(function() {
    if ($(this).attr("checked")) {
        $(".replace").show();
    } else {
        $(".replace").hide();
        $("input[id^=‘replace_‘]").attr("checked", false);
    }
    reBuildDefaultTitle();
});
$("#textType1").click(function() {
    if ($(this).attr("checked")) {
        buildDefaultTitle();
        $("#textBox1").show();
        $("#textBox2").hide();
        $("#textTypeTips").hide();
        $("#showTipId").hide();
    } else {
        $("#textBox1").hide();
    }
});
$("#textType2").click(function() {
    if ($(this).attr("checked")) {
        $("#textBox2").show();
        $("#textBox1").hide();
        $("#textTypeTips").html("注意:自定义文案中的内容不会根据促销内容的变化而变化");
        $("#textTypeTips").show();
        $("#showTipId").show();
        $("#content2Tips").hide();
        $("#nameTips").hide();
        //自动计算字数
        var _nameObj = document.getElementById("name");
        var _contentObj = document.getElementById("content2");
        checkCount(_nameObj, 17, ‘eLe‘);
        checkCount(_contentObj, 300, ‘etLe‘);
    } else {
        $("#textBox2").hide();
    }
});
$(function() {
    var manufacturerId = $("#manufacturerId").val();
    if (manufacturerId > 0) {
        dogetserialgroups(‘manufacturerId‘, ‘serialGroupId‘);
    }
    //初始化促销车系-START
    var serialGroupId = $("#serialGroupId").val();
    if (serialGroupId > 0) {
        $("#serialGroupMsgs").hide();
        getSerials();
    }
    //初始化促销车系-END
    if ($("#giftBtn").attr("checked")) {
        $("#giftBox").show();
    }
    if ($("#beiZhu").attr("checked")) {
        $("#beiZhuBox").show();
    }
    //存草稿
    $("#draftBtn").click(function() {
        $("#status").val( - 2);
        submitForm(true);
    });
});
function checktrim(id) { //焦点移出输入框时自动将连续的多余空格去掉;
    var namelist = "";
    var val = $.trim($("#" + id).val());
    var len = val.length;
    for (i = 0; i < len; i++) {
        if (isChinese(val.charAt(i))) {
            namelist += val.charAt(i);
        } else if (val.charAt(i).trim().length == 0) { //为空格时特殊处理
            if (val.charAt(i - 1).trim().length != 0) {
                namelist += " ";
            }
        } else {
            namelist += val.charAt(i);
        }
    }
    $("#" + id).val(namelist);
}
/**
* 检查行情标题
* @param id
*/
function checkName(id) {
    var title = $.trim($("#" + id).val());
    $.getJSON("/dealer/admin2013/action/info_center/do_hq_news.jsp", {
        method: ‘filterTitleSpecialChar‘,
        source: 1,
        content: title
    },
    function(data) {
        var IllegalTxt = data.content;
        if (IllegalTxt != ‘‘) {
            $("#" + id + "Tips").html(‘<i class="icon"></i>标题中不能使用这些符号: ‘ + IllegalTxt);
            $("#" + id + "Tips").show();
        } else {
            var len = countTxt(title);
            if (len < 15 || len > 17) {
                $("#nameTips").html(‘<i class="icon"></i>标题长度需控制在15-17个字之间‘);
                $("#nameTips").show();
            } else {
                $("#nameTips").hide();
                $("#nameTips").html(‘<i class="icon"></i>请输入文章标题‘);
            }
        }
    });
}
/**
* 检查礼包输入
* @param id
*/
function checkGift(id) {
    var value = $.trim($("#" + id).val());
    var regex = /^[A-Za-z0-9\s\u4e00-\u9fa5]+$/;
    if (!regex.test(value)) {
        $("#" + id + "Tips").html(‘<i class="icon"></i>不能使用特殊字符!‘);
        $("#" + id + "Tips").show();
    }
}
function hasSpecialChar(id, type) {
    var title = $.trim($("#" + id).val());
    var flag = true;
    $.getJSON("/dealer/admin2013/action/info_center/do_hq_news.jsp", {
        method: ‘filterTitleSpecialChar‘,
        source: 1,
        content: title
    },
    function(data) {
        data = data.replace(/\s{1,}/g, "");
        var json = (data != ‘‘ ? eval(‘0,‘ + data) : null);
        var IllegalTxt = ‘‘;
        for (var i = 0; i < json.length; ++i) {
            var o = json[i];
            if ("" != o.content) { //内容
                IllegalTxt = o.content;
                break;
            }
        }
        if (IllegalTxt != ‘‘) {
            $("#" + id + "Tips").html(‘<i class="icon"></i>标题中不能使用这些符号: ‘ + IllegalTxt);
            $("#" + id + "Tips").show();
            flag = false;
        } else {
            flag = true;
        }
    });
    return flag;
}
/**
* 车型列表展开收起
* @param index
*/
function showUpDown(index) {
    var title = $("#showBtn_" + index).text();
    if (title == "展开") {
        $("#showBtn_" + index).addClass("on").find("em").html("收起");
        $("#cars_" + index).show();
    } else {
        $("#showBtn_" + index).removeClass("on").find("em").html("展开");
        $("#cars_" + index).hide();
    }
}
/**
* 图片对象
* @param id 图片ID
* @param src 图片链接
* @param seq 图片位置
* @param type 图片类型(1:图库,2:用户上传)
* @constructor
*/
function PicInfo(id, src, seq, type) {
    this.id = id;
    this.src = src;
    this.seq = seq;
    this.type = type;
}
//展开年款
$(".addPri").each(function(i) {
    $(this).click(function() {
        $("#JyearList" + i).find("label").show();
        $(this).hide();
    });
});
//弹框
$(‘.editBtn‘).click(function() { //给box_btn绑定一个鼠标点击的事件
    showUpdateAddModelBox();
});
function showUpdateAddModelBox() {
    var h = parseInt($("#JaddPriPop").height());
    $.blockUI({ //当点击事件发生时调用弹出层
        message: $(‘#JaddPriPop‘),
        //要弹出的元素box
        css: { //弹出元素的CSS属性
            textAlign: ‘left‘,
            border: ‘none‘,
            background: ‘none‘,
            top: ($(window).height() - h) / 2 + ‘px‘,
            left: ($(window).width() - 721) / 2 + ‘px‘
        }
    });
}
$(‘#JaddType‘).click(function() { //给box_btn绑定一个鼠标点击的事件
    var serialGroupId = $("#serialGroupId").val();
    if (serialGroupId > 0) {
        $("#noSavedAddModelMsg").html("抱歉,您还没有新建任何加装车型,请新建一个");
    } else {
        $("#noSavedAddModelMsg").html("抱歉,您还未选择车系");
    }
    addAddModel();
});
//修改行情弹窗
function updateNewsConfirmPop() {
    var h = parseInt($("#JdelPop").height());
    $.blockUI({ //当点击事件发生时调用弹出层
        message: $(‘#JdelPop‘),
        //要弹出的元素box
        css: { //弹出元素的CSS属性
            textAlign: ‘left‘,
            border: ‘none‘,
            background: ‘none‘,
            top: ($(window).height() - h) / 2 + ‘px‘,
            left: ($(window).width() - 452) / 2 + ‘px‘
        }
    });
}
$(‘#JdelClose‘).click(function() {
    //关闭弹出层
    $.unblockUI();
});
$(‘#JmodCancel‘).click(function() {
    //关闭弹出层
    $.unblockUI();
});
$(‘.closeBtn‘).click(function() {
    //关闭弹出层
    $.unblockUI();
});
$(‘.cancelBtn‘).click(function() {
    //关闭弹出层
    $.unblockUI();
});
//确定发布
$("#submitBtn").click(function() {
    $("#status").val(1);
    submitForm(true);
});
$("#JmodConfirm").click(function() {
    $("#status").val(1);
    $("#punish").val(1);
    submitForm(true);
})
//效果预览
$("#previewBtn").click(function() {
    submitForm(false);
});
//是否正在发布,避免出现重复提交的情况
var isPublishing = false;
/**
* 发布
*@param isPublish:是否发布(ture:是,false:否(预览))
*/
function submitForm(isPublish) {
    var passFlag1 = true;
    //检测时间
    var beginTime = $.trim($("#beginTime").val());
    var endTime = $.trim($("#endTime").val());
    if (beginTime == "" || endTime == "") {
        $("#timeTips").html(‘<i class="icon"></i>请选择促销活动时间‘);
        $("#timeTips").css(‘display‘, ‘inline-block‘);
        passFlag1 = false;
    } else {
        var days = compareDate(beginTime, endTime);
        var now = new Date();
        var today = now.format(‘yyyy-MM-dd‘);
        if (days == -9999) {
            $("#timeTips").html(‘<i class="icon"></i>时间格式应为:yyyy-mm-dd‘);
            $("#timeTips").css(‘display‘, ‘inline-block‘);
            passFlag1 = false;
        } else if (days < 0) {
            $("#timeTips").html(‘<i class="icon"></i>结束时间应迟于开始时间‘);
            $("#timeTips").css(‘display‘, ‘inline-block‘);
            passFlag1 = false;
        } else if (days > 30) {
            $("#timeTips").html(‘<i class="icon"></i>有效期限不能够超过30天‘);
            $("#timeTips").css(‘display‘, ‘inline-block‘);
            passFlag1 = false;
        } else {
            $("#timeTips").html(‘<i class="icon"></i>请选择促销活动时间‘);
            $("#timeTips").hide();
        }
        if (compareDate(today, beginTime) < 0) {
            $("#timeTips").html(‘<i class="icon"></i>开始时间不应早于当前日期‘);
            $("#timeTips").css(‘display‘, ‘inline-block‘);
            passFlag1 = false;
        }
    }
    //检测车系
    var serialGroupId = $("#serialGroupId").val();
    if (serialGroupId == "") {
        $("#serialGroupTips").show();
        passFlag1 = false;
    } else {
        $("#serialGroupTips").hide();
    }
    //检测促销内容
    if (!$("#luoChe").attr("checked") && !$("#addModel").attr("checked")) {
        $("#twoModelsTips").html(‘<i class="icon"></i>请选择促销内容‘);
        $("#twoModelsTips").css(‘display‘, ‘inline-block‘);
        passFlag1 = false;
    } else {
        $("#twoModelsTips").hide();
    }
    var passFlag2 = false;
    var allValid = true;
    var discountNotNull = true;
    var optionId, valueId;
    //检测已选车型
    if ($("#luoChe").attr("checked")) {
        $("input[id^=‘chxModel_‘]:checked").each(function() {
            if ($(this).attr("isValid") == "0") {
                allValid = false;
            }
            passFlag2 = true;
            optionId = $(this).attr("id").replace().replace(‘chxModel_‘, ‘option_‘);
            if ($("#" + optionId).val() == 2) { //折扣优惠,折扣力度必填.
                valueId = $(this).attr("id").replace().replace(‘chxModel_‘, ‘mDiscount_‘);
                if ($("#" + valueId).val() == "") discountNotNull = false;
            }
        });
        if (!passFlag2) {
            $("#modelTips").html(‘<i class="icon"></i>抱歉,请至少选择一个促销车型</span>‘);
            $("#modelTips").css(‘display‘, ‘inline-block‘);
        } else {
            $("#modelTips").hide();
            if (!allValid) {
                $("#modelTips").html(‘<i class="icon"></i>存在车型优惠价格超出限制范围</span>‘);
                $("#modelTips").css(‘display‘, ‘inline-block‘);
            } else {
                $("#modelTips").hide();
                if (!discountNotNull) {
                    $("#modelTips").html(‘<i class="icon"></i>折扣优惠请输入折扣</span>‘);
                    $("#modelTips").css(‘display‘, ‘inline-block‘);
                } else {
                    $("#modelTips").hide();
                }
            }
        }
    }
    var passFlag4 = false;
    //检测是否有加装车
    if ($("#addModel").attr("checked")) {
        $("#addModelMsg tr").each(function() {
            var addModelId = $(this).attr("rel");
            if (parseInt(addModelId) > 0) {
                passFlag4 = true;
            }
        });
        if (!passFlag4) {
            $("#addModelBoxWarn").show();
        } else {
            $("#addModelBoxWarn").hide();
        }
    }
    //裸车优惠与加装车优惠两者选一可以提交
    if (passFlag4) {
        passFlag2 = true;
    }
    if (passFlag2) {
        passFlag4 = true;
    }
    var isAbroad = $("#isAbroad").val(); //是否海外车
    if (isAbroad == 1) { //海外车
        $("input[id^=‘year_‘]:checked").each(function() {
            var type = $(this).val();
            $("input[id^=‘chxModel_" + type + "_‘]:checked").each(function() {
                var v = $(this).val();
                var mId = v.split(‘_‘)[1];
                var discount = $("#mDiscount_" + type + "_" + mId).val();
                if (discount == "") {
                    $("#tipTxt_" + type + "_" + mId).html(‘<em class="arrow"></em>抱歉,售价不能为0‘);
                    $("#tipTxt_" + type + "_" + mId).show();
                    passFlag1 = false;
                }
            });
        });
    }
    //检测是否有选择文案类型
    if (!$("#textType1").attr("checked") && !$("#textType2").attr("checked")) {
        $("#textTypeTips").html(‘<em class="arrow"></em>请选择促销文案‘);
        $("#textTypeTips").show();
        passFlag1 = false;
    }
    if ($("#textType2").attr("checked")) { //默认文案不需要检测标题及内容的限制
        //检测标题
        var name = $.trim($("#name").val());
        if (name == "") {
            $("#nameTips").css(‘display‘, ‘inline-block‘);
            passFlag1 = false;
        } else {
            var len = countTxt(name);
            if (len < 15 || len > 17) {
                $("#nameTips").html(‘<i class="icon"></i>标题长度需控制在15-17个字之间‘);
                $("#nameTips").show();
                passFlag1 = false;
            } else {
                $("#nameTips").hide();
                $("#nameTips").html(‘<i class="icon"></i>请输入文章标题‘);
            }
        }
        //检测行情内容
        var contentTxt = $.trim($("#content2").val());
        if (contextTxt = "") {
            $("#textTips").html(‘<i class="icon"></i>请输入行情内容‘);
            $("#textTips").show();
            passFlag1 = false;
        } else {
            var len = countTxt(contentTxt);
            if (len < 50 || len > 300) {
                $("#textTips").html(‘<i class="icon"></i>行情内容请控制在50-300个中文字符内‘);
                $("#textTips").css(‘display‘, ‘inline-block‘);
                passFlag1 = false;
            } else {
                $("#textTips").hide();
                $("#textTips").html(‘<i class="icon"></i>请输入行情内容‘);
            }
        }
    }
    //检测行情说明
    var bContent = "";
    if ($("#beiZhu").attr("checked")) {
        bContent = $.trim($("#bContent").val());
        if (bContent == "可注明优惠的相关条件,如优惠针对旧车置换、优惠价格含节能补贴等") {
            $("#bContent").text("");
            $("#bContentTips").html(‘<i class="icon"></i>促销说明不能为空!‘);
            $("#bContentTips").css(‘display‘, ‘inline-block‘);
            passFlag1 = false;
        }
        var length = countTxt(bContent);
        if (length > 45) {
            $("#bContentTips").html(‘<i class="icon"></i>促销说明不能超出45个中文字符‘);
            $("#bContentTips").css(‘display‘, ‘inline-block‘);
            passFlag1 = false;
        }
    } else {
        $("#bContent").text("");
    }
    //检测行情礼包
    var isSelectGift = false;
    if ($("#giftBtn").attr("checked")) {
        $("input[name=‘gift‘]:checked").each(function() {
            isSelectGift = true;
        });
        $("input[name=‘otherGift‘]:checked").each(function() {
            isSelectGift = true;
        });
        var giftPrice = $("#giftPrice").val();
        if (isSelectGift) {
            if (giftPrice == "" || giftPrice == 0) {
                $("#giftPriceTips").html(‘<i class="icon"></i>抱歉,请填写礼包的等值金额‘);
                $("#giftPriceTips").show();
                passFlag1 = false;
            }
        }
        if (giftPrice != "" && !isSelectGift) {
            $("#giftPriceTips").html(‘<i class="icon"></i>抱歉,请选礼包内容‘);
            $("#giftPriceTips").show();
            passFlag1 = false;
        }
    }
    //检测图片
    var passFlag3 = true;
    if (selectPicArray.length < 5) {
        passFlag3 = false;
    } else {
        for (var i = 0; i < selectPicArray.length; i++) {
            if (selectPicArray[i] == null) {
                passFlag3 = false;
            }
        }
    }
    if (!passFlag3) {
        $("#picWarnMsg").html(‘<i class="icon"></i>抱歉,为了保持页面的美观,图片必须选满‘);
        $("#picWarnMsg").show();
    } else {
        $("#picTips").hide();
    }
    var url = "/dealer/admin2013/info_center/hq_news.jsp";
    if (!passFlag1) {
        window.location.href = url + "#top";
        //关闭弹出层
        $.unblockUI();
        return;
    } else if (!passFlag2) {
        window.location.href = url + "#sgTitle2";
        return;
    } else if (!allValid) {
        window.location.href = url + "#sgTitle2";
        return;
    } else if (!discountNotNull) {
        window.location.href = url + "#sgTitle2";
        return;
    } else if (!passFlag4) {
        window.location.href = url + "#sgTitle2";
        return;
    } else if (!passFlag3) {
        window.location.href = url + "#sgTitle3";
        return;
    } else {
        //清空车型选择表格里面的form控件,减少提交参数
        var modelIds = "";
        var addModelIds = "";
        var modelRePrices = "";
        var modelStatuss = "";
        var photoIds = "";
        var unitIds = "";
        var replaceIds = "";
        if ($("#luoChe").attr("checked")) {
            $("input[id^=‘year_‘]:checked").each(function() {
                var type = $(this).val();
                $("input[id^=‘chxModel_" + type + "_‘]:checked").each(function() {
                    var v = $(this).val();
                    var mId = v.split(‘_‘)[1];
                    modelIds += mId + "_";
                    var unit = $("#option_" + type + "_" + mId).val();
                    if (unit == "") {
                        unit = 1;
                    }
                    unitIds += unit + "_";
                    var discount = $("#mDiscount_" + type + "_" + mId).val();
                    if (discount == "") {
                        discount = 0;
                    }
                    modelRePrices += discount + "_";
                    var isReplace = $("#replace_" + type + "_" + mId).attr("checked"); //是否选中置换优惠
                    var replace = 0;
                    if (isReplace) {
                        replace = 1;
                    }
                    replaceIds += replace + "_";
                    var mStatus = 1;
                    if ($("#type2_" + type + "_" + mId).attr("checked")) {
                        mStatus = 2;
                    }
                    if ($("#type3_" + type + "_" + mId).attr("checked")) {
                        mStatus = 3;
                    }
                    modelStatuss += mStatus + "_";
                });
            });
        }

        //图片
        for (var i = 0; i < selectPicArray.length; i++) {
            photoIds += selectPicArray[i].id + "_" + selectPicArray[i].type + ";";
        }
        modelIds = ‘<input type="hidden" name="modelIds" value="‘ + modelIds + ‘"/>‘;
        modelRePrices = ‘<input type="hidden" name="modelRePrices" value="‘ + modelRePrices + ‘"/>‘;
        modelStatuss = ‘<input type="hidden" name="modelStatuss" value="‘ + modelStatuss + ‘"/>‘;
        photoIds = ‘<input type="hidden" name="photoIds" value="‘ + photoIds + ‘"/>‘;
        unitIds = ‘<input type="hidden" name="unitIds" value="‘ + unitIds + ‘"/>‘;
        replaceIds = ‘<input type="hidden" name="replaceIds" value="‘ + replaceIds + ‘"/>‘;
        addModelIds = ‘<input type="hidden" name="addModelIds" value="‘ + addModelIds + ‘"/>‘;
        if ($("#textType2").attr("checked")) {
            var name = $.trim($("#name").val());
            $.getJSON("/dealer/admin2013/action/info_center/do_hq_news.jsp", {
                method: ‘filterTitleSpecialChar‘,
                source: 1,
                content: name
            },
            function(items) {
                var IllegalStr = items.content;
                if (IllegalStr != ‘‘) {
                    $("#nameTips").html(‘<i class="icon"></i>标题中不能使用这些符号:‘ + IllegalStr);
                    $("#nameTips").show();
                } else {
                    var contentTxt = $.trim($("#content2").val());
                    $.getJSON("/dealer/admin2013/action/info_center/do_hq_news.jsp", {
                        method: ‘filterSpecialChar‘,
                        content: contentTxt
                    },
                    function(data) {
                        if (data != null) {
                            var IllegalTxt = data.content;
                            if (IllegalTxt != ‘‘) {
                                $("#content2Tips").html(‘<i class="icon"></i>抱歉,您输入的内容中含有不允许使用的字符: ‘ + IllegalTxt + ‘ 请删除,谢谢!‘);
                                $("#content2Tips").css(‘display‘, ‘inline-block‘);
                                window.location.href = url + "#top";
                            } else {
                                if (isPublish) { //发布/存草稿
                                    genShortName(); //生成短标题
                                    $("#luoModelSerial").html(‘‘); //清空车型参数防止表单参数太多
                                    $("#chooseModels2").html(modelIds + modelRePrices + modelStatuss + photoIds + unitIds + replaceIds + addModelIds);
                                    //如果没勾选礼包提交前先清空礼包内容,防止提交礼包
                                    if (!$("#giftBtn").attr("checked")) {
                                        $("#giftBox").html("");
                                    }
                                    //如果没勾选备注说明,也需要清空备注说明,防止过多参数提交
                                    if (!$("#beiZhu").attr("checked")) {
                                        $("#bContent").text("");
                                    }
                                    //预览效果时会更改action,故确认提交时要重置action
                                    $("#mainForm").attr("action", ‘/dealer/admin2013/action/info_center/do_hq_news.jsp?_charset=GBK‘);
                                    $("#mainForm").removeAttr("target");
                                    $("#mainForm").submit();
                                } else { //预览
                                    $("#chooseModels2").html(modelIds + modelRePrices + modelStatuss + photoIds + unitIds + replaceIds + addModelIds);
                                    var actionUrl = ‘/market/15075-preview.html‘;
                                    $("#mainForm").attr("action", actionUrl);
                                    $("#mainForm").attr("target", "previewWindow");
                                    window.open(‘about:blank‘, ‘previewWindow‘, ‘toolbar=yes,menubar=yes,scrollbars=yes,resizable=yes‘);
                                    $("#mainForm").submit();
                                }
                            }
                        }
                    });
                }
            });
        } else {
            if (isPublish) { //发布/存草稿
                //防止表单重复提交
                if (!isPublishing) {
                    var actionType = $("#status").val(); //存草稿:-2,发布:1
                    if (actionType == 1) {
                        $("#submitBtn").val("发布中...");
                        $("#submitBtn").attr("disabled", true);
                    } else if (actionType == -2) {
                        $("#draftBtn").val("存草稿中...");
                        $("#draftBtn").attr("disabled", true);
                    }
                    isPublishing = true;
                } else {
                    PCDialog.open("提示", "iframe:/dealer/admin2013/common/__tip.jsp?type=0&tip=" + escape("请勿进行重复提交或双击"), "350", "180");
                }
                genShortName(); //生成短标题
                $("#luoModelSerial").html(‘‘); //清空车型参数防止表单参数太多
                $("#chooseModels2").html(modelIds + modelRePrices + modelStatuss + photoIds + unitIds + replaceIds + addModelIds);
                //如果没勾选礼包提交前先清空礼包内容,防止提交礼包
                if (!$("#giftBtn").attr("checked")) {
                    $("#giftBox").html("");
                }
                //如果没勾选备注说明,也需要清空备注说明,防止过多参数提交
                if (!$("#beiZhu").attr("checked")) {
                    $("#bContent").text("");
                }
                //预览效果时会更改action,故确认提交时要重置action
                $("#mainForm").attr("action", ‘/dealer/admin2013/action/info_center/do_hq_news.jsp?_charset=GBK‘);
                $("#mainForm").removeAttr("target");
                $("#mainForm").submit();
            } else { //预览
                $("#chooseModels2").html(modelIds + modelRePrices + modelStatuss + photoIds + unitIds + replaceIds + addModelIds);
                var actionUrl = ‘/market/15075-preview.html‘;
                $("#mainForm").attr("action", actionUrl);
                $("#mainForm").attr("target", "previewWindow");
                window.open(‘about:blank‘, ‘previewWindow‘, ‘toolbar=yes,menubar=yes,scrollbars=yes,resizable=yes‘);
                $("#mainForm").submit();
            }
        }
    }
}
//日期格式化函数
Date.prototype.format = function(format) {
    var o = {
        "M+": this.getMonth() + 1,
        //month
        "d+": this.getDate(),
        //day
        "h+": this.getHours(),
        //hour
        "m+": this.getMinutes(),
        //minute
        "s+": this.getSeconds(),
        //second
        "q+": Math.floor((this.getMonth() + 3) / 3),
        //quarter
        "S": this.getMilliseconds() //millisecond
    }
    if (/(y+)/.test(format)) {
        format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    }
    for (var k in o) {
        if (new RegExp("(" + k + ")").test(format)) {
            format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
        }
    }
    return format;
}
//检查内容是否为时间格式:yyyy-mm-dd
function isDate(d) {
    var reg = /\d{4}-\d{2}-\d{2}$/;
    if (reg.test(d)) {
        return true;
    }
    return false;
}
//日期比较,返回两日期天数差
function compareDate(startDate, endDate) {
    if (!isDate(startDate) || !isDate(endDate)) {
        return - 9999;
    }
    var begin = new Date(startDate.replace(/-/g, "/") + " 00:00:00");
    var end = new Date(endDate.replace(/-/g, "/") + " 00:00:00");
    return parseInt(end - begin) / 1000 / 60 / 60 / 24;
}
//tab
featuredcontentslider.init({
    id: "slider1",
    contentsource: ["inline", ""],
    toc: "markup",
    link: true,
    nextprev: ["上一条", "下一条"],
    revealtype: "click",
    enablefade: [true, 0.15],
    autorotate: [false, 3500],
    delay: 150,
    onChange: function(previndex, curindex) {}
});
featuredcontentslider.init({
    id: "slider2",
    contentsource: ["inline", ""],
    toc: "markup",
    link: true,
    nextprev: ["上一条", "下一条"],
    revealtype: "click",
    enablefade: [true, 0.15],
    autorotate: [false, 3500],
    delay: 150,
    onChange: function(previndex, curindex) {}
});
featuredcontentslider.init({
    id: "slider3",
    contentsource: ["inline", ""],
    toc: "markup",
    contentclass: "picContent",
    link: true,
    nextprev: ["上一条", "下一条"],
    revealtype: "click",
    enablefade: [true, 0.15],
    autorotate: [false, 3500],
    delay: 150,
    onChange: function(previndex, curindex) {}
});

  

20150728

标签:

原文地址:http://www.cnblogs.com/wpbars/p/4684058.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!