<extend name="Public:base_new" />
<block name="content">
<script type="text/javascript" src="/static/js/dist/area/cascade.js"></script>
<script type="text/javascript" src="/web/resource/js/lib/moment.js"></script>
<link rel="stylesheet" href="/web/resource/components/datetimepicker/jquery.datetimepicker.css">
<link rel="stylesheet" href="/web/resource/components/daterangepicker/daterangepicker.css">
<style type='text/css'>
    .tabs-container .form-group {overflow: hidden;}
    .tabs-container .tabs-left > .nav-tabs {}
    .tab-goods .nav li {float:left;}
    .spec_item_thumb {position: relative; width: 30px; height: 20px; padding: 0; border-left: none;}
    .spec_item_thumb i {position: absolute; top: -5px; right: -5px;}
    .multi-img-details, .multi-audio-details {margin-top:.5em;max-width: 700px; padding:0; }
    .multi-audio-details .multi-audio-item {width:155px; height: 40px; position:relative; float: left; margin-right: 5px;}
	.region-goods-details {
		background: #f8f8f8;
		margin-bottom: 10px;
		padding: 0 10px;
	}
	.region-goods-left{
		text-align: center;
		font-weight: bold;
		color: #333;
		font-size: 14px;
		padding: 20px 0;
	}
	.region-goods-right{
		border-left: 3px solid #fff;
		padding: 10px 10px;
	}
</style>
<div class="page-header">
    当前位置：
    <span class="text-primary">
    <?php if(!empty($item['id'])){ ?>编辑<?php }else{ ?>添加<?php } ?>商品 <small><?php if(!empty($item['id'])){ ?>修改【<span class="text-info">{$item['goodsname']}</span>】<?php } ?></small>
    </span>
</div>
<div class="page-content">
<div class="page-sub-toolbar">
	<span class='pull-right'>
        <a class="btn btn-primary btn-sm" href="{:U('goods/addgoods')}" >添加商品</a>
    </span>
