<?php include_once(mvc::$cfg['PATH_TPL'].'public/headBase.php');?>
<link rel="stylesheet" type="text/css" href="<?php echo mvc::$cfg['ADMIN_URL'];?>static/css/jquery.autocomplete.css">
<div class="main_auto" style="width:1500px">
	<?php if ($PartArr['part_is_end'] > 0){?>
	<div id="ProRight" style="width:910px;">
		<form method="post" action="<?php echo mvc::$cfg['ADMIN_URL'];?>index.php/part/partParaSetOk" onsubmit="return CheckPartPara()" >
			<input type="hidden" name="PartId" value="<?php echo $PartArr['part_id'];?>"/>
			<div class="BgMenu"><span>子零件管理</span></div>
			<table class="table table-bordered" id="spartlist">
				<thead>
					<tr>
						<th width="30px"><a href="javascript:void(0)" class="icon2 icon2_add" onclick="addSmallPart(1)"></a></th>
						<th width="350px">名称</th>
						<th>顺序</th>
					</tr>
				</thead>
				<tbody>
					<?php foreach ($smallPartArr as $v){?>
					<tr num="<?php echo $v['pas_id'];?>">
						<td><a href="javascript:void(0)" class="icon2 icon2_del" onclick="delSmallPart(this)"></a></td>
						<td><input type="text" class="form-control" name="spart[<?php echo $v['pas_id'];?>][pas_name]" value="<?php echo $v['pas_name'];?>" size="30"/>
						ID:<?php echo $PartArr['part_id'].'_'.$v['pas_id'];?></td>
						<td><input type="text" class="form-control" name="spart[<?php echo $v['pas_id'];?>][pas_seq]" value="<?php echo $v['pas_seq'];?>" size="3"/></td>
					</tr>
					<?php }?>
				</tbody>
			</table>
			<br>
			
			<div class="BgMenu"><span>零件参数</span><span class="orange">（宜配名、TCD名、TCD中国名  多个用逗号,分隔）</span></div>
			<table class="table table-bordered" id="paralist">
				<thead>
					<tr>
						<th width="30px"><a href="javascript:void(0)" class="icon2 icon2_add" onclick="addPartPara(1)"></a></th>
						<th>参数名</th>
						<th>宜配名[英文]</th>
						<th>TCD名[英文]</th>
						<th>TCD中国名</th>
						<th>智配名</th>
						<th width="60px">值类型</th>
						<th width="60px">单位</th>
						<th width="60px">顺序</th>
						<th width="50px">配件数</th>
					</tr>
				</thead>
				<tbody>
				<?php foreach ($ParaArr as $V){?>
					<tr num="<?php echo $V['pal_id'];?>">
						<td><a href="javascript:void(0)" class="icon icon_delete" onclick="delPartPara(this, <?php echo (int) $palProCount[$V['pal_id']];?>)"></a></td>
						<td><input type="text" class="form-control w100" name="para[<?php echo $V['pal_id'];?>][pal_name]" value="<?php echo $V['pal_name'];?>"/></td>
						<td><input type="text" class="form-control w100" name="para[<?php echo $V['pal_id'];?>][ppl_toname_yp]" value="<?php echo $V['ppl_toname_yp'];?>"/></td>
						<td><input type="text" class="form-control w100" name="para[<?php echo $V['pal_id'];?>][ppl_toname_tcd]" value="<?php echo $V['ppl_toname_tcd'];?>"/></td>
						<td><input type="text" class="form-control w100" name="para[<?php echo $V['pal_id'];?>][ppl_toname_tcdcn]" value="<?php echo $V['ppl_toname_tcdcn'];?>"/></td>
						<td><input type="text" class="form-control w100" name="para[<?php echo $V['pal_id'];?>][ppl_toname_zhipei]" value="<?php echo $V['ppl_toname_zhipei'];?>"/></td>
						<td>
							<select name="para[<?php echo $V['pal_id'];?>][ppl_style]" class="form-control" onchange="ChangeParaStyle(this)"<?php if(!empty($palProCount[$V['pal_id']])) echo " disabled";?>>
								<option value="0" <?php if ($V['ppl_style'] == 0){?>selected="selected"<?php }?>>字符串</option>
								<option value="1" <?php if ($V['ppl_style'] == 1){?>selected="selected"<?php }?>>数值</option>
							</select>
						</td>
						<td> 
							<select name="para[<?php echo $V['pal_id'];?>][ppl_pau_id]" class="form-control" onchange="ChangeParaUnit(this)"<?php if(!empty($palProCount[$V['pal_id']])) echo " disabled";?>>
								<?php foreach ($AllUnitArr as $VV){?>
								<option value="<?php echo $VV['pau_id'];?>" <?php if ($V['pau_id'] === $VV['pau_id']){?>selected="selected"<?php }?>><?php echo $VV['pau_name'];?></option>
								<?php }?>
							</select>
						</td>
						<td><input type="text" class="form-control" name="para[<?php echo $V['pal_id'];?>][ppl_seq]" value="<?php echo $V['ppl_seq'];?>" size="3"/></td>
						<td><?php if(!empty($palProCount[$V['pal_id']])) echo $palProCount[$V['pal_id']];?></td>
					</tr>
				<?php }?>
				</tbody>
			</table>
			<input type="hidden" name="deleteId" value="">
			<br>
			<div class="center"><input class="btn btn-default btn-primary" type="submit" value="保存子零件/参数"/></div>
		</form>
	</div>
	<?php }?>
	<div id="ProLeft" style="width:570px;">
		<div class="BgMenu"><span>零件基本信息</span></div>
		<form method="post" action="<?php echo mvc::$cfg['ADMIN_URL'];?>index.php/part/partSetOk" onsubmit="return CheckPartBasic()">
			<input type="hidden" name="PartId" id="PartId" value="<?php echo $PartArr['part_id'];?>"/>
			<table class="table table-bordered">
				<tr>
					<th class="right" width="100px">零件名称：</th>
					<td><input type="text"  name="base[part_name]" class="form-control" id="partName" value="<?php echo $PartArr['part_name'];?>"/> ID:<?php echo $PartArr['part_id'].'_0';?></td>
				</tr>
				<tr>
					<th class="right"><span Helper="010_001"></span>关键字：</th>
					<td>
						<textarea class="form-control" rows="7" name="base[part_keyword]" cols="50" onchange="STRING.toKeyword(this)"><?php echo $PartArr['part_keyword'];?></textarea>
						<div style="float:right;">
							<div id="logoBox" class="picture-wrap">
								<?php if(!empty($PartArr['part_img'])){ ?>
									<a href="<?php echo LibFc::ImgRoute([$PartArr['part_img'],100],'logo');?>" target="_blank" title="点击查看大图">
										<img id="logoImg" src="<?php echo LibFc::ImgRoute([$PartArr['part_img']],'logo');?>"/>
									</a>
									<input type="hidden" name="base[part_img]" id='logoVal' value="<?php echo $PartArr['part_img'];?>"/>
								<?php }else{ ?>
									<img id="logoImg" onclick="clickBlank(this)" src="<?php echo mvc::$cfg['ADMIN_STATIC_URL'].'images/web-upload-addImg.png';?>"/>
									<input type="hidden" name="base[part_img]" id='logoVal' value=""/>
								<?php } ?>
							</div>
						</div>		
					</td>
				</tr>
				<tr>
					<th class="right">虚拟分类：</th>
					<td>
						<label><input type="radio" name="base[part_virtual]" value="1" <?php if ($PartArr['part_virtual'] > 0) echo ' checked';?>> 是</label>&nbsp;&nbsp;&nbsp;&nbsp;
						<label><input type="radio" name="base[part_virtual]" value="0" <?php if ($PartArr['part_virtual'] < 1) echo ' checked';?>> 否</label>
					</td>
				</tr>
				<tr>
					<th class="right">末级分类：</th>
					<td>
						<label><input type="radio" name="base[part_is_end]" value="1" <?php if ($PartArr['part_is_end'] > 0) echo ' checked';?>> 是</label>&nbsp;&nbsp;&nbsp;&nbsp;
						<label><input type="radio" name="base[part_is_end]" value="0" <?php if ($PartArr['part_is_end'] < 1) echo ' checked';?>> 否</label>
					</td>
				</tr>
				<tr>
					<th class="right">
					目录绑定厂商：
					<div class="center"><a href="<?php echo mvc::$cfg['ADMIN_URI'];?>part/tcdsup" target="_blank" class="a_blue">厂商列表</a></div>
					</th>
					<td><textarea class="form-control" rows="3" name="base[part_sup_names]" cols="70" onchange="STRING.toKeyword(this)" placeholder="如:TRW,ATE 多个逗号分隔"><?php echo $PartArr['part_sup_names'];?></textarea></td>
				</tr>
				<tr>
					<th class="right">
					目录绑定零件：
					<div class="center"><a href="<?php echo mvc::$cfg['ADMIN_URI'];?>part/tcdsup" target="_blank" class="a_blue">零件列表</a></div>
					</th>
					<td><textarea class="form-control" rows="3" name="base[part_opart_names]" cols="70" onchange="STRING.toKeyword(this)" placeholder="如:刹车片,刹车片(前) 多个逗号分隔"><?php echo $PartArr['part_opart_names'];?></textarea></td>
				</tr>
				<tr>
					<th class="right">目录车型：</th>
					<td>
						<?php foreach($partModelFiled as $filed=>$fname){?>
						<label><input type="checkbox" name="model_fileds[]" <?php if(in_array($filed, $PartArr['part_model_fileds'])) echo ' checked';?> value="<?php echo $filed;?>"><?php echo $fname;?></label>&nbsp;&nbsp;&nbsp;&nbsp;
						<?php }?>
					</td>
				</tr>
				<tr>
					<th class="right">关系树：</th>
					<td>
						<table class="table table-bordered" id="PartParentList">
							<tr class="success">
								<td colspan="3">
									<input type="text" class="form-control" id="TempPartParent" size="50"/>
									<input type="button" class="btn btn-default btn-info" value="添加父级" onclick="AddPartParent()"/>
								</td>
							</tr>
							<tr class="success">
								<th>父级</th>
								<th width="60px">主关系</th>
								<th width="40px">操作</th>
							</tr>
						<?php foreach ($ParentArr as $V){?>
							<tr id="ParentTr<?php echo $V['pt_parent_part_id'];?>" class="Parent">
								<td><input type="hidden" name="Parent[]" value="<?php echo $V['pt_parent_part_id'];?>"/><?php echo $V['name'];?></td>
								<td><label><input name="IsMain" value="<?php echo $V['pt_parent_part_id'];?>" <?php if ($V['pt_ismain'] > 0){?>checked<?php }?> type="radio"></label></div></td>
								<td><a href="javascript:void(0)" class="icon icon_delete" onclick="RemoveParentTr(<?php echo $V['pt_parent_part_id'];?>)"></a></td>
							</tr>
						<?php }?>
						</table>
					</td>
				</tr>
				<tr>
					<td colspan="2" align="center"><input type="submit" class="btn btn-default btn-primary" value="保存基本信息"/></td>
				</tr>
			</table>
		</form>
	</div>
	
