promotionEdit.html 14.1 KB
<!DOCTYPE html>

<div id="promotionEditDiv" class="easyui-layout" fit="true" style="overflow-y: scroll">
    <form name="promotionEditForm" id="promotionEditForm" 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 width="10%"><span style="color:red">*</span><label>活动名称:</label></td>
                    <td colspan="3">
                        <input class="easyui-textbox" id="activityName" name="activityName" data-options="validType:'length[1,50]'" style="width: 280px;"/>
                    </td>
                </tr>
                <tr style="height: 60px" >
                    <td width="10%"><span style="color:red">*</span><label>活动时间:</label></td>
                    <td colspan="3">
                        <input class="easyui-datetimebox" name="startTimeStr" id="startTimeStr" data-options="required:true,showSeconds:false" style="width:200px"> ~
                        <input class="easyui-datetimebox" name="endTimeStr" id="endTimeStr" data-options="required:true,showSeconds:false" style="width:200px">
                    </td>
                </tr>
                <tr style="height: 60px">
                    <td width="10%"><span style="color:red">*</span><label>标签:</label></td>
                    <td colspan="3">
                        <input class="easyui-textbox" id="label" name="label"  data-options="required:true" style="width: 280px;"/>
                    </td>
                </tr>
                <tr style="height: 60px">
                    <td width="10%"><span style="color:red">*</span><label>促销类型:</label></td>
                    <td colspan="3">
                        <input class="easyui-combobox" id="promotionType" name="promotionType" style="width: 200px;"/>
                    </td>
                </tr>
                <tr style="height: 60px;display: none" id="limitDisCountTr">
                    <td width="10%"><span style="color:red">*</span><label>优惠条件:</label></td>
                    <td colspan="3">
                        <div id="limitDisCountDiv">
                            商品金额大于等于<input class="easyui-numberbox" id="limitAmount_0" style="width: 60px" data-options="min:0,precision:0">元,
                            折扣为 <input class="easyui-numberbox" id="offerAmount_0" style="width: 60px;" data-options="min:0,precision:2">
                            最高优惠<input class="easyui-numberbox" id="offerMaxLimit" style="width: 60px;" data-options="min:0,precision:0">
                        </div>
                    </td>

                </tr>
                <tr>
                    <td></td>
                    <td colspan="3">
                        <span style="color:red">提示:折扣填写0-1之间的两位小数。例如:0.85表示85折</span><br>
                    </td>
                </tr>
                <tr style="height: 60px">
                    <td width="10%"><span style="color:red">*</span><label>商品适用范围:</label></td>
                    <td>
                        <input class="easyui-combobox" id="productScopeType" name="productScopeType" data-options="required:true"  style="width: 200px;"/>
                    </td>
                    <td id="limitTypeTr" hidden>
                        <input class="easyui-combobox" id="limitType" name="limitType" style="width: 200px;" data-options="required:true" />
                    </td>
                    <td id="limitValuesTr" hidden>
                        <input class="easyui-numberbox" id="limitValues" name="limitValues" style="width: 280px;" />
                    </td>
                </tr>

                <tr style="height: 60px">
                    <td width="10%"><span style="color:red">*</span><label>可用订单类型:</label></td>
                    <td colspan="3">
                        <label>
                            <input type="checkbox" name="isAll"
                                   id="isAll" onclick="isAllClick(this)">全部
                        </label>
                    </td>
                </tr>
                <tr style="height: 60px">
                    <td></td>
                    <td colspan="3">
                        <input type="checkbox" name="productLimitChose" id="productLimit1" value="1">现货发货
                        <input type="checkbox" name="productLimitChose" id="productLimit72" value="72" >闪购寄存
                        <input type="checkbox" name="productLimitChose" id="productLimit4" value="4" >预售
                        <input type="checkbox" name="productLimitChose" id="productLimit71" value="71" >现货寄存
                        <input type="checkbox" name="productLimitChose" id="productLimit17" value="17" >香港极速仓
                        <input type="checkbox" name="productLimitChose" id="productLimit6" value="6" >二手
                        <input type="checkbox" name="productLimitChose" id="productLimit3" value="3" >闪购发货
                        <input type="checkbox" name="productLimitChose" id="productLimit9" value="9" >极速发货
                        <input type="checkbox" name="productLimitChose" id="productLimit5" value="5" >全新瑕疵
                    </td>
                </tr>
                <tr style="height: 60px">
                    <td width="10%"><span style="color:red">*</span><label>活动期间内总次数限制:</label></td>
                    <td colspan="3">
                        <input class="easyui-numberbox" id="joinLimitTimes" name="joinLimitTimes" data-options="required:true"  style="width: 120px;"/>
                    </td>
                </tr>

                <tr style="height: 60px">
                    <td width="10%"><span style="color:red">*</span><label>活动是否开启:</label></td>
                    <td colspan="3">
                        <input class="easyui-combobox" id="initStatus" name="initStatus" data-options="required:true"  style="width: 200px;"/>
                    </td>
                </tr>
            </table>
        </div>
    </form>