</div>
<form action="" method="post" class="form-horizontal form-validate" enctype="multipart/form-data">
    <input type="hidden" id="tab" name="tab" value="#tab_basic" />
    <div class="tabs-container tab-goods">
        <div class="tabs-left">
            <ul class="nav nav-tabs" id="myTab">
                <li  <?php if(empty($_GET['tab']) || $_GET['tab']=='basic'){ ?>class="active"<?php } ?>><a href="#tab_basic">基本信息</a></li>
                <li  <?php if($_GET['tab']=='option'){ ?>class="active"<?php } ?> ><a href="#tab_option">规格库存</a></li>
               
                <li <?php if($_GET['tab']=='des'){ ?> class="active"<?php } ?> ><a href="#tab_des">商品详情</a></li>
            </ul>

            <div class="tab-content  ">
                <div class="tab-pane  <?php if(empty($_GET['tab']) || $_GET['tab']=='basic'){ ?>active<?php } ?>" id="tab_basic">
					<div class="panel-body">
						<!-- basic begin -->
						<div class="region-goods-details row">
							<div class="region-goods-left col-sm-2">
								基本信息
							</div>
							<div class="region-goods-right col-sm-10">
								<div class="form-group">
									<label class="col-sm-2 control-label must">商品名称</label>
								  
									<div class="col-sm-9 col-xs-12"  style="padding-right:0;" >
										<input type="text" name="goodsname" id="goodsname" class="form-control" value="{$item['goodsname']}" data-rule-required="true" />
									</div>
									
								</div>
								<div class="form-group">
									<label class="col-sm-2 control-label">商品分类</label>
									<div class="col-sm-9 col-xs-12">
										<select id="cates"  name='cates[]' class="form-control select2"  multiple='' >
											
											<?php foreach($category as $c){ ?>
											<option value="{$c['id']}" <?php if(is_array($item['cates']) &&  in_array($c['id'],$item['cates'])){ ?>selected<?php } ?> >{$c['name']}</option>
											
											<?php } ?>
										</select>
										
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-2 control-label">商品简介</label>
									<div class="col-sm-9 subtitle">
										<textarea  name="subtitle" id="subtitle" rows="5"  class="form-control" data-parent=".subtitle" maxlength="100" data-rule-maxlength="100">{$item['subtitle']}</textarea>
										<div class="help-block">副标题的长度请控制在100字以内</div>
									</div>
								</div>
								
								<div class="form-group">
									<label class="col-sm-2 control-label">商品简短标题</label>
									<div class="col-sm-9 subtitle">
										<input type="text" name="print_sub_title" id="print_sub_title" class="form-control" value="{$item['print_sub_title']}" />
										<div class="help-block">小票打印机使用，请控制字数，未填写默认截取商品标题(无须打印的可以不填写)</div>
									</div>
								</div>
		
		
								<div class="form-group">
									<label class="col-sm-2 control-label must">首页商品（大图）</label>
									<div class="col-sm-9 col-xs-12 gimgs">
										{:tpl_form_field_image2('big_img',$item['big_img'])}
										<span class="help-block image-block">此图为首页商品大图模式封面图，尺寸建议为710*400或同比例</span>
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-2 control-label must">商品图片</label>
									<div class="col-sm-9 col-xs-12 gimgs">
										
										{:tpl_form_field_multi_image3('thumbs',$item['piclist'])}
										
										
										<span class="layui-form-mid layui-word-aux image-block">商品详情页主图（轮播图），第一张为商品列表调用图，<span style="color: red;">图片类型必须为jpg或者png24，不支持png8</span>，建议为正方型，尺寸建议宽度为640，并保持图片大小一致，可拖拽改变图片顺序</span>
										
										<span class="help-block">您可以拖动图片改变其显示顺序 </span>
										
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-2 control-label">商品状态</label>
									<div class="col-sm-9 col-xs-12">
										<label class="radio-inline"><input type="radio" name="grounding" value="1" <?php if(!isset($item['grounding']) || $item['grounding'] == 1){ ?>checked="true"<?php } ?>  /> 上架</label>
										<label class="radio-inline"><input type="radio" name="grounding" value="0" <?php if(isset($item['grounding']) && $item['grounding'] == 0){ ?>checked="true"<?php } ?> /> 下架</label>
									</div>
								</div>
								
								<div class="form-group">
									<label class="col-sm-2 control-label">首页推荐</label>
									<div class="col-sm-9 col-xs-12">
										<label class="radio-inline"><input type="radio" name="is_index_show" value="1" <?php if(!isset($item['is_index_show']) || $item['is_index_show'] == 1){ ?>checked="true"<?php } ?>  /> 是</label>
										<label class="radio-inline"><input type="radio" name="is_index_show" value="0" <?php if(isset($item['is_index_show']) && $item['is_index_show'] == 0){ ?>checked="true"<?php } ?> /> 否</label>
									</div>
								</div>
								
								<div class="form-group">
									<label class="col-sm-2 control-label ">分享图片</label>
									<div class="col-sm-9 col-xs-12 gimgs">
										{:tpl_form_field_image2('goods_share_image',$item['goods_share_image'])}
										<span class="help-block image-block">此图为商品详情页分享图片（比例为长宽比5:4）</span>
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-2 control-label">分享标题</label>
									<div class="col-sm-9 subtitle">
										<input type="text" name="share_title" class="form-control" value="{$item['share_title']}" />
										<div class="help-block"></div>
									</div>
								</div>
								<div class="form-group" style="display:none;">
									<label class="col-sm-2 control-label">分享描述</label>
									<div class="col-sm-9 subtitle">
										<input type="text" name="share_description" class="form-control" value="{$item['share_description']}" />
										<div class="help-block">公众号才有的，小程序没有这个描述</div>
									</div>
								</div>
								<div class="form-group price" >
									<label class="col-sm-2 control-label">商品价格</label>
									<div class="col-sm-9 col-xs-12">
										
										<div class="input-group">
											<input type="text" name="price" id="price" class="form-control" value="{$item['price']}" />
											<span class="input-group-addon">元 原价</span>
											<input type="text" name="productprice" id="productprice" class="form-control" value="{$item['productprice']}" />
											<span class="input-group-addon">元 </span>
										</div>
										<span class='help-block'></span>
										
									</div>
								</div>
								
								<div class="form-group" >
									<label class="col-sm-2 control-label">已出售数</label>
									<div class="col-sm-6 col-xs-12">
										<div class="input-group">
											<input type="text" name="sales" id="sales" class="form-control" value="{$item['sales']}" />
											<span class="input-group-addon">备注：前台销量=虚拟销量+实际销量</span>
										</div>
									</div>
								</div>
								<div class="form-group" >
									<label class="col-sm-2 control-label">提货时间</label>
									<div class="col-sm-10 col-xs-12" id="radPickupDateTip"> 
										<?php $item['pick_up_type'] = isset($item['pick_up_type']) ? $item['pick_up_type'] : 1; ?>
										<label class="radio-inline"><input type="radio"  name="pick_up_type" <?php if(!isset($item['pick_up_type']) || $item['pick_up_type'] ==0){ ?> checked <?php } ?> value="0" /><span class="fake-radio"></span>当日达</label>
										<label  class="radio-inline"><input type="radio"  name="pick_up_type" <?php if(isset($item['pick_up_type']) && $item['pick_up_type'] ==1){ ?> checked <?php } ?> value="1" /><span class="fake-radio"></span>次日达</label>
										<label  class="radio-inline"><input type="radio"  name="pick_up_type" <?php if(isset($item['pick_up_type']) && $item['pick_up_type'] ==2){ ?> checked <?php } ?> value="2" /><span class="fake-radio"></span>隔日达</label>
										<label  class="radio-inline"><input type="radio"  name="pick_up_type" <?php if(isset($item['pick_up_type']) && $item['pick_up_type'] ==3){ ?> checked <?php } ?> value="3" /><span class="fake-radio"></span>自定义</label>
										
										<input class="form-control " id="txtPickupDateTip" name="pick_up_modify" style="vertical-align: sub; <?php if(isset($item['pick_up_type']) && $item['pick_up_type'] ==3){ ?>display:inline-block;<?php }else{ ?>display: none;<?php } ?>width: 120px;" type="text" value="{$item['pick_up_modify']}">
										
									  
										
										<span class="help-block">系统会根据当前日期自动生成具体提货时间，或直接显示自定义内容</span>
									</div>
								</div>
								
								
								<div class="form-group" style="display:none;">
									<label class="col-sm-2 control-label">标签</label>
									<div class="col-sm-9 col-xs-12">
										<label class="checkbox-inline"><input type="checkbox" name="quality" value="1" <?php if(!empty($item['quality'])){ ?>checked="true"<?php } ?>   /> 正品保证</label>
										<label class="checkbox-inline"><input type="checkbox" name="seven" value="1" <?php if(!empty($item['seven'])){ ?>checked="true"<?php } ?>   /> 7天无理由退换</label>
										<label class="checkbox-inline"><input type="checkbox" name="repair" value="1" <?php if(!empty($item['repair'])){ ?>checked="true"<?php } ?>   /> 保修</label>
									</div>
								</div>
								
								
								<div class="form-group">
									<label class="col-sm-2 control-label">自定义标签</label>
									<div class="col-sm-9 col-xs-12">
										<?php echo tpl_selector('labelname',
											array('key'=>'id',
											'text'=>'tagname',
											'type'=>'text',
											'placeholder'=>'自定义标签名称',
											'buttontext'=>'选择标签',
											'items'=>$item['label'],
											'nokeywords'=>1,
											'autosearch'=>1,
											'url'=>U('goods/labelquery')))?>
									</div>
								</div>
								
								<?php if($delivery_type_express == 1){ ?>
								<div class="form-group dispatch_info">
									<label class="col-sm-2 control-label">运费设置</label>
									<div class="col-sm-6 col-xs-6" style='padding-left:0'>
										
										<div class="input-group">
											<span class='input-group-addon' style='border:none'><label class="radio-inline" style='margin-top:-7px;' ><input type="radio" name="dispatchtype" value="0" <?php if(empty($item['dispatchtype'])){ ?>checked="true"<?php } ?>   /> 运费模板</label></span>
											<select class="form-control tpl-category-parent select2" id="dispatchid" name="dispatchid">
												
												
												<?php foreach($dispatch_data as $dispatch_item){ ?>
												<option value="{$dispatch_item['id']}" <?php if($item['dispatchid'] == $dispatch_item['id']){ ?>selected="true"<?php } ?>>{$dispatch_item['name']}</option>
												<?php } ?>
											</select>
										</div>
										
									</div>
								</div>
								<div class="form-group dispatch_info">
									<label class="col-sm-2 control-label"></label>
									<div class="col-sm-6 col-xs-6" style='padding-left:0'>
										<div class="input-group">
											<span class='input-group-addon' style='border:none'><label class="radio-inline"  style='margin-top:-7px;' >
											<input type="radio"name="dispatchtype" value="1" <?php if($item['dispatchtype'] == 1){ ?>checked="true"<?php } ?>  /> 统一邮费</label></span>
											<input type="text" name="dispatchprice" id="dispatchprice" class="form-control" value="{$item['dispatchprice']}" />
											<span class="input-group-addon">元</span>
										</div>

									</div>
								</div>
								<?php } ?>
								
								
								<?php if(!empty($is_open_fullreduction) && $is_open_fullreduction == 1){ ?>
								<div class="form-group" >
									<label class="col-sm-2 control-label">满减活动</label>
									<div class="col-sm-10 col-xs-12"> 
										<label class="radio-inline"><input type="radio"  name="is_take_fullreduction" <?php if(!isset($item['is_take_fullreduction']) || $item['is_take_fullreduction'] ==1){ ?> checked <?php } ?> value="1" /><span class="fake-radio"></span>参与</label>
										<label  class="radio-inline"><input type="radio"  name="is_take_fullreduction" <?php if(isset($item['is_take_fullreduction']) && $item['is_take_fullreduction'] ==0){ ?> checked <?php } ?> value="0" /><span class="fake-radio"></span>不参与</label>
									</div>
								</div>
								<?php } ?>
							</div>
						</div>

						<div class="region-goods-details row">
							<div class="region-goods-left col-sm-2">
									团购时间
							</div>
							<div class="region-goods-right col-sm-10">
								
								<div class="form-group">
									<label class="col-sm-2 control-label">团购时间</label>
									<div class="col-sm-9 subtitle">
										{:tpl_form_field_daterange('time', array('starttime'=>date('Y-m-d H:i', $item['begin_time']),'endtime'=>date('Y-m-d H:i', $item['end_time'])),true);}
										
									</div>
								</div>
								
							</div>
						</div>

						<div class="region-goods-details row">
							<div class="region-goods-left col-sm-2">
									限购设置
							</div>
							<div class="region-goods-right col-sm-10">
								
								<div class="form-group">
									<label class="col-sm-2 control-label">单次限购</label>
									<div class="col-sm-9 subtitle">
										
										<input type="text" name="one_limit_count" class="form-control " value="{$item['one_limit_count']}" />
										
										<div class="help-block">用户单次提交订单最多可购买数，默认为0表示不限制</div>
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-2 control-label">历史限购</label>
									<div class="col-sm-9 subtitle">
										
										<input type="text" name="total_limit_count" class="form-control" value="{$item['total_limit_count']}" />
										
										<div class="help-block">用户历史累积最多可购买数，默认为0表示不限制</div>
									</div>
								</div>
							</div>
						</div>
						<div class="region-goods-details row">
							<div class="region-goods-left col-sm-2" style="margin-top:10px;">
								  团长
							</div> 
							<div class="region-goods-right col-sm-10">
								<div class="form-group">
								   <label class="col-sm-2 control-label">团长提成</label>
									<div class="col-sm-10 ">
										<div class="input-group">
											<input type="text" name="community_head_commission" id="community_head_commission" class="form-control valid" value="<?php if(empty($item)){ ?>{$communityhead_commission}<?php }else{ ?>{$item['community_head_commission']}<?php } ?>" />
											<span class="input-group-addon">% </span>
										</div>
										<div class="help-block">预计团长可得佣金¥<font id="precommiss_head_money_tip"><?php if(isset($item['community_head_commission'])){ ?>{:round( ($item['community_head_commission']*$item['price'])/100 ,2) }<?php }else{ ?>0.00<?php } ?></font>，将根据商品最终的成交价格来计算佣金</div>	
									</div>
								</div>
								
								<div class="form-group">
								   <label class="col-sm-2 control-label">所有团长可销售</label>
									<div class="col-sm-10 ">
										<input type="checkbox" name="is_all_sale" class="form-control valid" <?php if(empty($item) || $item['is_all_sale'] ==1 || !isset($item['is_all_sale'])){ ?>checked<?php } ?> value="1" />
											
									</div>
								</div>
								
							
								
							</div>
						</div>
						<?php if (!defined('ROLE') || ROLE != 'agenter' ) { ?>	
						<div class="region-goods-details row">
							<div class="region-goods-left col-sm-2" style="margin-top:10px;">
								  供应商
							</div> 
							<div class="region-goods-right col-sm-10">
								<div class="form-group">
								   <label class="col-sm-2 control-label">选择供应商</label>
									<div class="col-sm-10 ">
								  
											{:tpl_selector('supply_id',array('key'=>'supply_id','autosearch' => 1,  'thumb'=>'logo', 'text'=>'shopname','placeholder'=>'供应商名称/供应商联系人/手机号','buttontext'=>'选择供应商 ', 'items'=>$item['supply_info'],'url'=>U('supply/zhenquery') ))}
											
										<div class="help-block"></div>	
									</div>
								</div>
							</div>
						</div>	    
						<?php } ?>		
						<script language="javascript">
							require(['jquery.ui'],function(){
								$('.multi-img-details').sortable({scroll:'false'});
								$('.multi-img-details').sortable('option', 'scroll', false);
								
							})
							$(function () {
								$('#price').blur(function(){
									var price = parseFloat( $("#price").val() );

									  var community_head_commission = parseFloat( $("#community_head_commission").val() );
									  if(price > 0 && community_head_commission >0)
									  {
											$('#precommiss_head_money_tip').html( ( (price * community_head_commission) /100 ).toFixed(2) );
									  }else{
										$('#precommiss_head_money_tip').html('0.00');
									  }
								})
								
								$("#community_head_commission").blur(function(){
								  var price = parseFloat( $("#price").val() );

								  var community_head_commission = parseFloat( $(this).val() );
								  if(price > 0 && community_head_commission >0)
								  {
										$('#precommiss_head_money_tip').html( ( (price * community_head_commission) /100 ).toFixed(2) );
								  }else{
									$('#precommiss_head_money_tip').html('0.00');
								  }
								  
								});
								
								$('#radPickupDateTip input[type=radio]').click(function(){
									var s_val = $(this).val();
									if(s_val == 3)
									{
										$('#txtPickupDateTip').css('display','inline-block');
									}else{
										$('#txtPickupDateTip').css('display', 'none');
									}
								 })
								$("input[name=isstatustime]").off('click').on('click',function () {
									if($(this).val()==1){
										$("#shelves").show()
									}else{
										$("#shelves").hide();
									}
								})
							})
						</script>
						<!-- basic end -->
					</div>
				</div>
				<div class="tab-pane <?php if($_GET['tab']=='option'){ ?>active<?php } ?>" id="tab_option"> <div class="panel-body">
				<include file="goods/tab/option" />
				<!-- option begin  -->
				
				<div class="region-goods-details row">
					<div class="region-goods-left col-sm-2">规格库存</div>
					<div class="region-goods-right col-sm-10">
						<div class="form-group">
							<label class="col-sm-1 control-label">商品编码</label>
							<div class="col-sm-9 subtitle">
								<input type="text" name="codes" class="form-control" value="{$item['codes']}" />
								<div class="help-block">商品编码 用部分商家用于统计</div>
							</div>
						</div>
						
						<div class="form-group">
							<label class="col-sm-1 control-label">重量</label>
							<div class="col-sm-11">
								<div class="input-group fixsingle-input-group">
									<input type="text" name="weight" id="weight" <?php if($item['hasoption']){ ?>readonly<?php } ?> class="form-control hasoption" value="{$item['weight']}"/>
									<span class="input-group-addon">克</span>
								</div>
							</div>
						</div>

						<div class="form-group">
							<label class="col-sm-1 control-label">库存</label>
							<div class="col-sm-11">
								<input type="text" name="total" id="total" class="form-control hasoption" value="{$item['total']}"  style="width:150px;display: inline;margin-right: 20px;" <?php if($item['hasoption']){ ?>readonly<?php } ?>/>
								<span class="help-block">商品的剩余数量, 如启用多规格，则此处设置无效.</span>
							</div>
						</div>

						
					</div>

				</div>



				<div class="region-goods-details row">
					<div class="region-goods-left  col-sm-2">
						规格
					</div>
					<div class="region-goods-right  col-sm-10">
						<div class="form-group">
							<div class="col-sm-11" style='padding-left:30px;'>
							
								<label class="checkbox-inline">
									<input type="checkbox" id="hasoption" value="1" name="hasoption" <?php if($item['hasoption']==1){ ?>checked<?php } ?> />启用商品规格
								</label>
								<span class="help-block">启用商品规格后，商品的价格及库存以商品规格为准,库存设置为0则会到”已售罄“中，手机也不会显示, -1为不限制</span>

								
							</div>
						</div>

						<div id='tboption' style="padding-left:15px;<?php if($item['hasoption']!=1){ ?>display:none<?php } ?>" >
							<div class="alert alert-info" style="display:none;">
								1. 拖动规格可调整规格显示顺序, 更改规格及规格项后请点击下方的【刷新规格项目表】来更新数据。<br/>
								2. 每一种规格代表不同型号，例如颜色为一种规格，尺寸为一种规格，如果设置多规格，手机用户必须每一种规格都选择一个规格项，才能添加购物车或购买。
							</div>
							<div id='specs'>
								
								<?php foreach($item['allspecs'] as $spec ){ ?>
								<!--spec begin -->
								 <div class='spec_item spec_class_{$cur_cate_id}' id='spec_{$spec['id']}' >
									 <div style='border:1px solid #e7eaec;padding:10px;margin-bottom: 10px;' >
										<input name="spec_id[]" type="hidden" class="form-control spec_id" value="{$spec['id']}"/>
										<div class="form-group">
										<div class="col-sm-12">
												<div class='input-group'>
													<input name="spec_title[{$spec['id']}]" type="text" class="form-control  spec_title" value="{$spec['title']}" placeholder="规格名称 (比如: 颜色)"/>
													<div class='input-group-btn'>
														<a href="javascript:;" id="add-specitem-{$spec['id']}" specid='{$spec['id']}' class='btn btn-info add-specitem' onclick="addSpecItem('{$spec['id']}')"><i class="fa fa-plus"></i> 添加规格项</a>
														<a href="javascript:void(0);" class='btn btn-danger' onclick="removeSpec('{$spec['id']}')"><i class="fa fa-remove"></i></a>
													</div>
												</div>
												
											</div>
										</div>
										<div class="form-group">
											<div class="col-md-12">
												<div id='spec_item_{$spec['id']}' class='spec_item_items'>
												
												<?php foreach($spec['items'] as $specitem){ ?>
													<!--begin spec_item-->
													
													<div class="spec_item_item" style="float:left;margin:5px;width:250px; position: relative">
														<input type="hidden" class="form-control spec_item_show" name="spec_item_show_{$spec['id']}[]" value="{$specitem['show']}" />
														<input type="hidden" class="form-control spec_item_id" name="spec_item_id_{$spec['id']}[]" value="{$specitem['id']}" />
														
														<div class="input-group">
															<span class="input-group-addon">
																<input type="checkbox" <?php if($specitem['id']>0){ ?>checked<?php } ?> value="1" onclick='showItem(this)'>
															</span>
															<input type="text" class="form-control spec_item_title" name="spec_item_title_{$spec['id']}[]" VALUE="{$specitem['title']}" />
															
															<span class="input-group-addon spec_item_thumb <?php if(!empty($specitem['thumb'])){ ?>has_thumb<?php } ?>">
																		   <input type='hidden'  name="spec_item_thumb_{$spec['id']}[]" value="{$specitem['thumb']}"
																			/>
																	<img onclick="selectSpecItemImage(this)" onerror="this.src='/static/images/nopic100.jpg'" 
																		 src="<?php if(empty($specitem['thumb'])){ ?>/static/images/nopic100.jpg<?php }else{ ?>{:resize($specitem['thumb'],100,100)}<?php } ?>" style='width:100%;'
																		 
																		 <?php if(!empty($specitem['thumb'])){ ?>
																				data-toggle='popover'
																				data-html ='true'
																				data-placement='top'
																				data-trigger ='hover'
																				data-content="<img src='{:tomedia($specitem['thumb'])}' style='width:100px;height:100px;' />"
																		 <?php } ?>
																		 >
																	<i class="fa fa-times-circle" <?php if(empty($specitem['thumb'])){ ?>style="display:none"<?php } ?>></i> 
															</span>
															
															<span class="input-group-addon">
																<a href="javascript:;" onclick="removeSpecItem(this)" title='删除'><i class="fa fa-times"></i></a>
																<a href="javascript:;" class="fa fa-arrows" title="拖动调整显示顺序" ></a>
															</span>
														</div>
													</div>
													 <!--end spec_item-->
												<?php } ?>
												</div>
											</div>
										</div>
								   </div> 
								</div>

								<!--spec end -->
								<?php } ?>
							</div>
							
							<table class="table">
								<tr>
									<td>
									<div class="form-group">
										<label class="col-sm-2 control-label">选择规格</label>
										<div class="col-sm-8 col-xs-12">
											<select id="cates2"  name='options[]' class="form-control select2" style='width:605px;' multiple='' >
												
												<?php foreach($spec_list as $c){ ?>
												<option value="{$c['id']}" data-names="{$c['value_str']}">{$c['name']}</option>
												
												<?php } ?>
											</select>
											
										</div>
									</div>
									<td>
								</tr>
								<tr>
									<td>
										<h4>
											<a href="javascript:;" class='btn btn-primary' id='add-spec' onclick="addSpec()" style="margin-top:10px;margin-bottom:10px;" title="添加规格"><i class='fa fa-plus'></i> 添加规格</a>
											<a style="display:none;" href="javascript:;" onclick="refreshOptions();" title="刷新规格项目表" class="btn btn-primary"><i class="fa fa-refresh"></i> 刷新规格项目表</a>
										</h4>
									</td>
								</tr>
								<tr style="display: none;" >
									<td>
										<div class="alert alert-danger">警告：规格数据有变动，请重新点击上方 [刷新规格项目表] 按钮！</div>
									</td>
								</tr>
							</table>
						
							<div class="alert alert-info wholesalewarning"  style="display:none;">
							
							</div>
						<div id="options" style="padding:0;">{$item['html']}</div>
					</div>

					
					</div>
				</div>
				<input type="hidden" name="optionArray" value=''>
				<input type="hidden" name="isdiscountDiscountsArray" value=''>
				<input type="hidden" name="discountArray" value=''>
				<input type="hidden" name="commissionArray" value=''>
				<script language="javascript">
				var chose_cate = -1;
				var chose_cate_id_arr = [];
					$(function(){
						
						$('#cates2').on('change',function(){
							var s_length = $("#cates2 option:selected").length -1;
							var options_name = $("#cates2 option:selected:eq("+s_length+")").text();
							var options_str =  $("#cates2 option:selected:eq("+s_length+")").attr('data-names');
							
							if(s_length > chose_cate)
							{
								chose_cate++;
								var cur_cate_id = '';
								$("#cates2 option:selected").each(function(){
									var tmp_cate_id = parseInt($(this).val());
									if( $.inArray( tmp_cate_id, chose_cate_id_arr ) == -1)
									{
										chose_cate_id_arr.push( parseInt(tmp_cate_id) );
										cur_cate_id = tmp_cate_id;
									}
								})
								addSpecList(options_name,options_str,cur_cate_id);
							}else{
								chose_cate--;
								var new_chose_cate_id_arr = [];
								if(chose_cate_id_arr.length == 1)
								{
									$('.spec_class_'+chose_cate_id_arr[0]).remove();
								}
								
								$("#cates2 option:selected").each(function(){
									var tmp_cate_id = parseInt( $(this).val() );
									if( $.inArray( tmp_cate_id, chose_cate_id_arr ) != -1)
									{
										new_chose_cate_id_arr.push( parseInt(tmp_cate_id) );
										chose_cate_id_arr.splice($.inArray( tmp_cate_id, chose_cate_id_arr ), 1);
									}
								})
								if(chose_cate_id_arr.length == 1)
								{
									$('.spec_class_'+chose_cate_id_arr[0]).remove();
								}
								
								chose_cate_id_arr = new_chose_cate_id_arr;
								refreshOptions();
							}
							
							
						})
						$(document).on('input propertychange change', '#specs input', function () {
							// 改变规格锁定提交
							window.optionchanged = true;
							$('#optiontip').show();
						});
						
						$(document).on('input propertychange change', '#specs input', function () {
							// 改变规格锁定提交
							window.optionchanged = true;
							$('#optiontip').show();
						});


						$(".spec_item_thumb").find('i').click(function(){
							var group  =$(this).parent();
							group.find('img').attr('src',"/static/images/nopic100.jpg");
							group.find(':hidden').val('');
							$(this).hide();
							group.find('img').popover('destroy');
						});

							require(['jquery.ui'],function(){
							$('#specs').sortable({
								stop: function(){
									refreshOptions();
								}
							});
							$('.spec_item_items').sortable(
							{
										handle:'.fa-arrows',
										stop: function(){
											refreshOptions();
										}
									}
							);
						});
						
						 
						
						
						$("#hasoption").click(function(){
							var obj = $(this);
							console.log(23232);
							if (obj.get(0).checked){
								$('#goodssn').attr('readonly',true);
								$('#productsn').attr('readonly',true);
								$('#weight').attr('readonly',true);
								$('#total').attr('readonly',true);

								$("#tboption").show();
								$("#tbdiscount").show();
								$("#isdiscount_discounts").show();
								$("#isdiscount_discounts_default").hide();
								$("#commission").show();
								$("#commission_default").hide();
								$("#discounts_type1").show().parent().show();
								refreshOptions();
							}else{
								$('#weight').removeAttr('readonly');
								$('#total').removeAttr('readonly');
								$("#tboption").hide();
								refreshOptions();

								$("#isdiscount_discounts").hide();
								var isdiscount_discounts = $("#isdiscount_discounts").html();
								$("#isdiscount_discounts").html('');
								//isdiscount_change();
								$("#isdiscount_discounts").html(isdiscount_discounts);
								

								$("#tbdiscount").hide();
								$("#isdiscount_discounts_default").show();

								$("#commission_default").show();

								$('#goodssn').removeAttr('readonly');
								$('#productsn').removeAttr('readonly');

								// 商品类型如果为虚拟卡密则不允许修改库存
								
								$("#discounts_type1").hide().parent().hide();
								$("#discounts_type0").click();
							}
						});
					});
					function selectSpecItemImage(obj){
						util.image('',function(val){
							$(obj).attr('src',val.url).popover({
								trigger: 'hover',
								html: true,
								container: $(document.body),
								content: "<img src='" + val.url  + "' style='width:100px;height:100px;' />",
								placement: 'top'
							});

							var group  =$(obj).parent();

							group.find(':hidden').val(val.attachment), group.find('i').show().unbind('click').click(function(){
								$(obj).attr('src',"/static/images/nopic100.jpg");
								group.find(':hidden').val('');
								group.find('i').hide();
								$(obj).popover('destroy');
							});
						});
					}
					function addSpecList(options_name,spec_str, cur_cate_id)
					{
					
						//var options_arr = options_str.split('@');
						var len = $(".spec_item").length;
						$("#add-spec").html("正在处理...").attr("disabled", "true").toggleClass("btn-primary");
						var url = "{:U('goods/mult_tpl',array('tpl'=>'spec'))}";
						$.ajax({
							"url": url,
							type:'post',
							data:{options_name:options_name,spec_str:spec_str,cur_cate_id:cur_cate_id},
							success:function(data){
								$("#add-spec").html('<i class="fa fa-plus"></i> 添加规格').removeAttr("disabled").toggleClass("btn-primary"); ;
								$('#specs').append(data);
								var len = $(".add-specitem").length -1;
								$(".add-specitem:eq(" +len+ ")").focus();
								refreshOptions();
							}
						});
					}
					
					function addSpec(){
						var len = $(".spec_item").length;
						$("#add-spec").html("正在处理...").attr("disabled", "true").toggleClass("btn-primary");
						var url = "{:U('goods/tpl',array('tpl'=>'spec'))}";
						$.ajax({
							"url": url,
							success:function(data){
								$("#add-spec").html('<i class="fa fa-plus"></i> 添加规格').removeAttr("disabled").toggleClass("btn-primary"); ;
								$('#specs').append(data);
								var len = $(".add-specitem").length -1;
								$(".add-specitem:eq(" +len+ ")").focus();
								refreshOptions();
							}
						});
					}
					function removeSpec(specid){
						if (confirm('确认要删除此规格?')){
							$("#spec_" + specid).remove();
							refreshOptions();
						}
					}
					function addSpecItem(specid){
							 $("#add-specitem-" + specid).html("正在处理...").attr("disabled", "true");
						var url = "{:U('goods/tpl',array('tpl'=>'specitem'))}" + "&specid=" + specid;
						$.ajax({
							"url": url,
							success:function(data){
								$("#add-specitem-" + specid).html('<i class="fa fa-plus"></i> 添加规格项').removeAttr("disabled");
								$('#spec_item_' + specid).append(data);
								var len = $("#spec_" + specid + " .spec_item_title").length -1;
								$("#spec_" + specid + " .spec_item_title:eq(" +len+ ")").focus();
								refreshOptions();
								if(type==3 && virtual==0){
											$(".choosetemp").show();
								 }
							}
						});
					}
					function removeSpecItem(obj){
						$(obj).closest('.spec_item_item').remove();
						refreshOptions();
					}

					function refreshOptions(){
						// 刷新后重置
						window.optionchanged = false;
						$('#optiontip').hide();


				 var html = '<table class="table table-bordered table-condensed"><thead><tr class="active">';
					var specs = [];
						 if($('.spec_item').length<=0){
							 $("#options").html('');
							 $("#discount").html('');
							 $("#isdiscount_discounts").html('');
							 $("#commission").html('');
							
								//isdiscount_change();
							 return;
						 }
					$(".spec_item").each(function(i){
						var _this = $(this);

						var spec = {
							id: _this.find(".spec_id").val(),
							title: _this.find(".spec_title").val()
						};

						var items = [];
						_this.find(".spec_item_item").each(function(){
							var __this = $(this);
							var item = {
								id: __this.find(".spec_item_id").val(),
								title: __this.find(".spec_item_title").val(),
																						virtual: __this.find(".spec_item_virtual").val(),
								show:__this.find(".spec_item_show").get(0).checked?"1":"0"
							}
							items.push(item);
						});
						spec.items = items;
						specs.push(spec);
					});
					specs.sort(function(x,y){
						if (x.items.length > y.items.length){
							return 1;
						}
						if (x.items.length < y.items.length) {
							return -1;
						}
					});

					var len = specs.length;
					var newlen = 1;
					var h = new Array(len);
					var rowspans = new Array(len);
					for(var i=0;i<len;i++){
						html+="<th>" + specs[i].title + "</th>";
						var itemlen = specs[i].items.length;
						if(itemlen<=0) { itemlen = 1 };
						newlen*=itemlen;

						h[i] = new Array(newlen);
						for(var j=0;j<newlen;j++){
							h[i][j] = new Array();
						}
						var l = specs[i].items.length;
						rowspans[i] = 1;
						for(j=i+1;j<len;j++){
							rowspans[i]*= specs[j].items.length;
						}
					}

				//  商品类型如果为虚拟卡密则不允许修改库存
					
					html += '<th><div class=""><div style="padding-bottom:10px;text-align:center;">库存</div><div class="input-group"><input type="text" class="form-control  input-sm option_stock_all" VALUE=""/><span class="input-group-addon"><a href="javascript:;" class="fa fa-angle-double-down" title="批量设置" onclick="setCol(\'option_stock\');"></a></span></div></div></th>';
					

					//html += '<th class="type-4"><div class=""><div style="padding-bottom:10px;text-align:center;">预售价</div><div class="input-group"><input type="text" class="form-control  input-sm option_presell_all"VALUE=""/><span class="input-group-addon"><a href="javascript:;" class="fa fa-angle-double-down" title="批量设置" onclick="setCol(\'option_presell\');"></a></span></div></div></th>';
					html += '<th class="type-4"><div class=""><div style="padding-bottom:10px;text-align:center;">现价</div><div class="input-group"><input type="text" class="form-control  input-sm option_marketprice_all"VALUE=""/><span class="input-group-addon"><a href="javascript:;" class="fa fa-angle-double-down" title="批量设置" onclick="setCol(\'option_marketprice\');"></a></span></div></div></th>';
					html+='<th class="type-4"><div class=""><div style="padding-bottom:10px;text-align:center;">原价</div><div class="input-group"><input type="text" class="form-control  input-sm option_productprice_all"VALUE=""/><span class="input-group-addon"><a href="javascript:;" class="fa fa-angle-double-down" title="批量设置" onclick="setCol(\'option_productprice\');"></a></span></div></div></th>';
					html+='<th class="type-4"><div class=""><div style="padding-bottom:10px;text-align:center;">成本价</div><div class="input-group"><input type="text" class="form-control  input-sm option_costprice_all"VALUE=""/><span class="input-group-addon"><a href="javascript:;" class="fa fa-angle-double-down" title="批量设置" onclick="setCol(\'option_costprice\');"></a></span></div></div></th>';
					html+='<th><div class=""><div style="padding-bottom:10px;text-align:center;">编码</div><div class="input-group"><input type="text" class="form-control  input-sm option_goodssn_all"VALUE=""/><span class="input-group-addon"><a href="javascript:;" class="fa fa-angle-double-down" title="批量设置" onclick="setCol(\'option_goodssn\');"></a></span></div></div></th>';
					//html+='<th><div class=""><div style="padding-bottom:10px;text-align:center;">条码</div><div class="input-group"><input type="text" class="form-control  input-sm option_productsn_all"VALUE=""/><span class="input-group-addon"><a href="javascript:;" class="fa fa-angle-double-down" title="批量设置" onclick="setCol(\'option_productsn\');"></a></span></div></div></th>';
					html+='<th><div class=""><div style="padding-bottom:10px;text-align:center;">重量（克）</div><div class="input-group"><input type="text" class="form-control  input-sm option_weight_all"VALUE=""/><span class="input-group-addon"><a href="javascript:;" class="fa fa-angle-double-down" title="批量设置" onclick="setCol(\'option_weight\');"></a></span></div></div></th>';
					html+='</tr></thead>';

					for(var m=0;m<len;m++){
						var k = 0,kid = 0,n=0;
						for(var j=0;j<newlen;j++){
							var rowspan = rowspans[m];
							if( j % rowspan==0){
								h[m][j]={title: specs[m].items[kid].title, virtual: specs[m].items[kid].virtual,html: "<td class='full' rowspan='" +rowspan + "'>"+ specs[m].items[kid].title+"</td>\r\n",id: specs[m].items[kid].id};
							}
							else{
								h[m][j]={title:specs[m].items[kid].title,virtual: specs[m].items[kid].virtual, html: "",id: specs[m].items[kid].id};
							}
							n++;
							if(n==rowspan){
							kid++; if(kid>specs[m].items.length-1) { kid=0; }
							n=0;
							}
						}
					}

					var hh = "";
					for(var i=0;i<newlen;i++){
						hh+="<tr>";
						var ids = [];
						var titles = [];
													var virtuals = [];
						for(var j=0;j<len;j++){
							hh+=h[j][i].html;
							ids.push( h[j][i].id);
							titles.push( h[j][i].title);
										   virtuals.push( h[j][i].virtual);
						}
						ids =ids.join('_');
						titles= titles.join('+');

						var val ={ id : "",title:titles, stock : "",presell : "",costprice : "",productprice : "",marketprice : "",weight:"",productsn:"",goodssn:"",virtual:virtuals };
						if( $(".option_id_" + ids).length>0){
							val ={
								id : $(".option_id_" + ids+":eq(0)").val(),
								title: titles,
								stock : $(".option_stock_" + ids+":eq(0)").val(),
								presell : $(".option_presell_" + ids+":eq(0)").val(),
								costprice : $(".option_costprice_" + ids+":eq(0)").val(),
								productprice : $(".option_productprice_" + ids+":eq(0)").val(),
								marketprice : $(".option_marketprice_" + ids +":eq(0)").val(),
													goodssn : $(".option_goodssn_" + ids +":eq(0)").val(),
													productsn : $(".option_productsn_" + ids +":eq(0)").val(),
								weight : $(".option_weight_" + ids+":eq(0)").val(),
												  virtual : virtuals
							}
						}

						hh += '<td>'
						//  商品类型如果为虚拟卡密则不允许修改库存
						
							hh += '<input name="option_stock_' + ids +'" type="text" class="form-control option_stock option_stock_' + ids +'" value="' +(val.stock=='undefined'?'':val.stock )+'"/></td>';
						
						hh += '<input name="option_id_' + ids+'" type="hidden" class="form-control option_id option_id_' + ids +'" value="' +(val.id=='undefined'?'':val.id )+'"/>';
						hh += '<input name="option_ids[]" type="hidden" class="form-control option_ids option_ids_' + ids +'" value="' + ids +'"/>';
						hh += '<input name="option_title_' + ids +'" type="hidden" class="form-control option_title option_title_' + ids +'" value="' +(val.title=='undefined'?'':val.title )+'"/></td>';
						hh += '<input name="option_virtual_' + ids +'" type="hidden" class="form-control option_virtual option_virtual_' + ids +'" value="' +(val.virtual=='undefined'?'':val.virtual )+'"/></td>';
						hh += '</td>';
						//hh += '<td class="type-4"><input data-name="option_presell_' + ids+'" type="text" class="form-control option_presell option_presell_' + ids +'" value="' +(val.presell=='undefined'?'':val.presell )+'"/></td>';
						hh += '<td class="type-4"><input name="option_marketprice_' + ids+'" type="text" class="form-control option_marketprice option_marketprice_' + ids +'" value="' +(val.marketprice=='undefined'?'':val.marketprice )+'"/></td>';
						hh += '<td class="type-4"><input name="option_productprice_' + ids+'" type="text" class="form-control option_productprice option_productprice_' + ids +'" " value="' +(val.productprice=='undefined'?'':val.productprice )+'"/></td>';
						hh += '<td class="type-4"><input name="option_costprice_' +ids+'" type="text" class="form-control option_costprice option_costprice_' + ids +'" " value="' +(val.costprice=='undefined'?'':val.costprice )+'"/></td>';
						hh += '<td><input name="option_goodssn_' +ids+'" type="text" class="form-control option_goodssn option_goodssn_' + ids +'" " value="' +(val.goodssn=='undefined'?'':val.goodssn )+'"/></td>';
						//hh += '<td><input data-name="option_productsn_' +ids+'" type="text" class="form-control option_productsn option_productsn_' + ids +'" " value="' +(val.productsn=='undefined'?'':val.productsn )+'"/></td>';
						hh += '<td><input name="option_weight_' + ids +'" type="text" class="form-control option_weight option_weight_' + ids +'" " value="' +(val.weight=='undefined'?'':val.weight )+'"/></td>';
						hh += "</tr>";
					}
					html+=hh;
					html+="</table>";
					$("#options").html(html);
						refreshDiscount();
						refreshIsDiscount();
						
						//isdiscount_change();

						if(window.type=='4'){
							$('.type-4').hide();
						}else{
							$('.type-4').show();
						}
				}

					function refreshDiscount() {
						var html = '<table class="table table-bordered table-condensed"><thead><tr class="active">';
						var specs = [];

						$(".spec_item").each(function (i) {
							var _this = $(this);

							var spec = {
								id: _this.find(".spec_id").val(),
								title: _this.find(".spec_title").val()
							};

							var items = [];
							_this.find(".spec_item_item").each(function () {
								var __this = $(this);
								var item = {
									id: __this.find(".spec_item_id").val(),
									title: __this.find(".spec_item_title").val(),
									virtual: __this.find(".spec_item_virtual").val(),
									show: __this.find(".spec_item_show").get(0).checked ? "1" : "0"
								}
								items.push(item);
							});
							spec.items = items;
							specs.push(spec);
						});
						specs.sort(function (x, y) {
							if (x.items.length > y.items.length) {
								return 1;
							}
							if (x.items.length < y.items.length) {
								return -1;
							}
						});

						var len = specs.length;
						var newlen = 1;
						var h = new Array(len);
						var rowspans = new Array(len);
						for (var i = 0; i < len; i++) {
							html += "<th>" + specs[i].title + "</th>";
							var itemlen = specs[i].items.length;
							if (itemlen <= 0) {
								itemlen = 1
							}
							;
							newlen *= itemlen;

							h[i] = new Array(newlen);
							for (var j = 0; j < newlen; j++) {
								h[i][j] = new Array();
							}
							var l = specs[i].items.length;
							rowspans[i] = 1;
							for (j = i + 1; j < len; j++) {
								rowspans[i] *= specs[j].items.length;
							}
						}

						
						<?php foreach($levels as $level){ ?>
						<?php if($level['key']=='default'){ ?>
						html += '<th><div class=""><div style="padding-bottom:10px;text-align:center;">{$level['levelname']}</div><div class="input-group"><input type="text" class="form-control  input-sm discount_{$level["key"]}_all"VALUE=""/><span class="input-group-addon"><a href="javascript:;" class="fa fa-angle-double-down" title="批量设置" onclick="setCol(\'discount_{$level["key"]}\');"></a></span></div></div></th>';
						<?php }else{ ?>
						html += '<th><div class=""><div style="padding-bottom:10px;text-align:center;">{$level['levelname']}</div><div class="input-group"><input type="text" class="form-control  input-sm discount_level{$level['id']}_all"VALUE=""/><span class="input-group-addon"><a href="javascript:;" class="fa fa-angle-double-down" title="批量设置" onclick="setCol(\'discount_level{$level['id']}\');"></a></span></div></div></th>';
						<?php } ?>
						<?php } ?>
						html += '</tr></thead>';

						for (var m = 0; m < len; m++) {
							var k = 0, kid = 0, n = 0;
							for (var j = 0; j < newlen; j++) {
								var rowspan = rowspans[m];
								if (j % rowspan == 0) {
									h[m][j] = {
										title: specs[m].items[kid].title,
										virtual: specs[m].items[kid].virtual,
										html: "<td class='full' rowspan='" + rowspan + "'>" + specs[m].items[kid].title + "</td>\r\n",
										id: specs[m].items[kid].id
									};
								}
								else {
									h[m][j] = {
										title: specs[m].items[kid].title,
										virtual: specs[m].items[kid].virtual,
										html: "",
										id: specs[m].items[kid].id
									};
								}
								n++;
								if (n == rowspan) {
									kid++;
									if (kid > specs[m].items.length - 1) {
										kid = 0;
									}
									n = 0;
								}
							}
						}

						var hh = "";
						for (var i = 0; i < newlen; i++) {
							hh += "<tr>";
							var ids = [];
							var titles = [];
							var virtuals = [];
							for (var j = 0; j < len; j++) {
								hh += h[j][i].html;
								ids.push(h[j][i].id);
								titles.push(h[j][i].title);
								virtuals.push(h[j][i].virtual);
							}
							ids = ids.join('_');
							titles = titles.join('+');
							var val = {
								id: "",
								title: titles,
								
								<?php foreach($levels as  $level){  ?>
								
								<?php if($level['key']=='default'){ ?>
								level{$level['key']}: '',
								<?php }else{ ?>
								level{$level['id']}: '',
								<?php } ?>
								<?php } ?>
								costprice: "",
								presell: "",
								productprice: "",
								marketprice: "",
								weight: "",
								productsn: "",
								goodssn: "",
								virtual: virtuals
							};

							var val ={ id : "",title:titles,
								<?php foreach($levels as $level){ ?>
								<?php if($level['key']=='default'){ ?>
								level{$level['key']}: '',
								<?php }else{ ?>
								level{$level['id']}: '',
								<?php } ?>
								<?php } ?>
								costprice : "",productprice : "",marketprice : "",weight:"",productsn:"",goodssn:"",virtual:virtuals };
							if ($(".discount_id_" + ids).length > 0) {
								val = {
									id: $(".discount_id_" + ids + ":eq(0)").val(),
									title: titles,
									<?php foreach($levels as $level){ ?>
									
								<?php if($level['key']=='default'){ ?>
									level{$level['key']}: $(".discount_{$level['key']}_" + ids + ":eq(0)").val(),
								<?php }else{ ?>
									level{$level['id']}: $(".discount_level{$level['id']}_" + ids + ":eq(0)").val(),
								<?php } ?>
								<?php } ?>
									costprice: $(".discount_costprice_" + ids + ":eq(0)").val(),
									presell: $(".discount_presell_" + ids + ":eq(0)").val(),
									productprice: $(".discount_productprice_" + ids + ":eq(0)").val(),
									marketprice: $(".discount_marketprice_" + ids + ":eq(0)").val(),
									presell: $(".discount_presell_" + ids + ":eq(0)").val(),
									goodssn: $(".discount_goodssn_" + ids + ":eq(0)").val(),
									productsn: $(".discount_productsn_" + ids + ":eq(0)").val(),
									weight: $(".discount_weight_" + ids + ":eq(0)").val(),
									virtual: virtuals
								}
							}

							<?php foreach($levels as $level){ ?>
							hh += '<td>'
							<?php if($level['key']=='default'){ ?>
							hh += '<input data-name="discount_level_{$level['key']}_' + ids +'"type="text" class="form-control discount_{$level['key']} discount_{$level['key']}_' + ids +'" value="' +(val.level{$level['key']}=='undefined'?'':val.level{$level['key']} )+'"/>';
							<?php }else{ ?>
							hh += '<input data-name="discount_level_{$level['id']}_' + ids +'"type="text" class="form-control discount_level{$level['id']} discount_level{$level['id']}_' + ids +'" value="' +(val.level{$level['id']}=='undefined'?'':val.level{$level['id']} )+'"/>';
							<?php } ?>
							hh += '</td>';
							<?php } ?>
							hh += '<input data-name="discount_id_' + ids+'"type="hidden" class="form-control discount_id discount_id_' + ids +'" value="' +(val.id=='undefined'?'':val.id )+'"/>';
							hh += '<input data-name="discount_ids"type="hidden" class="form-control discount_ids discount_ids_' + ids +'" value="' + ids +'"/>';
							hh += '<input data-name="discount_title_' + ids +'"type="hidden" class="form-control discount_title discount_title_' + ids +'" value="' +(val.title=='undefined'?'':val.title )+'"/></td>';
							hh += '<input data-name="discount_virtual_' + ids +'"type="hidden" class="form-control discount_virtual discount_virtual_' + ids +'" value="' +(val.virtual=='undefined'?'':val.virtual )+'"/></td>';
							hh += "</tr>";
						}
						html += hh;
						html += "</table>";
						$("#discount").html(html);
					}

					function refreshIsDiscount() {
						var html = '<table class="table table-bordered table-condensed"><thead><tr class="active">';
						var specs = [];

						$(".spec_item").each(function (i) {
							var _this = $(this);

							var spec = {
								id: _this.find(".spec_id").val(),
								title: _this.find(".spec_title").val()
							};

							var items = [];
							_this.find(".spec_item_item").each(function () {
								var __this = $(this);
								var item = {
									id: __this.find(".spec_item_id").val(),
									title: __this.find(".spec_item_title").val(),
									virtual: __this.find(".spec_item_virtual").val(),
									show: __this.find(".spec_item_show").get(0).checked ? "1" : "0"
								}
								items.push(item);
							});
							spec.items = items;
							specs.push(spec);
						});
						specs.sort(function (x, y) {
							if (x.items.length > y.items.length) {
								return 1;
							}
							if (x.items.length < y.items.length) {
								return -1;
							}
						});

						var len = specs.length;
						var newlen = 1;
						var h = new Array(len);
						var rowspans = new Array(len);
						for (var i = 0; i < len; i++) {
							html += "<th>" + specs[i].title + "</th>";
							var itemlen = specs[i].items.length;
							if (itemlen <= 0) {
								itemlen = 1
							}
							;
							newlen *= itemlen;

							h[i] = new Array(newlen);
							for (var j = 0; j < newlen; j++) {
								h[i][j] = new Array();
							}
							var l = specs[i].items.length;
							rowspans[i] = 1;
							for (j = i + 1; j < len; j++) {
								rowspans[i] *= specs[j].items.length;
							}
						}

						<?php foreach($levels as $level){ ?>
						<?php if($level['key']=='default'){ ?>
						html += '<th><div class=""><div style="padding-bottom:10px;text-align:center;">{$level['levelname']}</div><div class="input-group"><input type="text" class="form-control  input-sm isdiscount_discounts_{$level['key']}_all"VALUE=""/><span class="input-group-addon"><a href="javascript:;" class="fa fa-angle-double-down" title="批量设置" onclick="setCol(\'isdiscount_discounts_{$level['key']}\');"></a></span></div></div></th>';
						<?php }else{ ?>
						html += '<th><div class=""><div style="padding-bottom:10px;text-align:center;">{$level['levelname']}</div><div class="input-group"><input type="text" class="form-control  input-sm isdiscount_discounts_level{$level['id']}_all"VALUE=""/><span class="input-group-addon"><a href="javascript:;" class="fa fa-angle-double-down" title="批量设置" onclick="setCol(\'isdiscount_discounts_level{$level['id']}\');"></a></span></div></div></th>';
						<?php } ?>
						<?php } ?>
						html += '</tr></thead>';

						for (var m = 0; m < len; m++) {
							var k = 0, kid = 0, n = 0;
							for (var j = 0; j < newlen; j++) {
								var rowspan = rowspans[m];
								if (j % rowspan == 0) {
									h[m][j] = {
										title: specs[m].items[kid].title,
										virtual: specs[m].items[kid].virtual,
										html: "<td class='full' rowspan='" + rowspan + "'>" + specs[m].items[kid].title + "</td>\r\n",
										id: specs[m].items[kid].id
									};
								}
								else {
									h[m][j] = {
										title: specs[m].items[kid].title,
										virtual: specs[m].items[kid].virtual,
										html: "",
										id: specs[m].items[kid].id
									};
								}
								n++;
								if (n == rowspan) {
									kid++;
									if (kid > specs[m].items.length - 1) {
										kid = 0;
									}
									n = 0;
								}
							}
						}

						var hh = "";
						for (var i = 0; i < newlen; i++) {
							hh += "<tr>";
							var ids = [];
							var titles = [];
							var virtuals = [];
							for (var j = 0; j < len; j++) {
								hh += h[j][i].html;
								ids.push(h[j][i].id);
								titles.push(h[j][i].title);
								virtuals.push(h[j][i].virtual);
							}
							ids = ids.join('_');
							titles = titles.join('+');
							var val = {
								id: "",
								title: titles,
							<?php foreach($levels as $level){ ?>
							<?php if($level['key']=='default'){ ?>
							level{$level['key']}: '',
							<?php }else{ ?>
							level{$level['if']}: '',
							<?php } ?>
							<?php } ?>
							costprice: "",
									presell: "",
									productprice: "",
									marketprice: "",
									weight: "",
									productsn: "",
									goodssn: "",
									virtual: virtuals
						};

							var val ={ id : "",title:titles,
							<?php foreach($levels as $level){ ?>
							<?php if($level['key']=='default'){ ?>
							level{$level['key']}: '',
							<?php }else{ ?>
							level{$level['id']}: '',
							<?php } ?>
							<?php } ?>
							costprice : "",productprice : "",marketprice : "",weight:"",productsn:"",goodssn:"",virtual:virtuals };
							if ($(".isdiscount_discounts_id_" + ids).length > 0) {
								val = {
									id: $(".isdiscount_discounts_id_" + ids + ":eq(0)").val(),
									title: titles,
								<?php foreach($levels as $level){ ?>
								<?php if($level['key']=='default'){ ?>
								level{$level['key']}: $(".isdiscount_discounts_{$level['key']}_" + ids + ":eq(0)").val(),
								<?php }else{ ?>
								level{$level['id']}: $(".isdiscount_discounts_level{$level['id']}_" + ids + ":eq(0)").val(),
								<?php } ?>
								<?php } ?>
								costprice: $(".isdiscount_discounts_costprice_" + ids + ":eq(0)").val(),
										productprice: $(".isdiscount_discounts_productprice_" + ids + ":eq(0)").val(),
										marketprice: $(".isdiscount_discounts_marketprice_" + ids + ":eq(0)").val(),
										presell: $(".isdiscount_discounts_presell_" + ids + ":eq(0)").val(),
										goodssn: $(".isdiscount_discounts_goodssn_" + ids + ":eq(0)").val(),
										productsn: $(".isdiscount_discounts_productsn_" + ids + ":eq(0)").val(),
										weight: $(".isdiscount_discounts_weight_" + ids + ":eq(0)").val(),
										virtual: virtuals
							}
							}

							<?php foreach($levels as $level){ ?>
							hh += '<td>'
							<?php if($level['key']=='default'){ ?>
							hh += '<input data-name="isdiscount_discounts_level_{$level['key']}_' + ids +'"type="text" class="form-control isdiscount_discounts_{$level['key']} isdiscount_discounts_{$level['key']}_' + ids +'" value="' +(val.level{$level['key']}=='undefined'?'':val.level{$level['key']} )+'"/>';
							<?php }else{ ?>
							hh += '<input data-name="isdiscount_discounts_level_{$level['id']}_' + ids +'"type="text" class="form-control isdiscount_discounts_level{$level['id']} isdiscount_discounts_level{$level['id']}_' + ids +'" value="' +(val.level{$level['id']}=='undefined'?'':val.level{$level['id']} )+'"/>';
							<?php } ?>
							hh += '</td>';
							<?php } ?>
							hh += '<input data-name="isdiscount_discounts_id_' + ids+'"type="hidden" class="form-control isdiscount_discounts_id isdiscount_discounts_id_' + ids +'" value="' +(val.id=='undefined'?'':val.id )+'"/>';
							hh += '<input data-name="isdiscount_discounts_ids"type="hidden" class="form-control isdiscount_discounts_ids isdiscount_discounts_ids_' + ids +'" value="' + ids +'"/>';
							hh += '<input data-name="isdiscount_discounts_title_' + ids +'"type="hidden" class="form-control isdiscount_discounts_title isdiscount_discounts_title_' + ids +'" value="' +(val.title=='undefined'?'':val.title )+'"/></td>';
							hh += '<input data-name="isdiscount_discounts_virtual_' + ids +'"type="hidden" class="form-control isdiscount_discounts_virtual isdiscount_discounts_virtual_' + ids +'" value="' +(val.virtual=='undefined'?'':val.virtual )+'"/></td>';
							hh += "</tr>";
						}
						html += hh;
						html += "</table>";
						$("#isdiscount_discounts").html(html);
					}

					function refreshCommission() {
						var commission_level = {:json_encode($commission_level)};
						var html = '<table class="table table-bordered table-condensed"><thead><tr class="active">';
						var specs = [];

						$(".spec_item").each(function (i) {
							var _this = $(this);

							var spec = {
								id: _this.find(".spec_id").val(),
								title: _this.find(".spec_title").val()
							};

							var items = [];
							_this.find(".spec_item_item").each(function () {
								var __this = $(this);
								var item = {
									id: __this.find(".spec_item_id").val(),
									title: __this.find(".spec_item_title").val(),
									virtual: __this.find(".spec_item_virtual").val(),
									show: __this.find(".spec_item_show").get(0).checked ? "1" : "0"
								}
								items.push(item);
							});
							spec.items = items;
							specs.push(spec);
						});
						specs.sort(function (x, y) {
							if (x.items.length > y.items.length) {
								return 1;
							}
							if (x.items.length < y.items.length) {
								return -1;
							}
						});

						var len = specs.length;
						var newlen = 1;
						var h = new Array(len);
						var rowspans = new Array(len);
						for (var i = 0; i < len; i++) {
							html += "<th>" + specs[i].title + "</th>";
							var itemlen = specs[i].items.length;
							if (itemlen <= 0) {
								itemlen = 1
							}
							;
							newlen *= itemlen;

							h[i] = new Array(newlen);
							for (var j = 0; j < newlen; j++) {
								h[i][j] = new Array();
							}
							var l = specs[i].items.length;
							rowspans[i] = 1;
							for (j = i + 1; j < len; j++) {
								rowspans[i] *= specs[j].items.length;
							}
						}

						$.each(commission_level,function (key,level) {
							html += '<th><div class=""><div style="padding-bottom:10px;text-align:center;">'+level.levelname+'</div></div></th>';
						})
						html += '</tr></thead>';

						for (var m = 0; m < len; m++) {
							var k = 0, kid = 0, n = 0;
							for (var j = 0; j < newlen; j++) {
								var rowspan = rowspans[m];
								if (j % rowspan == 0) {
									h[m][j] = {
										title: specs[m].items[kid].title,
										virtual: specs[m].items[kid].virtual,
										html: "<td class='full' rowspan='" + rowspan + "'>" + specs[m].items[kid].title + "</td>\r\n",
										id: specs[m].items[kid].id
									};
								}
								else {
									h[m][j] = {
										title: specs[m].items[kid].title,
										virtual: specs[m].items[kid].virtual,
										html: "",
										id: specs[m].items[kid].id
									};
								}
								n++;
								if (n == rowspan) {
									kid++;
									if (kid > specs[m].items.length - 1) {
										kid = 0;
									}
									n = 0;
								}
							}
						}
						var hh = "";
						for (var i = 0; i < newlen; i++) {
							hh += "<tr>";
							var ids = [];
							var titles = [];
							var virtuals = [];
							for (var j = 0; j < len; j++) {
								hh += h[j][i].html;
								ids.push(h[j][i].id);
								titles.push(h[j][i].title);
								virtuals.push(h[j][i].virtual);
							}
							ids = ids.join('_');
							titles = titles.join('+');

							var val = {
								id: "",
								title: titles,
							<?php foreach($commission_level as  $level){ ?>
							<?php if($level["key"] == "default"){ ?>
							level{$level['key']}: '',
							<?php }else{ ?>
							level{$level['id']}: '',
							<?php } ?>
							<?php } ?>
							costprice: "",
									presell: "",
									productprice: "",
									marketprice: "",
									weight: "",
									productsn: "",
									goodssn: "",
									virtual: virtuals
						};

							var val ={ id : "",title:titles,
							
							<?php foreach($commission_level as $level){ ?>
							<?php if($level["key"] == "default"){ ?>
							level{$level['key']}: '',
							<?php }else{ ?>
							level{$level['id']}: '',
							<?php } ?>
							<?php } ?>
							costprice : "",productprice : "",marketprice : "",weight:"",productsn:"",goodssn:"",virtual:virtuals };
							<?php foreach($commission_level as  $level){ ?>
							<?php if($level["key"] == "default"){ ?>
							var level{$level['key']} = new Array(3);
							$(".commission_{$level['key']}_"+ ids).each(function(index,val){
								level{$level['key']}[index] = val;
							})
							<?php }else{ ?>
							var level{$level['id']} = new Array(3);
							$(".commission_level{$level['id']}_"+ ids).each(function(index,val){
								level{$level['id']}[index] = val;
							})
							<?php } ?>
							<?php } ?>
							if ($(".commission_id_" + ids).length > 0) {
								val = {
									id: $(".commission_id_" + ids + ":eq(0)").val(),
									title: titles,
									costprice: $(".commission_costprice_" + ids + ":eq(0)").val(),
									presell: $(".commission_presell_" + ids + ":eq(0)").val(),
										productprice: $(".commission_productprice_" + ids + ":eq(0)").val(),
										marketprice: $(".commission_marketprice_" + ids + ":eq(0)").val(),
										goodssn: $(".commission_goodssn_" + ids + ":eq(0)").val(),
										productsn: $(".commission_productsn_" + ids + ":eq(0)").val(),
										weight: $(".commission_weight_" + ids + ":eq(0)").val(),
										virtual: virtuals
								}
							}
							
							<?php foreach($commission_level as $level){ ?>
							hh += '<td>';
							var level_temp = <?php if($level['key'] == 'default'){ ?>level{$level['key']}<?php }else{ ?>level{$level['id']}<?php } ?>;
							if (len >= i && typeof (level_temp) != 'undefined')
							{
								if('{$level['key']}' == 'default')
								{
									for (var li = 0; li<{$shopset_level};li++)
									{
										if (typeof (level_temp[li])!= "undefined")
										{
											hh += '<input data-name="commission_level_{$level['key']}_' +ids+ '"  type="text" class="form-control commission_{$level['key']} commission_{$level['key']}_' +ids+ '" value="' +$(level_temp[li]).val()+ '" style="display:inline;width: '+96/parseInt({$shopset_level})+'%;"/> ';
										}
										else
										{
											hh += '<input data-name="commission_level_{$level['key']}_' +ids+ '"  type="text" class="form-control commission_{$level['key']} commission_{$level['key']}_' +ids+ '" value="" style="display:inline;width: '+96/parseInt({$shopset_level})+'%;"/> ';
										}
									}
								}
								else
								{
									for (var li = 0; li<{$shopset_level};li++)
									{
										if (typeof (level_temp[li])!= "undefined")
										{
											hh += '<input data-name="commission_level_{$level['id']}_' +ids+ '"  type="text" class="form-control commission_level{$level['id']} commission_level{$level['id']}_' +ids+ '" value="' +$(level_temp[li]).val()+ '" style="display:inline;width: '+96/parseInt({$shopset_level})+'%;"/> ';
										}
										else
										{
											hh += '<input data-name="commission_level_{$level['id']}_' +ids+ '"  type="text" class="form-control commission_level{$level['id']} commission_level{$level['id']}_' +ids+ '" value="" style="display:inline;width: '+96/parseInt({$shopset_level})+'%;"/> ';
										}
									}
								}
							}
							else
							{
								if('{$level['key']}' == 'default')
								{
									for (var li = 0; li<{$shopset_level};li++)
									{
										if (typeof (level_temp[li])!= "undefined")
										{
											hh += '<input data-name="commission_level_{$level['key']}_' +ids+ '"  type="text" class="form-control commission_{$level['key']} commission_{$level['key']}_' +ids+ '" value="' +$(level_temp[li]).val()+ '" style="display:inline;width: '+96/parseInt({$shopset_level})+'%;"/> ';
										}
										else
										{
											hh += '<input data-name="commission_level_{$level['key']}_' +ids+ '"  type="text" class="form-control commission_{$level['key']} commission_{$level['key']}_' +ids+ '" value="" style="display:inline;width: '+96/parseInt({$shopset_level})+'%;"/> ';
										}
									}
								}
								else
								{
									for (var li = 0; li<{$shopset_level};li++)
									{
										if (typeof (level_temp[li])!= "undefined")
										{
											hh += '<input data-name="commission_level_{$level['id']}_' +ids+ '"  type="text" class="form-control commission_level{$level['id']} commission_level{$level['id']}_' +ids+ '" value="' +$(level_temp[li]).val()+ '" style="display:inline;width: '+96/parseInt({$shopset_level})+'%;"/> ';
										}
										else
										{
											hh += '<input data-name="commission_level_{$level['id']}_' +ids+ '"  type="text" class="form-control commission_level{$level['id']} commission_level{$level['id']}_' +ids+ '" value="" style="display:inline;width: '+96/parseInt({$shopset_level})+'%;"/> ';
										}
									}
								}
							}
							hh += '</td>';
							<?php } ?>
							hh += '<input data-name="commission_id_' + ids+'"type="hidden" class="form-control commission_id commission_id_' + ids +'" value="' +(val.id=='undefined'?'':val.id )+'"/>';
							hh += '<input data-name="commission_ids"type="hidden" class="form-control commission_ids commission_ids_' + ids +'" value="' + ids +'"/>';
							hh += '<input data-name="commission_title_' + ids +'"type="hidden" class="form-control commission_title commission_title_' + ids +'" value="' +(val.title=='undefined'?'':val.title )+'"/></td>';
							hh += '<input data-name="commission_virtual_' + ids +'"type="hidden" class="form-control commission_virtual commission_virtual_' + ids +'" value="' +(val.virtual=='undefined'?'':val.virtual )+'"/></td>';
							hh += "</tr>";
						}
						html += hh;
						html += "</table>";
						$("#commission").html(html);
					}

				function setCol(cls){
					$("."+cls).val( $("."+cls+"_all").val());
				}
				function showItem(obj){
					var show = $(obj).get(0).checked?"1":"0";
					$(obj).parents('.spec_item_item').find('.spec_item_show:eq(0)').val(show);
				}
				function nofind(){
					var img=event.srcElement;
					img.src="./resource/image/module-nopic-small.jpg";
					img.onerror=null;
				}

					function choosetemp(id){
					$('#modal-module-chooestemp').modal();
					$('#modal-module-chooestemp').data("temp",id);
				}
				function addtemp(){
					var id = $('#modal-module-chooestemp').data("temp");
					var temp_id = $('#modal-module-chooestemp').find("select").val();
					var temp_name = $('#modal-module-chooestemp option[value='+temp_id+']').text();
					//alert(temp_id+":"+temp_name);
					$("#temp_name_"+id).val(temp_name);
					$("#temp_id_"+id).val(temp_id);
					$('#modal-module-chooestemp .close').click();
					refreshOptions()
				}

				function setinterval(type)
				{
					var intervalfloor =$('#intervalfloor').val();
					if(intervalfloor=="")
					{
						intervalfloor=0;
					}
					intervalfloor = parseInt(intervalfloor);

					if(type=='plus')
					{
						if(intervalfloor==3)
						{
							tip.msgbox.err("最多添加三个区间价格");
							return;
						}
						intervalfloor=intervalfloor+1;
					}
					else if(type=='minus')
					{
						if(intervalfloor==0)
						{
							tip.msgbox.err("请最少添加一个区间价格");
							return;
						}
						intervalfloor=intervalfloor-1;
					}else
					{
						return;
					}

					if(intervalfloor<1)
					{

						$('#interval1').hide();
						$('#intervalnum1').val("");
						$('#intervalprice1').val("");
					}else
					{
						$('#interval1').show();
					}

					if(intervalfloor<2)
					{

						$('#interval2').hide();
						$('#intervalnum2').val("");
						$('#intervalprice2').val("");
					}else
					{
						$('#interval2').show();
					}

					if(intervalfloor<3)
					{

						$('#interval3').hide();
						$('#intervalnum3').val("");
						$('#intervalprice3').val("");
					}else
					{
						$('#interval3').show();
					}


					$('#intervalfloor').val(intervalfloor);

				}


				</script>

				
				<!-- option end -->
				</div></div>
				<div class="tab-pane <?php if($_GET['tab']=='des'){ ?>active<?php } ?>" id="tab_des" > <div class="panel-body" >
				<include file="goods/tab/des" />
				<!--des begin -->
				<div class="region-goods-details row">
					<div class="region-goods-left col-sm-2">商品详情</div>
					<div class=" region-goods-right col-sm-10">
						<div class="">
						   
							{:tpl_ueditor('content',htmlspecialchars_decode($item['content']),array('height'=>'300'))}
							
						</div>
					</div>
				</div>


				
				<!--des end-->
				</div></div>
				
				
			</div>
        </div>
    </div>
   
    <div class="form-group">
        <label class="col-sm-2 control-label"></label>
        <div class="col-sm-9 subtitle">
            <input type="submit" value="保存商品" class="btn btn-primary"/>
			
        </div>
    </div>
  