</div>
<?php include_once(mvc::$cfg['PATH_TPL'].'public/footBase.php');?>
<script type="text/javascript" src="<?php echo mvc::$cfg['ADMIN_URL'];?>static/js/part.js?ver=<?php echo mvc::$cfg['VER']['js'];?>"></script>
<script type="text/javascript" src="<?php echo mvc::$cfg['ADMIN_URL'];?>static/js/jquery.autocomplete.js"></script>
<script type="text/javascript">
var AutoPartArr = <?php echo json_encode($AutoPartArr);?>;
$(function() {
	//父级自动完成
	$("#TempPartParent").autocomplete(AutoPartArr, {
		minChars: 0,
		max: 500,
		matchContains : true,
		formatItem: function(row) {
			return row.name;
		},
		formatMatch: function(row) {
			return row.name;
		},
		formatResult: function(row) {
			return row.name;
		}
	});

	intiParamAdd();
	if($('#spartlist tbody tr').length < 1) addSmallPart(2);
	if($('#paralist tbody tr').length < 1) addPartPara(2);
	
	//分类标识
	PartLogo.initUpload('logo','shopLogo');
});

//子零件管理
function addSmallPart(count)
{
	var num = -new Date().getTime();
	for(var i = count; i > 0; i--){
		num -= i;
		var tpl = `<tr num="`+num+`">
			<td><a href="javascript:void(0)" class="icon2 icon2_del" onclick="delSmallPart(this)"></a></td>
			<td><input type="text" class="form-control" name="spart[`+num+`][pas_name]" size="50"/></td>
			<td><input type="text" class="form-control" name="spart[`+num+`][pas_seq]" size="3"/></td>
		</tr>`;
		$('#spartlist tbody').append(tpl);
	}
}

