JS 循环 table

[#escape x as x?html]
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title></title>
	<meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" type="text/css" href="${base}/resources/admin1.0/H-ui/static/h-ui/css/H-ui.min.css" />
    <link rel="stylesheet" href="${base}/resources/admin1.0/css/public.css" />
    <link rel="stylesheet" href="${base}/resources/admin1.0/css/admin.css" />

    <link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap.min.css">
    <style>
        body{background:#f9f9f9;}
        .pag_div{width:45%;float:left;}
		.col-sm-7{width:72%;}
        th{border-top:1px solid #f0f0f0;}
		.form_box{
			overflow: auto;
			overflow-x: hidden;
		}
        .check-box, .radio-box{padding-bottom:8px;}
		.input_box ul{right:0;}

        .spec{
            padding: 0;
            height: 34px;
            width: 90%;
            margin-left: 8px;
            margin-bottom: 20%;
            cursor: pointer;
            vertical-align: middle;
        }

        .spec ul{
            padding: 0;
            height: 34px;
            width: 90%;
            margin-left: 8px;
            cursor: pointer;
            vertical-align: middle;
        }

        .spec table{
            padding: 0;
            height: 34px;
            width: 100%;
            margin-left: 8px;
            margin-top: 8px;
            cursor: pointer;
            vertical-align: middle;
        }
        .spec table td{
            padding: 0;
            height: 34px;
            width: 80%;
            margin-left: 8px;
            margin-top: 8px;
            cursor: pointer;
            vertical-align: middle;
        }

        .spec table li{
            padding: 0;
            height: 34px;
            width: 15%;
            margin-left: 8px;
            cursor: pointer;
            vertical-align: middle;
        }


        .spec table li input{
            padding: 0;
            height: 34px;
            width: 56%;
            margin-left: 8px;
            cursor: pointer;
            vertical-align: middle;
        }


        .spec table li{
           float:left;
        }

        .lineOverflow {
            white-space: nowrap;/*禁止自动换行*/
        }
    </style>
</head>
<body>
<form id="inputForm" action="save_new.jhtml" method="post" class="form form-horizontal">
    <input type="hidden" id="isDefault" name="product.isDefault" value="true" />
    <input type="hidden" id="exchangePoint" name="product.exchangePoint" class="text" maxlength="9" disabled="disabled" />
    <input type="hidden" id="stock" name="product.stock" class="text" value="999999999" maxlength="9" />
    <input type="hidden" id="labels" name="labels" value="" />
    <div class="child_page">
        <div class="cus_nav">
            <ul>
            	<li><a href="">${message("admin.breadcrumb.home")}</a></li>
            	<li><a href="list.jhtml">${message("admin.goods.list")}</a></li>
                <li>${message("admin.goods.add")}</li>
            </ul>
        </div>
        <div class="form_box">

            <div class='form_baseInfo'>
                <h3 class="form_title" style="margin:20px 0 0 20px;">基本信息</h3>
                <div class="pag_div">
                    <div class="row cl">
                        <label class="form-label col-xs-4 col-sm-3">
                        	<img src="${base}/resources/admin1.0/images/bitian_icon.svg" alt="" />${message("Goods.productCategory")}</label>
                        <div class="formControls col-xs-8 col-sm-7">

                            <input type="text" id="productCategoryValue"  class="input-text radius down_list" readonly placeholder="请选择">
                            <input type="text" id="productCategoryId" name="productCategoryId" class="downList_val" />
                            <ul class="downList_con categoryUl">
                                [#list productCategoryTree as productCategory]
                                    <li val="${productCategory.id}">[#if productCategory.grade != 0][#list 1..productCategory.grade as i]&nbsp;&nbsp;[/#list][/#if]${productCategory.name}</li>
                                [/#list]
                            </ul>

                        </div>
                    </div>

                    <div class="row cl">
                        <label class="form-label col-xs-4 col-sm-3">
                        	<img src="${base}/resources/admin1.0/images/bitian_icon.svg" alt="" />${message("Goods.name")}</label>
                        <div class="formControls col-xs-8 col-sm-7 nameDiv">

                            <input type="text" id="goodsName" name="name" autocomplete="off" class="input-text radius down_list" placeholder="请选择" />
                            <!--  <input type="text" id="goodsName" name="name" class="downList_val" />  -->
                            <ul class="downList_con nameUl">

                            </ul>

                        </div>
                    </div>

                    <!--  <div class="row cl">
                        <label class="form-label col-xs-4 col-sm-3">
                        	<img src="${base}/resources/admin1.0/images/bitian_icon.svg" alt="" />${message("Goods.name")}</label>
                        <div class="formControls col-xs-8 col-sm-7">
                            <input type="text" class="input-text radius" placeholder="" name="name" id="goodsName"/>
                        </div>
                    </div>  -->


                    <div class="row cl">
                        <label class="form-label col-xs-4 col-sm-3">主图</label>
                        <div class="formControls col-xs-8 col-sm-7">
                            <p class="imgRule">仅支持png、jpg、jpeg,建议800*800,大小不超过6M</p>
                            <div class="updateDivImgs">
                                <div class="updateImg mainImg">
                                    <div class="img_box"></div>
                                    <input type="hidden" name="image" value=""/>
                                    <a id="filePicker" class="file"
                                       style="display:block;width:60px;height:60px;margin:10px;opacity: 0" >gggggggggggggggggggggggggg</a>
                                    <div class="img_model">
                                        <span class="delImg"></span>
                                    </div>
                                </div>
                            </div>

                        </div>
                    </div>
                    <div class="row cl">
                        <label class="form-label col-xs-4 col-sm-3">${message("Goods.sn")}</label>
                        <div class="formControls col-xs-8 col-sm-7">
                        [#--<span class="input_no_span">4374837447832</span>--]
                            <input type="text" name="sn" class="input-text" maxlength="100" title="${message("admin.goods.snTitle")}" value=""/>
                        </div>
                    </div>
                    <!--<div class="row cl">
                        <label class="form-label col-xs-4 col-sm-3">${message("Goods.caption")}</label>
                        <div class="formControls col-xs-8 col-sm-7">
                            <input type="text" class="input-text radius" placeholder="" name="caption" />
                        </div>
                    </div>-->

                    <div class="row cl">
                        <label class="form-label col-xs-4 col-sm-3">${message("Goods.shelfLife")}</label>
                        <div class="formControls col-xs-8 col-sm-7">
                            <div class="input_box">
                                <input type="text" name="shelfLife" class="" />
                                <div class="box_right" style="text-align:right;">天</div>
                            </div>
                        </div>
                    </div>
                    <div class="row cl">
                        <label class="form-label col-xs-4 col-sm-3">${message("Goods.weight")}</label>
                        <div class="formControls col-xs-8 col-sm-7">
                            <div class="input_box">
                                <input type="text" name="weight" class="" />
                                <div class="box_right input_right">
                                    <input type="text" readonly="readonly" class="weight_unit" value="" />
                                    <input type="text" name="weightUnit" class="downList_val" />
                                    <ul>
                                    [#list weightUnits as weightUnit]
                                        <li val="${weightUnit}">${message("Goods.weightUnit."+weightUnit)}</li>
                                    [/#list]
                                    </ul>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="row cl">
                        <label class="form-label col-xs-4 col-sm-3">${message("Goods.nature")}</label>
                        <div class="formControls col-xs-8 col-sm-7">
                        [#--<span class="select-box">
                            <select id="nature" name="nature" class="select size-L" size="1">
                                <option value="">${message("admin.common.choose")}</option>
                                [#list natures as nature]
                                    <option value="${nature}">${message("Goods.nature."+nature)}</option>
                                [/#list]

                            </select>
                        </span>--]

                            <input type="text" class="input-text radius down_list" readonly placeholder="请选择">
                            <input type="text" name="nature" class="downList_val" />
                            <ul class="downList_con">
                                <li val="">${message("admin.common.choose")}</li>
                                [#list natures as nature]
                                    <li val="${nature}">${message("Goods.nature."+nature)}</li>
                                [/#list]

                            </ul>

                        </div>
                    </div>
                    <div class="row cl">
                        <label class="form-label col-xs-4 col-sm-3">${message("Goods.type")}</label>
                        <div class="formControls col-xs-8 col-sm-7">
                                   [#--<span class="select-box">
										<select id="type" name="type" class="select size-L" size="1">
                                            [#list types as type]
                                                [#if type_index == 0]
                                                    <option value="${type}">${message("Goods.Type." + type)}</option>
                                                [/#if]
                                            [/#list]
										</select>
								   </span>--]
                                       <input type="hidden" name="type" id="type" value="general">
                                       <span class="input_no_span in_span_bag">${message("Goods.Type.general")}</span>
                        </div>
                    </div>


                    <div class="row cl">
                        <label class="form-label col-xs-4 col-sm-3">${message("Product.cost")}</label>
                        <div class="formControls col-xs-8 col-sm-7">
                        [#--<span class="input_no_span">4374837447832</span>--]
                            <input type="text" name="product.cost" id="cost" class="input-text" maxlength="100" />
                        </div>
                    </div>

                    <div class="row cl">
                        <label class="form-label col-xs-4 col-sm-3">条形码</label>
                        <div class="formControls col-xs-8 col-sm-7">
                        [#--<span class="input_no_span">4374837447832</span>--]
                            <input type="text" id="barCode" name="product.barCode" class="input-text" maxlength="50"  value="" />
                        </div>
                    </div>



                </div>
                <div class="pag_div">
                    <!--  <div class="row cl">
                        <label class="form-label col-xs-4 col-sm-3">
                        	<img src="${base}/resources/admin1.0/images/bitian_icon.svg" alt="" />${message("Goods.name")}</label>
                        <div class="formControls col-xs-8 col-sm-7">
                            <input type="text" class="input-text radius" placeholder="" name="name" id="goodsName"/>
                        </div>
                    </div>  -->

                     <div class="row cl">
                        <label class="form-label col-xs-4 col-sm-3">品牌</label>
                        <div class="formControls col-xs-8 col-sm-7 brandDiv">
                            <input type="text" id="brandName" name="brandName" class="input-text radius down_list" autocomplete="off" placeholder="请选择" />
                            <input type="text"class="downList_val" />
                            <ul class="downList_con" id="brandUl">

                            </ul>
                        </div>
                    </div>




                    <div class="row cl">
                        <label class="form-label col-xs-4 col-sm-3">展示图片</label>
                        <div class="formControls col-xs-8 col-sm-7">
                            <p class="imgRule">仅支持png、jpg、jpeg,建议800*800,大小不超过6M</p>
                            <div class="updateDivImgs displayArrImg">
                                <div class="displayImgs">
                                    <!--<div class="displayImg">
                                        <div class="img_Box">
                                            <img src="${base}/resources/admin1.0/images/denglubj_icon.png" alt="">
                                        </div>
                                        <div class="img_model">
                                            <span class="delImg"></span>
                                        </div>
                                    </div>-->
                                </div>
                                <div class="updateImg">
                                    <div class="img_box"></div>
                                    <input type="hidden" name="images" value=""/>
                                    <a id="imgsFilePicker" class="file"
                                       style="display:block;width:60px;height:60px;margin:10px;opacity: 0" >gggggggggggggggggggggggggg</a>
                                    <div class="img_model">
                                        <span class="delImg"></span>
                                    </div>
                                </div>
                            </div>

                        </div>
                    </div>
                    <div class="row cl">
                        <label class="form-label col-xs-4 col-sm-3">${message("Goods.packagesNum")}</label>
                        <div class="formControls col-xs-8 col-sm-7">
                            <input type="text" class="input-text radius" placeholder="" name="packagesNum" />
                        </div>
                    </div>

                    <div class="row cl">
                        <label class="form-label col-xs-4 col-sm-3">${message("Goods.unit")}</label>
                        <div class="formControls col-xs-8 col-sm-7">
                            <input type="text" class="input-text radius down_list" readonly placeholder="请选择">
                            <input type="text" name="unit" class="downList_val" />
                            <ul class="downList_con">
                                <li val="">${message("admin.common.choose")}</li>
                                [#list units as unit]
                                    <li val="${unit}">${message("Goods.unit."+unit)}</li>
                                [/#list]

                            </ul>
                        </div>
                    </div>
                    <div class="row cl">
                        <label class="form-label col-xs-4 col-sm-3">${message("Goods.storageConditions")}</label>
                        <div class="formControls col-xs-8 col-sm-7">
									[#--<span class="select-box">
										<select class="select size-L" size="1" name="storageConditions">
											<option value="">${message("admin.common.choose")}</option>
											<option value="roomTemperature">${message("Goods.storageConditions.roomTemperature")}</option>
											<option value="refrigeration">${message("Goods.storageConditions.refrigeration")}</option>
											<option value="frozen">${message("Goods.storageConditions.frozen")}</option>
										</select>
									</span>--]
                                        <input type="text" class="input-text radius down_list" readonly placeholder="请选择">
                                        <input type="text" name="storageConditions" class="downList_val" />
                                        <ul class="downList_con">
                                            <li val="">${message("admin.common.choose")}</li>
                                            [#list storageConditions as storageCondition]
                                                <li val="${storageCondition}">${message("Goods.storageConditions."+storageCondition)}</li>
                                            [/#list]

                                        </ul>
                        </div>
                    </div>
                    <div class="row cl">
                        <label class="form-label col-xs-4 col-sm-3">${message("Goods.volume")}</label>
                        <div class="formControls col-xs-8 col-sm-7">
                            <div class="input_box">
                                <input type="text" class="" name="volume"/>
                                <div class="box_right input_right">
                                    <input type="text" readonly="readonly" class="weight_unit" value="cm³" />
                                    <input type="text" name="volumeUnit" class="downList_val" />
                                    <ul>
                                        [#list volumeUnits as volumeUnit]
                                            <li val="${volumeUnit}">${message("Goods.volume." + volumeUnit)}</li>
                                        [/#list]
                                    </ul>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="row cl">
                        <label class="form-label col-xs-4 col-sm-3">设置</label>
                        <div class="formControls skin-minimal col-xs-8 col-sm-9">
                            <div class="check-box">
                                <input type="checkbox" name="isMarketable" value="true" checked="checked" /><span>${message("Goods.isMarketable")}</span>
                                <input type="hidden" name="_isMarketable" value="false" />

								<label style="display: none">
									<input type="checkbox" name="isTop" value="true" [#if goods.isTop] checked="checked"[/#if] /><span>${message("Goods.isTop")}</span>
									<input type="hidden" name="_isTop" value="false" />
								</label>
                                <label style="display: none">
                                    <input type="checkbox" name="isList" value="true" checked="checked" />${message("Goods.isList")}
                                    <input type="hidden" name="_isList" value="false" />
                                </label>
                                <label style="display: none">
                                    <input type="checkbox" name="isDelivery" value="true" checked="checked" />${message("Goods.isDelivery")}
                                    <input type="hidden" name="_isDelivery" value="false" />
                                </label>

                            </div>
                        [#--<div class="check-box">
                            <input type="checkbox" name=""><span>是否列出</span>
                        </div>
                        <div class="check-box">
                            <input type="checkbox" name=""><span>是否置顶</span>
                        </div>--]
                        </div>
                    </div>

                    <div class="row cl" style="display:none;">
                        <label class="form-label col-xs-4 col-sm-3">${message("Product.marketPrice")}</label>
                        <div class="formControls col-xs-8 col-sm-7">
                            <input type="text" id="marketPrice" name="product.marketPrice" class="input-text radius" placeholder="">
                        </div>
                    </div>

                    <div class="row cl">
                        <label class="form-label col-xs-4 col-sm-3">${message("Product.price")}</label>
                        <div class="formControls col-xs-8 col-sm-7">
                        [#--<span class="input_no_span">4374837447832</span>--]
                            <input type="text" id="price" name="product.price" class="input-text" maxlength="100"  value="0"/>
                        </div>
                    </div>

                    <div class="row cl">
                        <label class="form-label col-xs-4 col-sm-3">标签</label>
                        <div class="formControls col-xs-8 col-sm-7">
                            <span class="labelSpan">新品</span>
                            <span class="labelSpan">热卖</span>
                            <span class="labelSpan">促销</span>
                            <span class="labelSpan">特惠</span>
                            <span class="labelSpan">人气</span>
                            <span class="labelSpan">爆款</span>
                        </div>
                    </div>

                </div>

                <div style="clear:both;"></div>

                <div >
	                <div class="row cl">
		                <label class="form-label col-xs-4 col-sm-3">是否秒杀</label>
		                <div class="formControls col-xs-8 col-sm-7">
		                    <div class="check-box">
		                        <input type="checkbox" id="activityType" name="product.activityType" value="1" /><span>商品超出秒杀数量后,按照正常的销售价购买</span>
		                        <input type="hidden" name="product.activityType" value="0" />
		                    </div>
		            	</div>
		            </div>
		            <div class="row cl">
		                <label class="form-label col-xs-4 col-sm-3"></label>
		                <div class="formControls col-xs-8 col-sm-7">
		                	<label>秒杀时间&nbsp;&nbsp;</label>
                            <input type="text" id="activityTimeShow" class="input-text radius down_list" readonly placeholder="请选择" style="width: 95px;left: 74px;"  disabled="true" >
                            <input type="text" id="activityTime" name="product.activityTime.id" class="downList_val" value="" style="width: 95px;" disabled="true"/>
                            <ul class="downList_con  " style="width: 95px;" >
                            	<li val="">${message("admin.common.choose")}</li>
                                <li val="1">10:00</li>
                            </ul>&nbsp;&nbsp;&nbsp;&nbsp;
		                	<label>秒杀价格&nbsp;&nbsp;</label><input type="text" id="activityPrice" name="product.activityPrice" class="input-text" maxlength="100"  value="${goods.defaultProduct.activityPrice}" style="width: 75px;"  disabled="true"  />&nbsp;&nbsp;&nbsp;&nbsp;
							<label>可秒杀数量&nbsp;&nbsp;</label><input type="text" id="maxActivityNumber" name="product.maxActivityNumber" class="input-text" maxlength="100"  value="${goods.defaultProduct.maxActivityNumber}" style="width: 75px;"  disabled="true"  />&nbsp;&nbsp;&nbsp;&nbsp;
							<input type="hidden" id="nowActivityNumber" name="product.nowActivityNumber" class="input-text" maxlength="100"  value="${goods.defaultProduct.nowActivityNumber}" style="width: 75px;"  disabled="true"  />
							<label>每人限购数量&nbsp;&nbsp;</label><input type="text" id="maxNumber" name="product.maxNumber" class="input-text" maxlength="100"  value="${goods.defaultProduct.maxNumber}" style="width: 75px;"  disabled="true"  />&nbsp;&nbsp;
		                	<input type="hidden" readonly="readonly" id="types" name="product.types" class="input-text" maxlength="100"  value="${goods.defaultProduct.types}" style="width: 75px;"  disabled="true"  />&nbsp;&nbsp;
		                </div>
		            </div>
				</div>

            </div>
            <div class="form_spec">
                <h3 class="form_title" style="margin:20px 0 0 20px;">商品规格</h3>
                <div class="" style="overflow: auto;">

                        <button type="button" class="op_button reset_spec" id="resetSpecification" >重置规格</button>
                        <button type="button" class="op_button reset_spec" id="addSpecButton" ">添加规格</button>
                        [#--<input type="hidden" id="productCategoryId1" name="productCategoryId1" />--]
                        <div class=''>
                            <div class="">
                                <div class="row">
                                    <div class="spec"  id="specificationTable" style="">
                                        <table>
                                            <tbody>
                                            <tr>
                                                <td class='lineOverflow'>
                                                    <ul class='lineNum_0'>
                                                        <li>
                                                            <img src="${base}/resources/admin1.0/images/bitian_icon.svg" alt="" />
                                                            ${message("Specification.name")}
                                                            <input type="text" class="input-text radius specificationItemName" name="specificationItems[0].name" id="name" maxlength="30" >
                                                        </li>

                                                        <li>
                                                            ${message("admin.common.order")}
                                                            <input type="text" class="input-text radius" name="order" id="order" maxlength="9">
                                                        </li>
                                                        <li>
                                                            <input type="hidden" name="specificationItems[0].entries[0].id" class="text specificationItemEntryId" value="0" \/>
                                                            规格 <input type="text" name="specificationItems[0].entries[0].value" class="input-text radius specificationItemEntryValue" value="" />
                                                            <input type="checkbox" name="specificationItems[0].entries[0].isSelected" value="true" \/>
                                                            <input type="hidden" name="_specificationItems[0].entries[0].isSelected" value="false" \/>

                                                        </li>
                                                    </ul>
                                                </td>
                                                <td align="right" width="10%">
                                                    <button type="button" id="addOptionButton_0" class="op_button add_B addOptionButton" overflow="left"></button>
                                                    <button type="button" id="delOptionButton_0" class="op_button del_B" overflow="left"></button>
                                                </td>

                                            </tr>
                                            </tbody>
                                        </table>

                                    </div>
                                </div>
                            </div>

                        </div>


                </div>

                <div  class="spec_form" style="margin-bottom:10px;">
                	<div class="table_box">
                    <table id="productTable" class="table table-border table-hover table_width">

                    </table>
                    </div>
                </div>
            </div>

            <div class="goodDetail">
                <h3 class="form_title" style="margin:20px 0 0 20px;">商品详情</h3>
                <div class="editorDiv" style="padding:10px 20px;">
                    <textarea id="description" name="introduction" class="editor" style="width: 100%;">${goods.introduction}</textarea>
                </div>
            </div>

        </div>
        <div class="footer_submit">
            <input class="btn radius confir_S" type="submit" value="${message("admin.common.submit")}">
            <input class="btn radius cancel_B" type="button" value="${message("admin.common.back")}" onclick="history.back();return false;">
        </div>
    </div>

</form>



<!--模仿bootstrap的模态框-->
<div id="motaikunag" style="display: none;">
    <div class="layui-row">
        <div class="layui-col-md9">
            你的内容 9/12
        </div>
        <div class="layui-col-md3">
            你的内容 3/12
        </div>
    </div>
    <div class="layui-row">
        <div class="layui-col-md3">
            名字
        </div>
        <div class="layui-col-md9">
            <input type="text" name="testname" value="">
        </div>
    </div>

    <br/>
    <input type="button" onclick="javascript:alert('点击按钮')" title="点我" value="点我">
</div>


<script src="${base}/resources/admin1.0/js/jquery.min.js"></script>
<script type="text/javascript" src="${base}/resources/admin1.0/js/jquery.tools.js"></script>
<script type="text/javascript" src="${base}/resources/admin1.0/ueditor/ueditor.js"></script>
<script src="${base}/resources/admin1.0/js/validate/jquery.validate.min.js"></script>
<script type="text/javascript" src="${base}/resources/admin1.0/H-ui/lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="${base}/resources/admin1.0/js/webuploader.js"></script>
<script type="text/javascript" src="${base}/resources/admin1.0/js/common.js"></script>
<script type="text/javascript" src="${base}/resources/admin1.0/zwz/layui/layui.js"></script>

<script type="text/javascript">
        var $inputForm = $("#inputForm");
        var $isDefault = $("#isDefault");
        var $productCategoryId = $("#productCategoryId");
        var $activityType = $("#activityType");
        var $maxNumber = $("#maxNumber");
        var $activityTime = $("#activityTime");
        var $activityTimeShow = $("#activityTimeShow");
        var $activityPrice = $("#activityPrice");
        var $maxActivityNumber = $("#maxActivityNumber");
        var $nowActivityNumber = $("#nowActivityNumber");
        var $types = $("#types");
        var $type = $("#type");
        var $price = $("#price");
        var $cost = $("#cost");
        var $marketPrice = $("#marketPrice");
        var $rewardPoint = $("#rewardPoint");
        var $exchangePoint = $("#exchangePoint");
        var $stock = $("#stock");
        var $promotionIds = $("input[name='promotionIds']");
        var $introduction = $("#introduction");
        var $productImageTable = $("#productImageTable");
        var $addProductImage = $("#addProductImage");
        var $parameterTable = $("#parameterTable");
        var $addParameter = $("#addParameter");
        var $resetParameter = $("#resetParameter");
        var $attributeTable = $("#attributeTable");
        var $specificationTable = $("#specificationTable");
        var $resetSpecification = $("#resetSpecification");
        var $productTable = $("#productTable");
        var productImageIndex = 0;
        var parameterIndex = 0;
        var specificationItemEntryId = 0;
        var specificationItemName = 0;
        //所在行
        var row = 0;
        //所在列
        var cloumn = 0;

        //定义二维数组,key:row,value:cloum,存放input行和列的数组
        var inputArray = [];

        var hasSpecification = false;
        var labels = [];

        var $barCode = $("#barCode") ;
    $().ready(function() {

        [@flash_message /]

        /*var previousProductCategoryId = getCookie("previousProductCategoryId");
        previousProductCategoryId != null ? $productCategoryId.val(previousProductCategoryId) : previousProductCategoryId = $productCategoryId.val();*/

        /*标签的点击*/

        var colorArr=['newProducts','selling','promotions','specialOffer','popularity','explosions'];
        $(".labelSpan").on("click",function(){
            var index = $(this).index();

            if($(this).hasClass(colorArr[index])){
                $(this).removeClass(colorArr[index]);
            }else{
                if(labels.length == 3){
                    console.log(labels.length);
                    $.message("warn", "只能选择三个标签");
                    return;
                }

                $(this).addClass(colorArr[index]);
            }

            var bool = $.inArray(colorArr[index], labels);
            //判断数组中是否存在该标签,没有就添加,有就删除
            if(bool<0){
                labels.push(colorArr[index]);
            }else{
                removeByValue(labels,colorArr[index]);
            }

            console.log(labels);
            $("#labels").val(labels);

        });


        //删除数组中指定的元素
        function removeByValue(arr, val) {
            for(var i=0; i<arr.length; i++) {
                if(arr[i] == val) {
                    arr.splice(i, 1);
                    break;
                }
            }
        }

        /*富文本编辑*/
        $("#description").editor();

        /*主图上传图片*/
        var $filePicker = $("#filePicker");
        $filePicker.uploader({
            maxSize:6,
            before:function(file){
                console.log(file);
            },
            complete:function(file,data){

                console.log(data);
                if(data.state == 'SUCCESS'){
                    $(".mainImg .img_box").html("<img src='' />");
                    $(".mainImg img").attr("src", data.url);
                    $("input[name=image]").val(data.url);
                }

            }
        });

        /*展示图上传图片*/
        var imgsFilePicker = $("#imgsFilePicker");
        imgsFilePicker.uploader({
            maxSize:6,
            before:function(file){
                console.log(file);
            },
            complete:function(file,data){
                console.log(data);
                if(data.state == 'SUCCESS'){
                    var img = '<div class="displayImg"><div class="img_Box">'+
                        '<img src="'+data.url+'" alt="">'+
                        '</div><div class="img_model"><span class="delImg"></span></div></div>'

                    $(".displayImgs").append(img);

                    var imgsString = $("input[name=images]").val();
                    imgsString = imgsString.replace(/[\[|\]]/gi,'');
                    var imgsArr = [];

                    if(imgsString != ''){
                        var imgsArr = imgsString.split(',');
                    }

                    imgsArr.push(data.url);
                    imgDisplayBool(imgsArr);
                    $('input[name=images]').val(imgsArr);

                }
            }
        });

        /*当图片大于2张时,隐藏上传按钮*/
        function imgDisplayBool(imgsArr){
            if(imgsArr.length>=2){
                $(".displayArrImg .updateImg").css("display",'none');
            }else{
                $(".displayArrImg .updateImg").css("display",'inline-block');
            }
        }

        /*主图删除图片*/
        $(".mainImg .delImg").on("click", function () {
            $(".mainImg .img_box").html("");
            $(this).parent().css("display", "none");

            $(this).parent().siblings("input:text").val("");
        });

        /*主图删除图片*/
        $(".mainImg .img_box").mouseover(function () {
            $(".mainImg .img_model").css("display", "block");
        });
        $(".mainImg .img_model").mouseleave(function () {
            $(".mainImg .img_model").css("display", "none");
        });

        /*展示图删除*/
        $(".displayImgs").delegate(".displayImg .delImg","click",function(){

            var imgsString = $("input[name=images]").val();
            imgsString = imgsString.replace(/[\[|\]]/gi,'');
            var imgsArr = imgsString.split(',');

            var index = $(this).closest('.displayImg').index();
            $(this).closest('.displayImg').remove();
            imgsArr.splice(index, 1);
            imgDisplayBool(imgsArr);
            $('input[name=images]').val(imgsArr);
        });



        $(".in_no_all").click(function () {
            if (this.checked) {
                $(this).parent().parent().find(".in_no").attr("disabled", false);
                $(this).parent().parent().find(".no_dafault").attr("disabled", false);
                if ($("input[name='dafault']:checked")) {

                } else {
                    $(".no_dafault").eq(0);
                }
            } else {
                $(this).parent().parent().find(".in_no").attr("disabled", true);
                $(this).parent().parent().find(".no_dafault").attr("disabled", true).attr("checked", this.checked);
                ;
            }
        })

		/*单位的下拉列表*/
		$(".input_box").each(function(){
            $(this).find("ul li").eq(0).addClass("li_bag");
            var firstText = $(this).find("li:eq(0)").text();
            var firstVal = $(this).find("li:eq(0)").attr("val");
        	$(this).find(".weight_unit").val(firstText);
        	$(this).find(".downList_val").val(firstVal);
       	});




		/*获取页面的高度*/
        var formHeight = $(document.body).height() - 100;
        $(".form_box").css("height", formHeight);

		/*下拉框的样式*/
        $(".input_box .box_right ul li").on("click",function(){
            $(this).parent().siblings(".weight_unit").val($(this).html());
            $(this).parent().siblings(".downList_val").val($(this).attr("val"));

            $(this).parent().css("display","none");
            $(this).addClass("li_bag").siblings().removeClass("li_bag");
        });
        $(".input_box .box_right").mouseover(function(){
            $(this).find("ul").css("display","block");
        });
        $(".input_box .box_right").mouseout(function(){
            $(this).find("ul").css("display","none");
        });

        $(".down_list").click(function(){
            $(this).siblings(".downList_con").toggle();
        });

        $("*").click(function (event) {
            if (!$(this).hasClass("down_list")&&!$(this).hasClass("downList_con")){
                $(".downList_con").hide();
            }
            event.stopPropagation();
        });

        $(".downList_con").each(function(){
        	$(this).find("li:eq(0)").addClass("li_bag");
        	var firstText = $(this).find("li:eq(0)").text();
        	var firstVal = $(this).find("li:eq(0)").attr("val");
        	$(this).siblings(".down_list").val(firstText);
        	$(this).siblings(".downList_val").val(firstVal);
        });



        $(".downList_con li").click(function(){
            $(this).parent().siblings(".down_list").attr("value",$(this).text());
          	$(this).parent().siblings(".downList_val").val($(this).attr("val"));

            $(this).parent().siblings(".downList_val").change();

            $(this).addClass("li_bag").siblings().removeClass("li_bag");

            var _this = this;
            //选择某个分类--获取品牌
            if($(this).parent().hasClass('categoryUl')){
                $.get("${base}/admin/goods/publicbrandList.jhtml",{"productCategoryId":$(_this).attr("val")},function(o){
                    var data=o.data;
                    var lis="";
                    for (var i = 0; i < data.length; i++) {
                        lis+="<li val='"+data[i]+"'> "+data[i]+"</li>";
                    }
                    $("#brandUl").html(lis);
                    $("#brandInp").val('');
                    $("#brandName").val('');
                    $("#goodsName").val('');
                    $(".nameUl").html('');

                });
            }

        });


        console.log($('.categoryUl li'));
        if($('.categoryUl li').length>0){

            var value = $('.categoryUl li').eq(0).attr('val');
             $.get("${base}/admin/goods/publicbrandList.jhtml",{"productCategoryId":value},function(o){
                var data=o.data;
                var lis="";
                for (var i = 0; i < data.length; i++) {
                    lis+="<li val='"+data[i]+"'> "+data[i]+"</li>";
                }
                $("#brandUl").html(lis);

            });
        }

        //点击品牌
        $(".brandDiv .downList_con").delegate('li','click',function(){
            $(this).parent().siblings(".down_list").attr("value",$(this).text());
          	$(this).parent().siblings(".downList_val").val($(this).attr("val"));
            $(this).parent().siblings(".downList_val").change();
            $(this).addClass("li_bag").siblings().removeClass("li_bag");
            $(this).parent().toggle();

            var _this = this;



            //选择品牌--获取商品名称列表
            $.get("${base}/admin/goods/publicGoodsNameList.jhtml",{"productCategoryId":$('#productCategoryId').val(),"brandName":$(_this).text()},function(o){
                var data=o.data;
                var lis="";
                for (var i = 0; i < data.length; i++) {
                    lis+="<li val='"+data[i]+"'> "+data[i]+"</li>";
                }
                $(".nameUl").html(lis);

            });


        });
         $(".nameDiv .downList_con").delegate('li','click',function(){
            $(this).parent().siblings(".down_list").attr("value",$(this).text());
            $(this).parent().siblings(".downList_val").change();
            $(this).addClass("li_bag").siblings().removeClass("li_bag");
            $(this).parent().toggle();
        });

		// 是否秒杀	启用/禁用相关选项;	types相应改动
        $("#activityType").on("change",function(){
            if ($("#activityType").is(":checked")) {
            	$("#maxNumber").prop("disabled", false);
            	$("#activityTime").prop("disabled", false);
            	$("#activityTimeShow").prop("disabled", false);
            	$("#activityPrice").prop("disabled", false);
            	$("#maxActivityNumber").prop("disabled", false);
            	$("#nowActivityNumber").prop("disabled", false);
            	$("#types").prop("disabled", false);
            	$("#types").prop("value", "pike");
            } else {
            	$("#maxNumber").prop("disabled", true);
            	$("#activityTime").prop("disabled", true);
            	$("#activityTimeShow").prop("disabled", true);
            	$("#activityPrice").prop("disabled", true);
            	$("#maxActivityNumber").prop("disabled", true);
            	$("#nowActivityNumber").prop("disabled", true);
            	$("#types").prop("disabled", true);
            }
        });

        // maxNumber变动,每人限购数量maxNumber < 可秒杀数量maxActivityNumber
        $("#maxNumber").on("change",function(){
        	if(parseFloat($("#maxActivityNumber").val())<parseFloat($("#maxNumber").val())){
            	$.message("warn", "可秒杀数量必须大于每人限购数量");
        	}
        });

        // maxActivityNumber变动,当天剩余秒杀数量 = 可秒杀数量
        $("#maxActivityNumber").on("change",function(){
        	$("#nowActivityNumber").val($("#maxActivityNumber").val());
            if(parseFloat($("#maxActivityNumber").val())<parseFloat($("#maxNumber").val())){
            	$.message("warn", "可秒杀数量必须大于每人限购数量");
        	}
        });

        //处理品牌
        /*--  $("#brandInp").focus(function(){
            var productCategoryId=$("#productCategoryId").val();
            //$adminDiv.find("input").val('');
            $.get("${base}/admin/goods/publicbrandList.jhtml",{"productCategoryId":productCategoryId},function(o){
                var data=o.data;
                var lis="";
                for (var i = 0; i < data.length; i++) {
                    lis+="<li val='"+data[i]+"'> "+data[i]+"</li>";
                }
                $("#brandUl").html(lis);
            });
        });  -*/

        /*$("#goodsName").focus(function() {
            var productCategoryId=$("#productCategoryId").val();
            var brandName=$("#brandName").val();
            $.get("${base}/admin/goods/publicGoodsNameList.jhtml",{"productCategoryId":productCategoryId,"brandName":brandName},function(o){
                var data=o.data;
                var lis="";
                for (var i = 0; i < data.length; i++) {
                    lis+="<li val='"+data[i]+"'> "+data[i]+"</li>";
                }
                $("#brandUl").html(lis);
            });
        });*/

        //loadSpecification();

        // 商品分类
        /*$productCategoryId.change(function() {
            loadSpecification();
            //previousProductCategoryId = $productCategoryId.val();
        });*/



        $("#submit_spec").click(function () {

            var id = $("#productCategoryId").val();
            $('#productCategoryId1').val(id);
            var productCategoryId1 = $("#productCategoryId1").val();
            var name = $("#name").val();
            var order = $("#order").val();
            var arr =[];
            $("input[name='options']").each(function(){
                arr.push($(this).val());
            });
            /*$.ajax({
                //几个参数需要注意一下
                type: "POST",//方法类型
                dataType: "json",//预期服务器返回的数据类型
                url: "save_new_spec.jhtml" ,//url
                data: {"productCategoryId": productCategoryId1,
                    "name": name,
                    "order": order,
                    "options": arr},
                success: function (result) {
                    console.log(result);//打印服务端返回的数据(调试用)
                    if (result.resultCode == 200) {
                        console.log("SUCCESS");
                    }
                    ;
                },
                error : function() {
                    console.log("异常!");
                }
            });*/
            //loadSpecification1();
            changeView();
            buildProductTable();
        });

        // 类型
        $type.change(function() {
            changeView();
            buildProductTable();
        });

        // 修改视图
        function changeView() {
            if (hasSpecification) {
                $isDefault.prop("disabled", true);
                $activityType.prop("disabled", true);
                $price.add($cost).add($barCode).prop("disabled", true).closest("div.row").hide();
                $activityType.add($maxNumber).add($activityTime).add($activityPrice)
                .add($maxActivityNumber).add($nowActivityNumber).add($types)
                .prop("disabled", true).closest("div.row").hide();

            } else {
                $isDefault.prop("disabled", false);
                $activityType.prop("disabled", false);
                $cost.add($barCode).add($price).prop("disabled", false).closest("div.row").show();
                $activityType.add($maxNumber).add($activityTime).add($activityPrice)
                .add($maxActivityNumber).add($nowActivityNumber).add($types)
                .prop("disabled", false).closest("div.row").show();
            }
        }

        // 重置规格
        $resetSpecification.click(function() {

            $.dialog({
                type: "warn",
                content: "${message("admin.goods.resetSpecificationConfirm")}",
                width: 450,
                onOk: function() {
                    hasSpecification = false;
                    //清空input值
                    $(".spec input").val("");
                    //清空选中的复选框
                    $(".spec input[type='checkbox']").each(function(){this.checked=false;});
                }
            });
        });


        /*添加行*/
        $("#addSpecButton").click(function(){
            specificationItemEntryId ++;
            row ++;
            //添加行时,重置列
            cloumn = 0;
            var spcObj = '<tr>\n' +
                '           <td class=\'lineOverflow\'>\n' +
                '               <ul class=\'lineNum_'+row+'\'>\n' +
                '                   <li>\n' +
                '                       <img src="${base}/resources/admin1.0/images/bitian_icon.svg" alt="" />\n' +
                '                       ${message("Specification.name")}\n' +
                '                       <input type="text" class="input-text radius specificationItemName" name="specificationItems[1].name" maxlength="30" >\n' +
                '                   </li>\n' +
                '\n' +
                '                   <li>\n' +
                '                       ${message("admin.common.order")}\n' +
                '                       <input type="text" class="input-text radius" name="order1"  maxlength="9">\n' +
                '                   </li>\n' +
                '                   <li>\n' +
                '                       <input type="hidden" name="specificationItems['+row+'].entries[0].id" class="text specificationItemEntryId" value="0" \\/>\n' +
                '                       规格<input type="text" name="specificationItems['+row+'].entries[0].value" class="input-text radius specificationItemEntryValue" value="" />\n' +
                '                       <input type="checkbox" name="specificationItems['+row+'].entries[0].isSelected" value="true" \\/>\n' +
                '                       <input type="hidden" name="_specificationItems['+row+'].entries[0].isSelected" value="false" \\/>\n' +
                '                   </li>\n' +
                '\n' +
                '                </ul>\n' +
                '             </td>\n' +
                '             <td align="right" width="10%">\n' +
                '               <button type="button" id="addOptionButton_'+row+'" class="op_button add_B" overflow="left" onclick="addRow(this)"></button>\n' +
                '               <button type="button" id="delOptionButton_'+row+'" class="op_button del_B" overflow="left" onclick="delRow(this)"></button>\n' +
                '             </td>\n' +
                '           </tr>';
            $(".spec tbody").append(
                [@compress single_line = true]
                    spcObj
                [/@compress]
            );
        });


        //addOptionButton 操作标记
        var add= "addOptionButton_"+specificationItemName;
        var del= "delOptionButton_"+specificationItemName;
        //tr所在行
        //var trlineNum= ".lineNum_"+row;
        /*添加可选项  cloumn*/
        $('#'+add).click(function(){

            var $thisRow = $(this).parent();
            //当前所在行
            var curretRow = $thisRow.parent().parent().find('tr').index($thisRow.parent()[0]);

            //addOptionButton 操作标记
            var add= "addOptionButton_"+specificationItemName;
            //tr所在行
            var trlineNum= ".lineNum_"+curretRow;
            specificationItemEntryId ++;
            //cloumn ++;
            var currentLi = trlineNum+" li";
            //获取表格中li当前行最后一列,第一个input值
            var currentValue = $(currentLi).last().find('input').first().val();
            var current = currentValue*1+1;
            $(trlineNum).append(
                [@compress single_line = true]
                    '
                    <li>
                        <input type="hidden" name="specificationItems['+curretRow+'].entries['+current+'].id" class="text specificationItemEntryId" value="' + current + '" \/>
                        <input type="text" name="specificationItems['+curretRow+'].entries['+current+'].value" class="input-text radius specificationItemEntryValue" value="" />
                        <input type="checkbox" name="specificationItems['+curretRow+'].entries['+current+'].isSelected" value="true" \/>
                        <input type="hidden" name="_specificationItems['+curretRow+'].entries['+current+'].isSelected" value="false" \/>

                    </li>
                    '
                [/@compress]
             );
        });

        /*删除规格项*/
        $("#"+del).click(function(){
            var $thisRow = $(this).parent();
            var curretRow = $thisRow.parent().parent().find('tr').index($thisRow.parent()[0]);
            //tr所在行
            var trlineNum= ".lineNum_"+curretRow;

            var currentLi = trlineNum+" li";
            //获取表格中li当前行最后一列,第一个input值
            var currentValue = $(currentLi).last().find('input').first().val();
            if(currentValue*1 > 0){
                $(""+trlineNum+" li").last().remove();
            }else {

                $.dialog({
                    type: "warn",
                    content: "无法继续删除",
                    width: 250,
                    onOk: function() {
                    }
                });
            }


        });

        // 选择规格
        $specificationTable.on("change", "input:checkbox", function() {
            if ($specificationTable.find("input:checkbox:checked").size() > 0) {
                hasSpecification = true;
            } else {
                hasSpecification = false;
            }
            changeView();
            buildProductTable();
        });

        // 规格
        $specificationTable.on("change", "input:text", function() {
            var $this = $(this);
            var value = $.trim($this.val());
            if (value == "") {
                $this.val($this.data("value"));
                return false;
            }
            if ($this.hasClass("specificationItemEntryValue")) {
                var values = $this.closest("tr").find("input.specificationItemEntryValue").not($this).map(function() {
                    return $.trim($(this).val());
                }).get();
                if ($.inArray(value, values) >= 0) {
                    $.message("warn", "${message("admin.goods.specificationItemEntryValueRepeated")}");
                    $this.val($this.data("value"));
                    return false;
                }
            }
            $this.data("value", value);
            buildProductTable();
        });

        // 是否秒杀	启用/禁用相关选项;	types相应改动
        $productTable.on("change", "input.activityType", function() {
            var $this = $(this);
            if ($this.prop("checked")) {
            	$this.closest('tr').find(".maxNumber").prop("disabled", false);
            	$this.closest('tr').find(".activityTime").prop("disabled", false);
            	$this.closest('tr').find(".activityPrice").prop("disabled", false);
            	$this.closest('tr').find(".maxActivityNumber").prop("disabled", false);
            	$this.closest('tr').find(".nowActivityNumber").prop("disabled", false);
            	$this.closest('tr').find(".types").prop("disabled", false);
            	$this.closest('tr').find(".types").prop("value", "pike");
            } else {
            	$this.closest('tr').find(".maxNumber").prop("disabled", true);
            	$this.closest('tr').find(".activityTime").prop("disabled", true);
            	$this.closest('tr').find(".activityPrice").prop("disabled", true);
            	$this.closest('tr').find(".maxActivityNumber").prop("disabled", true);
            	$this.closest('tr').find(".nowActivityNumber").prop("disabled", true);
            	$this.closest('tr').find(".types").prop("disabled", true);
            }
        });

        // maxNumber变动,每人限购数量maxNumber < 可秒杀数量maxActivityNumber
        $productTable.on("change", "input.maxNumber", function() {
            var $this = $(this);
            var maxActivityNumber = $this.closest('tr').find(".maxActivityNumber").val();
            var maxNumber = $this.closest('tr').find(".maxNumber").val();
            if(parseFloat(maxActivityNumber)<parseFloat(maxNumber)){
            	$.message("warn", "可秒杀数量必须大于每人限购数量");
        	}
        });

        // maxActivityNumber变动,当天剩余秒杀数量 = 可秒杀数量
        $productTable.on("change", "input.maxActivityNumber", function() {
            var $this = $(this);
            var maxActivityNumber = $this.closest('tr').find(".maxActivityNumber").val();
            var maxNumber = $this.closest('tr').find(".maxNumber").val();
            if(parseFloat(maxActivityNumber)<parseFloat(maxNumber)){
            	$.message("warn", "可秒杀数量必须大于每人限购数量");
        	}
            $this.closest('tr').find(".nowActivityNumber").prop("value", maxActivityNumber);
        });

        // 是否默认
        $productTable.on("change", "input.isDefault", function() {
            var $this = $(this);
            if ($this.prop("checked")) {
                $productTable.find("input.isDefault").not($this).prop("checked", false);
            } else {
                $this.prop("checked", true);
            }
        });

        // 是否启用
        $productTable.on("change", "input.isEnabled", function() {
            var $this = $(this);
            if ($this.prop("checked")) {
                $this.closest("tr").find("input:not(.isEnabled)").prop("disabled", false);
            	//开启时,根据活动是否开启判断活动相关字段是否禁止
                if ($this.closest('tr').find(".activityType").prop("checked")) {
	            	$this.closest('tr').find(".maxNumber").prop("disabled", false);
	            	$this.closest('tr').find(".activityTime").prop("disabled", false);
	            	$this.closest('tr').find(".activityPrice").prop("disabled", false);
	            	$this.closest('tr').find(".maxActivityNumber").prop("disabled", false);
	            	$this.closest('tr').find(".nowActivityNumber").prop("disabled", false);
	            	$this.closest('tr').find(".types").prop("disabled", false);
	            	$this.closest('tr').find(".types").prop("value", "pike");
	            } else {
	            	$this.closest('tr').find(".maxNumber").prop("disabled", true);
	            	$this.closest('tr').find(".activityTime").prop("disabled", true);
	            	$this.closest('tr').find(".activityPrice").prop("disabled", true);
	            	$this.closest('tr').find(".maxActivityNumber").prop("disabled", true);
	            	$this.closest('tr').find(".nowActivityNumber").prop("disabled", true);
	            	$this.closest('tr').find(".types").prop("disabled", true);
	            }
            } else {
            	$this.closest('tr').find(".activityTime").prop("disabled", true);
                $this.closest("tr").find("input:not(.isEnabled)").prop("disabled", true).end().find("input.isDefault").prop("checked", false);
            }
            if ($productTable.find("input.isDefault:not(:disabled):checked").size() == 0) {
                $productTable.find("input.isDefault:not(:disabled):first").prop("checked", true);
            }
        });

        // 生成商品表
        function buildProductTable() {
            var type = $type.val();
            var productValues = {};
            var specificationItems = [];
            if (!hasSpecification) {
                $productTable.empty()
                return false;
            }
            $specificationTable.find("ul").each(function() {
                var $this = $(this);
                var $checked = $this.find("input:checkbox:checked");
                if ($checked.size() > 0) {
                    var specificationItem = {};
                    specificationItem.name = $this.find("input.specificationItemName").val();
                    specificationItem.entries = $checked.map(function() {
                        return {
                            id: $(this).siblings("input.specificationItemEntryId").val(),
                            value: $(this).siblings("input.specificationItemEntryValue").val()
                        };
                    }).get();
                    specificationItems.push(specificationItem);
                }
            });
            var products = cartesianProductOf($.map(specificationItems, function(specificationItem) {
                return [specificationItem.entries];
            }));
            $productTable.find("tr:gt(0)").each(function() {
                var $this = $(this);
                productValues[$this.data("ids")] = {
                    price: $this.find("input.price").val(),
                    activityType: $this.find("input.activityType").prop("checked"),
                    maxNumber : $this.find("input.maxNumber").val(),
                    activityTime  : $this.find(".activityTime").val(),
                    activityPrice : $this.find("input.activityPrice").val(),
                    maxActivityNumber : $this.find("input.maxActivityNumber").val(),
                    nowActivityNumber : $this.find("input.nowActivityNumber").val(),
                    types : $this.find("input.types").val(),
                    cost: $this.find("input.cost").val(),
                    marketPrice: $this.find("input.marketPrice").val(),
                    rewardPoint: $this.find("input.rewardPoint").val(),
                    exchangePoint: $this.find("input.exchangePoint").val(),
                    stock: $this.find("input.stock").val(),
                    isDefault: $this.find("input.isDefault").prop("checked"),
                    isEnabled: $this.find("input.isEnabled").prop("checked"),
                    barCode: $this.find("input.barCode").val()
                };
            });
            $titleTr = $('<tr class="text-l"><\/tr>').appendTo($productTable.empty());
            $.each(specificationItems, function(i, specificationItem) {
                $titleTr.append('<th>' + escapeHtml(specificationItem.name) + '<\/th>');
            });
        $titleTr.append(
            [@compress single_line = true]
            '<th>条形码<\/th>'+
            (type == "general" ? '<th>${message("Product.price")}<\/th>' : '') + '
            <th>
                ${message("Product.cost")}
            <\/th>
            '+ (type == "general" ? '
            <th>秒杀价格<\/th>
            <th>可秒杀数量<\/th>
            <th>秒杀时间<\/th>
            <th>每人限购数量<\/th>
            <th>是否秒杀<\/th>
            ' : '') + '
            <th class="hidden">
            	${message("Product.marketPrice")}
            <\/th>
            ' + (type == "general" ? '<th class="hidden">${message("Product.rewardPoint")}<\/th>' : '') +
            (type == "exchange" ? '<th class="hidden">${message("Product.exchangePoint")}<\/th>' : '') + '
            <th class="hidden">
                ${message("Product.stock")}
            <\/th>
            <th>
            	${message("Product.isDefault")}
            <\/th>
            <th>
            	${message("admin.goods.isEnabled")}
            <\/th>'
            [/@compress]
        );
            $.each(products, function(i, entries) {
                var ids = [];
                $productTr = $('<tr class="text-l"><\/tr>').appendTo($productTable);
                $.each(entries, function(j, entry) {
                $productTr.append(
                    [@compress single_line = true]
                            '<td>
                        ' + escapeHtml(entry.value) + '
                        <input type="hidden" name="productList[' + i + '].specificationValues[' + j + '].id" value="' + entry.id + '" \/>
                        <input type="hidden" name="productList[' + i + '].specificationValues[' + j + '].value" value="' + escapeHtml(entry.value) + '" \/>
                        <\/td>'
                    [/@compress]
                    );
                    ids.push(entry.id);
                });
                var productValue = productValues[ids.join(",")];
                var price = productValue != null && productValue.price != null ? productValue.price : "";
                var activityType = productValue != null && productValue.activityType != null ? productValue.activityType : 0;
                var maxNumber = productValue != null && productValue.maxNumber != null ? productValue.maxNumber : "";
                var activityTime = productValue != null && productValue.activityTime != null ? productValue.activityTime : "";
                var activityTimeDateStr = productValue != null && productValue.activityTimeDateStr != null ? productValue.activityTimeDateStr : "";
                var activityPrice = productValue != null && productValue.activityPrice != null ? productValue.activityPrice : "";
                var maxActivityNumber = productValue != null && productValue.maxActivityNumber != null ? productValue.maxActivityNumber : "";
                var nowActivityNumber = productValue != null && productValue.nowActivityNumber != null ? productValue.nowActivityNumber : maxActivityNumber;
                var types = productValue != null && productValue.types != null ? productValue.types : "";
                var cost = productValue != null && productValue.cost != null ? productValue.cost : "";
                var marketPrice = productValue != null && productValue.marketPrice != null ? productValue.marketPrice : "";
                var rewardPoint = productValue != null && productValue.rewardPoint != null ? productValue.rewardPoint : "";
                var exchangePoint = productValue != null && productValue.exchangePoint != null ? productValue.exchangePoint : "";
                var stock = productValue != null && productValue.stock != null ? productValue.stock : "";
                var isDefault = productValue != null && productValue.isDefault != null ? productValue.isDefault : false;
                var isEnabled = productValue != null && productValue.isEnabled != null ? productValue.isEnabled : false;
                var barCode = productValue != null && productValue.barCode != null ? productValue.barCode : "";

            $productTr.append(
                [@compress single_line = true]
                '<td><input type="text" name="productList[' + i + '].barCode" class="price_form_p text barCode" value="' + barCode + '" maxlength="50"  \/><\/td>'+
                (type == "general" ? '<td><p class="price_form_p">
                <span>¥<\/span><input type="text" name="productList[' + i + '].price" class="text price" value="' + price + '" maxlength="16"  \/><\/p><\/td>' : '') + '
                <td>
                	<p class="price_form_p">
	                    <span>¥<\/span>
	                	<input type="text" name="productList[' + i + '].cost" class="in_no cost" value="' + cost + '" maxlength="16"  \/>
                    <\/p>
                <\/td>
                '+
                (type == "general" ? '
                	<td>
	                	<p class="price_form_p">
	                    <span>¥<\/span>
	                	<input type="text" name="productList[' + i + '].activityPrice" class="text price activityPrice" value="' + activityPrice + '" maxlength="16" ' + (!activityType ? ' disabled="true"' : '') + '  \/>
	                    <\/p>
	                <\/td>
                	<td>
                		<p class="price_form_p" style="width: 52px;">
	                		<input type="text" name="productList[' + i + '].maxActivityNumber" class="maxActivityNumber text price_form_p" value="' + maxActivityNumber + '" style="width: 50px;" ' + (!activityType ? ' disabled="true"' : '') + '  \/>
	                	<\/p>
	                <\/td>
                	<td>
                        <select name="productList[' + i + '].activityTime.id" class="activityTime text price_form_p" style="width: 50px;" ' + (!activityType ? ' disabled="true"' : '') + '>
					        <option >${message("admin.common.choose")}</option \/>
					        <option value="1" ' + (activityTime=="1" ? ' selected=true' : '') + ' >10:00</option \/>
					    </select \/>
	                <\/td>
                	<td>
                		<p class="price_form_p" style="width: 52px;">
	                		<input type="text" name="productList[' + i + '].maxNumber" class="text maxNumber price_form_p" value="' + maxNumber + '" style="width: 50px;" ' + (!activityType ? ' disabled="true"' : '') + ' \/>
	                	<\/p>
	                <\/td>
                	<td>
	                	<input type="checkbox" name="productList[' + i + '].activityType" class="activityType" value="1"' + (activityType ? ' checked="checked"' : '') + ' \/>
	                    <input type="hidden" name="productList[' + i + '].activityType" value="0" \/>
		                <input type="hidden" name="productList[' + i + '].nowActivityNumber" class="text price_form_p nowActivityNumber" value="' + nowActivityNumber + '" style="width:20px" ' + (!activityType ? ' disabled="true"' : '') + '  \/>
	                	<input type="hidden" name="productList[' + i + '].types" class="in_no types" value="' + types + '" style="width:20px" ' + (!activityType ? ' disabled="true"' : '') + '  \/>
                	<\/td>
                ' : '') + '
                <td class="hidden">
	                <p class="price_form_p">
	                <span>¥<\/span>
	                <input type="text" name="productList[' + i + '].marketPrice" class="text marketPrice" value="' + marketPrice + '" maxlength="16"  \/><\/p>
                <\/td>
                ' + (type == "general" ? '<td class="hidden"><input type="text" name="productList[' + i + '].rewardPoint" class="text rewardPoint" value="' + rewardPoint + '" maxlength="9" style="width: 50px;" \/><\/td>' : '') +
                (type == "exchange" ? '<td class="hidden"><input type="text" name="productList[' + i + '].exchangePoint" class="text exchangePoint" value="' + exchangePoint + '" maxlength="9" style="width: 50px;" \/><\/td>' : '') + '
                <td class="hidden">
                    <input type="text" name="productList[' + i + '].stock" class="text stock" value="99999999" maxlength="9" style="width: 50px;" \/>
                <\/td>
                <td>
                	<input type="checkbox" name="productList[' + i + '].isDefault" class="isDefault" value="true"' + (isDefault ? ' checked="checked"' : '') + ' \/>
                    <input type="hidden" name="_productList[' + i + '].isDefault" value="false" \/>
                <\/td>
                <td>
                	<input type="checkbox" name="isEnabled" class="isEnabled" value="true"' + (isEnabled ? ' checked="checked"' : '') + ' \/>
                <\/td>'
                [/@compress]
                ).data("ids", ids.join(","));
                if (!isEnabled) {
                    $productTr.find(":input:not(.isEnabled)").prop("disabled", true);
                }
            });
            if ($productTable.find("input.isDefault:not(:disabled):checked").size() == 0) {
                $productTable.find("input.isDefault:not(:disabled):first").prop("checked", true);
            }
            if ($productTable.find("input.activityType:not(:disabled):checked").size() == 0) {
                $productTable.find("input.isDefault:not(:disabled):first").prop("checked", true);
            }
        }

        // 笛卡尔积
        function cartesianProductOf(array) {
            function addTo(current, args) {
                var i, copy;
                var rest = args.slice(1);
                var isLast = !rest.length;
                var result = [];
                for (i = 0; i < args[0].length; i++) {
                    copy = current.slice();
                    copy.push(args[0][i]);
                    if (isLast) {
                        result.push(copy);
                    } else {
                        result = result.concat(addTo(copy, rest));
                    }
                }
                return result;
            }
            return addTo([], array);
        }

        // 加载规格
        function loadSpecification() {
            $.ajax({
                url: "specifications.jhtml",
                type: "GET",
                data: {productCategoryId: $productCategoryId.val()},
                dataType: "json",
                success: function(data) {
                    $specificationTable.empty();
                    $productTable.empty();
                    $.each(data, function(i, specification) {
                        var $td = $(
                            [@compress single_line = true]
                            '<div class="row cl">
                            <label class="form-label col-xs-4 col-sm-2">'+escapeHtml(specification.name)+'</label>
                            <div class="formControls col-xs-8 col-sm-8">
                            <ul class="spec_list_ul">
                            <input type="hidden" name="specificationItems[' + i + '].name" class="text specificationItemName" value="' + escapeHtml(specification.name) + '" style="width: 50px;" \/>
                        <\/ul>
                        <\/div>
                        <\/div>'
                        [/@compress]
                    ).appendTo($specificationTable).find("input").data("value", specification.name).end().find("ul");
                        $.each(specification.options, function(j, option) {
                            $(
                                [@compress single_line = true]
                                '<li>
                                <span><input type="checkbox" name="specificationItems[' + i + '].entries[' + j + '].isSelected" value="true" \/>
                            <input type="hidden" name="_specificationItems[' + i + '].entries[' + j + '].isSelected" value="false" \/>
                            <input type="hidden" name="specificationItems[' + i + '].entries[' + j + '].id" class="text specificationItemEntryId" value="' + specificationItemEntryId + '" \/>
                            <input type="hidden" name="specificationItems[' + i + '].entries[' + j + '].value" class="text specificationItemEntryValue" value="' + escapeHtml(option) + '" style="width: 50px;" \/></span>
                            <i class="i_padding">'+escapeHtml(option)+'</i>
                                <\/li>'
                            [/@compress]
                        ).appendTo($td).find("input.specificationItemEntryValue").data("value", option);
                            specificationItemEntryId ++;
                        });
                    });
                }
            });
        };


        $.validator.addClassRules({
            productImageFile: {
                required: true,
                extension: "${setting.uploadImageExtension}"
            },
            productImageOrder: {
                digits: true
            },
            parameterGroup: {
                required: true
            },
            price: {
                required: true,
                min: 0,
                decimal: {
                    integer: 12,
                    fraction: ${setting.priceScale}
                }
            },
            cost: {
                min: 0,
                decimal: {
                    integer: 12,
                    fraction: ${setting.priceScale}
                }
            },
            marketPrice: {
                min: 0,
                decimal: {
                    integer: 12,
                    fraction: ${setting.priceScale}
                }
            },
            rewardPoint: {
                digits: true
            },
            exchangePoint: {
                required: true,
                digits: true
            },
            stock: {
                required: true,
                digits: true
            },
            maxNumber: {
                required: true,
                digits: true
            },
            maxActivityNumber: {
                required: true,
                digits: true
            },
            activityTime: {
                required: true
            }
        });

        // 表单验证
        $("#inputForm").validate({
            rules: {
                productCategoryId: "required",
                sn: {
                    pattern: /^[0-9a-zA-Z_-]+$/,
                    remote: {
                        url: "check_sn.jhtml",
                        cache: false
                    }
                },
                name: {
                    required: true,
                    remote: {
                        url: "getGoods.jhtml",
                        name:$("#goodsName").val(),
                        cache: false
                    }

                },
                "product.price": {
                    required: true,
                    min: 0,
                    decimal: {
                        integer: 12,
                        fraction: ${setting.priceScale}
                    }
                },
                "product.cost": {
                    min: 0,
                    decimal: {
                        integer: 12,
                        fraction: ${setting.priceScale}
                    }
                },
                "product.marketPrice": {
                    min: 0,
                    decimal: {
                        integer: 12,
                        fraction: ${setting.priceScale}
                    }
                },
                image: {
                    pattern: /^(http:\/\/|https:\/\/|\/).*$/i
                },
                packagesNum: {
                	digits:true
                },
                shelfLife: {
                	digits:true
                },
                weight: {
                    min: 0,
                    decimal: {
                        integer: 12,
                        fraction: ${setting.priceScale}
                    }
                },
                volume:{
                    min: 0,
                    decimal: {
                        integer: 12,
                        fraction: ${setting.priceScale}
                    }
                },
                "product.rewardPoint": "digits",
                "product.exchangePoint": {
                    digits: true,
                    required: true
                },
                "product.stock": {
                    required: true,
                    digits: true
                },
                "product.activityPrice": {
                    min: 0,
                    required: true,
                    decimal: {
                        integer: 12,
                        fraction: ${setting.priceScale}
                    }
                },
                "product.maxNumber": {
                    required: true,
                    digits: true
                },
                "product.maxActivityNumber": {
                    required: true,
                    digits: true
                }
            },
            messages: {
                sn: {
                    pattern: "${message("admin.validate.illegal")}",
                    remote: "${message("admin.validate.exist")}"
                },
                name: {
                	remote: "商品已存在"
                }
            },
            submitHandler: function(form) {
                if (hasSpecification && $productTable.find("input.isEnabled:checked").size() == 0) {
                    $.message("warn", "${message("admin.goods.specificationProductRequired")}");
                    return false;
                }
                if(!hasSpecification && $("#activityType").prop("checked")==true && ($("#activityTimeShow").prop("value")=='请选择...')){
	            	//无规格 + 开启秒杀:必须选中秒杀时间
	            	$.message("warn", "请选择秒杀时间");
                    return false;
	            }
	            if(hasSpecification ){
	            	//有规格 + 开启秒杀:必须选中秒杀时间
	            	var checkList = $productTable.find("input.activityType:checked").closest('tr').find(".activityTime");
	            	for(var i = 0 ; i < checkList.length ; i++){
	            		if(checkList[i].value == "请选择..."){
	            			$.message("warn", "请选择秒杀时间");
                    		return false;
	            		}
	            	}
	            }
                //addCookie("previousProductCategoryId", $productCategoryId.val(), {expires: 24 * 60 * 60});
                $(form).find("input:submit").prop("disabled", true);
                form.submit();
            }
        });


    });

    //添加规格,jquery 追加的button,需再外面写点击事件
    function addRow(obj){

        var $thisRow = $(obj).parent();
        //当前所在行
        var curretRow = $thisRow.parent().parent().find('tr').index($thisRow.parent()[0]);

        //addOptionButton 操作标记
        var add= "addOptionButton_"+specificationItemName;
        //tr所在行
        var trlineNum= ".lineNum_"+curretRow;
        var currentLi = trlineNum+" li";
        //获取表格中li当前行最后一列,第一个input值
        var currentValue = $(currentLi).last().find('input').first().val();
        var current = currentValue*1+1;

        $(trlineNum).append(
            [@compress single_line = true]
            '
            <li>
                <input type="hidden" name="specificationItems['+curretRow+'].entries['+current+'].id" class="text specificationItemEntryId" value="' + current + '" \/>
                <input type="text" name="specificationItems['+curretRow+'].entries['+current+'].value" class="input-text radius specificationItemEntryValue" value="" />
                <input type="checkbox" name="specificationItems['+curretRow+'].entries['+current+'].isSelected" value="true" \/>
                <input type="hidden" name="_specificationItems['+curretRow+'].entries['+current+'].isSelected" value="false" \/>

            </li>
            '
            [/@compress]
        );
    }

    //删除规格,jquery 追加的button,需再外面写点击事件
    function delRow(obj){
        //tr所在行
        var $thisRow = $(obj).parent();
        //当前所在行
        var curretRow = $thisRow.parent().parent().find('tr').index($thisRow.parent()[0]);
        var trlineNum= ".lineNum_"+curretRow;
        var currentLi = trlineNum+" li";
        //获取表格中li当前行最后一列,第一个input值
        var currentValue = $(currentLi).last().find('input').first().val();
        if(currentValue*1 > 0){
            $(""+trlineNum+" li").last().remove();
        }else {
            $.dialog({
                type: "warn",
                content: "是否删除当前行",
                width: 250,
                onOk: function() {
                    $(""+trlineNum).parent().parent().remove();
                }
            });
        }

    }
</script>

</body>
</html>
[/#escape]

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值