</div>
<script>
    var promotionId = paramObject.promotionId;

    $("#promotionEditForm #activityName").textbox({
        required: true,
        missingMessage: "促活动名称不能为空",
        prompt: "活动名称"
    });

    $("#promotionEditForm #startTimeStr").datetimebox({
        required: true,
        missingMessage: "开始时间不能为空",
        prompt: "开始时间",
        showSeconds : true
    });

    $("#promotionEditForm #endTimeStr").datetimebox({
        required: true,
        missingMessage: "结束时间不能为空",
        prompt: "结束时间",
        showSeconds : true
    });

    $("#promotionEditForm #allTimesLimit").numberbox({
        required: true,
        missingMessage: "总次数限制不能为空",
        prompt: "总次数限制次数"
    });


    $("#promotionEditForm #promotionType").combobox({
        textField : "text",
        valueField : "value",
        data:[{text:"折扣",value:"2"}],
        panelHeight : 80,
        editable:false,
        onSelect : function(record){
            if(record.value == 1){
                //满减
                $("#limitCrashTr").show();
                $("#limitDisCountTr").hide();

            }else if(record.value == 2){
                //折扣
                $("#limitCrashTr").hide();
                $("#limitDisCountTr").show();
            }
        },
        onLoadSuccess : function(){
            if(promotionId == 0){
                $("#promotionEditForm #promotionType").combobox("setValue",2);
                $("#limitCrashTr").show();
            }

        }
    });

    $("#promotionEditForm #limitType").combobox({
        prompt:"请选择",
        textField : "text",
        valueField : "value",
        editable: false,
        panelHeight : 80,
        data:[{text:"属于",value:"1"},{text:"不属于",value:"2"}],

    });

    $("#promotionEditForm #initStatus").combobox({
        prompt:"请选择",
        textField : "text",
        valueField : "value",
        panelHeight : 80,
        editable:false,
        data:[{text:"开启",value:"1"},{text:"关闭",value:"2"}],
    });

    $("#promotionEditForm #productScopeType").combobox({
        prompt:"请选择",
        textField : "text",
        valueField : "value",
        panelHeight : 80,
        editable: false,
        url : contextPath + "/PromotionController/getProductLimitEnums.do",
        onSelect : function(record){
            if(record.value == 1){//全部商品
                $("#limitTypeTr").hide();
                $("#limitValuesTr").hide();
            }else if(record.value == 2){//商品池限制
                $("#limitTypeTr").show();
                $("#limitValuesTr").show();
            }
        }
    });


    $("#promotionEditForm #limitValues").textbox({
        prompt : "请输入商品池id"
    });



    function isAllClick(object){
        if(object.checked){
            $("#promotionEditDiv").find("input:checkbox[name='productLimitChose']").prop("checked", true);
        }else{
            $("#promotionEditDiv").find("input:checkbox[name='productLimitChose']").prop("checked", false);
        }

    }

    $("#limitAddBtn").linkbutton({
        iconCls : "icon-add",
        onClick : function() {
            var addCount = $("#promotionEditForm #addLimitCount").val();
            addCount = eval(addCount) + 1;
            $("#promotionEditForm #addLimitCount").val(addCount);

            var appendStr = '<div name="limitCrashDiv" style="margin-top: 5px" id="limitCrashDiv' + addCount + '">商品金额大于等于<input type="text" id="limitAmount_' + addCount + '" name="limitAmount" style="width: 60px;">元,减 ' +
                    '<input type="text" id="offerAmount_' + addCount + '" name="offerAmount" style="width: 60px;">元 &nbsp;&nbsp;&nbsp;<a id="DelBtn' + addCount + '" class="btn-danger" href="#">-</a></div>';

            $("#promotionEditForm #limitCrashDiv").append(appendStr);

            loadLimitData("limitAmount_" + addCount, "offerAmount_" + addCount);

            $("#promotionEditForm #DelBtn" + addCount).linkbutton({
                iconCls : "icon-del",
                onClick : function() {
                    $("#promotionEditForm #limitCrashDiv" + addCount).remove();
                }
            });
        }
    });

    function loadLimitData(limitAmountId,offerAmountId) {
        $("#promotionEditForm" + " #" + limitAmountId).numberbox({
            min : 0,
            precision : 0
        });

        $("#promotionEditForm" + " #" + offerAmountId).numberbox({
            min : 0,
            precision : 0
        });
    }

    if(promotionId > 0){
        $.post(contextPath + "/PromotionController/getByPromotionId", {
            id: promotionId
        }, function (data) {
            var loadData = data.data;
            $("#promotionEditForm").form("load", loadData);
            $("#initStatus").combobox("setValue",loadData.status);
            $("#startTimeStr").datetimebox("setValue",loadData.startTimeStr);
            $("#endTimeStr").datetimebox("setValue",loadData.endTimeStr);
            $("#promotionType").combobox("setValue",loadData.promotionType);

            //商品限制范围
            var scope = loadData.productScopeList;
            var productScopeType = scope[0].productScopeType;
            var limitType = productScopeType == 1 ? 1 : scope[0].limitType;
            $("#limitType").combobox("setValue", limitType);
            $("#limitValues").textbox("setValue", scope[0].scopeValue);
            $("#productScopeType").combobox("setValue",productScopeType);
            if(productScopeType == 1){
                $("#limitTypeTr").hide();
                $("#limitValuesTr").hide();
            }else{
                $("#limitTypeTr").show();
                $("#limitValuesTr").show();
            }


            //填充促销类型限制参数
            var typeParams = loadData.amountConditionList;
            if(loadData.promotionType == 2){
                //折扣
                $("#limitCrashTr").hide();
                $("#limitDisCountTr").show();
                $("#limitAmount_0").numberbox("setValue",typeParams[0].limitAmount);
                $("#offerAmount_0").numberbox("setValue",typeParams[0].offerAmount);
                $("#offerMaxLimit").numberbox("setValue",typeParams[0].offerMaxLimit);
            }else{
                //满减
                $("#limitCrashTr").show();
                $("#limitDisCountTr").hide();
                for(var i = 0; i < typeParams.length; i++){
                    if(i == 0){
                        $("#promotionEditForm #limitAmount_1").numberbox("setValue",typeParams[0].limitAmount);
                        $("#promotionEditForm #offerAmount_1").numberbox("setValue",typeParams[0].offerAmount);
                        continue;
                    }
                    $("#promotionEditForm #limitAddBtn").trigger("click");
                }
                setTimeout(function () {
                    for(var i = 0; i < typeParams.length; i++){
                        $("#promotionEditForm #limitAmount_" + (i + 1)).numberbox("setValue",typeParams[0].limitAmount);
                        $("#promotionEditForm #offerAmount_" + (i + 1)).numberbox("setValue",typeParams[0].offerAmount);
                    }
                }, 100);
            }

            //设定商品适用类型
            if(loadData.isProductTypeAll == 1){
                $("#promotionEditDiv").find("input:checkbox[name='isAll']").prop("checked", true);
                $("#promotionEditDiv").find("input:checkbox[name='productLimitChose']").prop("checked", true);
            }else{
                $("#promotionEditDiv").find("input:checkbox[name='isAll']").prop("checked", false);
                var productLimits = loadData.productLimitType;
                var array = productLimits.split(",");
                for(var j =0; j < array.length; j++){
                    $("#promotionEditForm #productLimit" + array[j]).prop("checked", true);
                }
            }


        })
    }


</script>