function delSmallPart(obj){
	$(obj).parents('tr').remove();
}

//零件参数
function addPartPara(count)
{
	var num = -new Date().getTime();
	for(var i = count; i > 0; i--){
		num -= i;
		var tpl = `<tr num="`+num+`">
			<td><a href="javascript:void(0)" class="icon icon_delete" onclick="delPartPara(this, 0)"></a></td>
			<td><input type="text" class="form-control w100" name="para[`+num+`][pal_name]"/></td>
			<td><input type="text" class="form-control w100" name="para[`+num+`][ppl_toname_yp]"/></td>
			<td><input type="text" class="form-control w100" name="para[`+num+`][ppl_toname_tcd]"/></td>
			<td><input type="text" class="form-control w100" name="para[`+num+`][ppl_toname_tcdcn]"/></td>
			<td><input type="text" class="form-control w100" name="para[`+num+`][ppl_toname_zhipei]"/></td>
			<td>
				<select name="para[`+num+`][ppl_style]" class="form-control" onchange="ChangeParaStyle(this)">
					<option value="0">字符串</option>
					<option value="1">数值</option>
				</select>
			</td>
			<td> 
				<select name="para[`+num+`][ppl_pau_id]" class="form-control" onchange="ChangeParaUnit(this)">
					<?php foreach ($AllUnitArr as $VV){?>
					<option value="<?php echo $VV['pau_id'];?>"><?php echo $VV['pau_name'];?></option>
					<?php }?>
				</select>
			</td>
			<td><input type="text" class="form-control" name="para[`+num+`][ppl_seq]" size="3"/></td>
			<td></td>
		</tr>`;
		$('#paralist tbody').append(tpl);
	}
}

function delPartPara(obj, ProCount){
	if(ProCount < 1)
	{
		$(obj).parents('tr').remove();
	}
	else if(confirm('有'+ProCount+'个产品有该参数的值，确定要删除吗？'))
	{
		$(obj).parents('tr').remove();
	}
}
</script>