</form>
</div>
<script type="text/javascript">
	window.type = "{$item['type']}";
	window.virtual = "{$item['virtual']}";
	require(['bootstrap'], function ($) {
		
		$('#myTab a').click(function (e) {
			
			$('#tab').val( $(this).attr('href'));
			e.preventDefault();
			$(this).tab('show');
		})
	});
	
</script>



<script>
    $(function () {
        $("label[for='commission_type0']").click(function () {
            $("#commission_1").hide();
            $("#commission_0").show();
        });
        $("label[for='commission_type1']").click(function () {

            commission_change();
            $("#commission_0").hide();
            $("#commission_1").show();
        });
    });
    function commission_change() {
        var html = '<table class="table table-bordered table-condensed" {if count($commission_level) >5} style="width: {php echo count($commission_level)* 205}px;" <?php } ?> ><thead><tr class="active">{loop $commission_level $level}<th><div class=""><div style="padding-bottom:10px;text-align:center;">{$level["levelname"]}</div></div></th><?php } ?></tr></thead><tbody><tr>{loop $commission_level $level}{if $level["key"]=="default"}<td>{php for ($c_i = 0; $c_i < $set["commiss_level"]; $c_i++): }<input name="commission_level_{$level["key"]}_default[]" type="text" class="form-control commission_{$level["key"]} commission_{$level["key"]}_default" value="{php echo $commission[$level["key"]]["option0"][$c_i ];}" style="display:inline;width: {php echo (96 / $set["commiss_level"])}%;" placeholder="{php echo $c_i+1}级"> {php endfor;}</td><?php  }else{  ?><td>{php for ($c_i = 0; $c_i < $set["commiss_level"]; $c_i++): }<input name="commission_level_{$level["id"]}_default[]" type="text" class="form-control commission_level{$level["id"]} commission_{$level["key"]}_default" value="{php echo $commission["level".$level["id"]]["option0"][$c_i ];}" style="display:inline;width: {php echo (96 / $set["commiss_level"])}%;" placeholder="{php echo $c_i+1}级"> {php endfor;}</td><?php } ?><?php } ?></tr></tbody></table>';
        if ($("#commission").html()=='')
        {
            $("#commission_default").html(html);
            $("#commission_default").show();
        }
        else
        {
            $("#commission_default").html('');
            $("#commission_default").show();
        }
    }
    commission_change();

    function commission_change_all() {
        var commission_level1 = $("#commission_level1").val();
        var commission_level2 = $("#commission_level2").val();
        var commission_level3 = $("#commission_level3").val();

        if (commission_level1=='')
        {
            tip.msgbox.err('请选择分销商等级');
            return false;
        }
        if (commission_level2=='')
        {
            tip.msgbox.err('请选择佣金等级');
            return false;
        }
        if (commission_level3=='')
        {
            tip.msgbox.err('请填写佣金比例');
            return false;
        }

        if (commission_level1=='default')
        {
            $(".commission_default").each(function (key,val) {
                if(key%{$set["commiss_level"]} == commission_level2)
                {
                    $(this).val(commission_level3);
                }
            });
        }
        else
        {
            $(".commission_level"+commission_level1).each(function (key,val) {
                if(key%1 == commission_level2)
                {
                    $(this).val(commission_level3);
                }
            });
        }
    }
	function showTime(obj) {
        if (obj.checked) {
            $('#timediv').show();
            $('#isdiscount_time').hide();
            $('input[name="isdiscount"]').removeAttr('checked');
            $('#isdiscount_true').hide();
        } else {
            $('#timediv').hide();
        }
    }

  
    function isdiscount_change() {
        var html = '<table class="table table-bordered table-condensed"><thead><tr class="active">{loop $levels $level}<th><div class=""><div style="padding-bottom:10px;text-align:center;">{$level["levelname"]}</div></div></th><?php } ?></tr></thead><tbody><tr>{loop $levels $level}{if $level["key"]=="default"}<td><input name="isdiscount_discounts_level_{$level["key"]}_default" type="text" class="form-control isdiscount_discounts_{$level["key"]} isdiscount_discounts_{$level["key"]}_default" value="{php echo is_array($isdiscount_discounts[$level["key"]]["option0"]) ? '' : $isdiscount_discounts[$level["key"]]["option0"];}" placeholder="会员促销价格单位: 元"></td><?php  }else{  ?><td><input name="isdiscount_discounts_level_{$level["id"]}_default" type="text" class="form-control isdiscount_discounts_level{$level["id"]} isdiscount_discounts_level{$level["id"]}_default" value="{php echo is_array($isdiscount_discounts["level".$level["id"]]["option0"]) ? '' : $isdiscount_discounts["level".$level["id"]]["option0"];}" placeholder="会员促销价格单位: 元"></td><?php } ?><?php } ?></tr></tbody></table>';
        if ($("#isdiscount_discounts").html()=='')
        {
            $("#isdiscount_discounts_default").html(html);
        }
        else
        {
            $("#isdiscount_discounts_default").html('');
        }
    }

    isdiscount_change();
</script>

</block>