<?php include_once(mvc::$cfg['PATH_TPL'].'public/headBase.php');?>
<div class="main_auto martb10">
	<form action="<?php echo mvc::$cfg['ADMIN_URI'];?>ads/editAds" method="post" onsubmit="return addAds.check();" id="editAds_form" data-ast="<?php echo $baseArr['pal_pll_id'];?>">
		<?php if (!empty($_GET['adsId'])){?>
			<input type="hidden" name="adsId" value="<?php echo $_GET['adsId'];?>">
		<?php }?>
		<table class="table table-bordered" id="addAds" style="width: 1200px;">
			<tr>
				<th class="right" width="100px">广告组 - 广告位</th>
				<td colspan="2">
					<select class="form-control" name="pal[pla_id]" id="place">
						<?php if(!empty($placeArr)){?>
						<?php foreach($placeArr as $k => $v){?>
						<option value="<?php echo $k;?>"><?php echo $v;?></option>
						<?php }?>
						<?php }?>
					</select>
					<select class="form-control" name="pal[pll_id]" id="placs_ads">
						<option value="0">请选择</option>
					</select>
				</td>
			</tr>
			<tr <?php if (!empty($baseArr['ads_shop_id'])){echo 'style="display:none;"';}?>>
				<th class="right">用户名称</th>
				<td colspan="2">
					<input type="text" data-provide="typeahead" value="" class="form-control" autocomplete="off" id="user_name" value="<?php echo $baseArr['u_name'];?>">
					<input type="hidden" name="ads[u_id]" value="<?php echo $baseArr['ads_u_id'];?>">
				</td>
			</tr>
			<tr <?php if (empty($baseArr['ads_shop_id'])){echo 'style="display:none;"';}?>>
				<th class="right">店铺名称</th>
				<td colspan="2">
					<input type="text" data-provide="typeahead" value="<?php echo $baseArr['shop_name'];?>" class="form-control" autocomplete="off" id="shop">
					<input type="hidden" name="ads[shop_id]" value="<?php echo $baseArr['ads_shop_id'];?>">
				</td>
			</tr>
			<tr>
				<th class="right">已有时间段</th>
				<td colspan="2">
					<?php foreach ($timeArr as $key => $value) {?>
					<?php if (!empty($value['pat_etime'])){?>
					<div class="has-time">
						<?php if (!empty($addr[$value['pat_pc_id']])){?>
						<label><?php echo $addr[$value['pat_pc_id']]['pc_pname'].' - '.$addr[$value['pat_pc_id']]['pc_name'];?></label>
						<?php }?>
					<?php echo date('Y-m-d H:i:s', $value['pat_btime']);?> 到 <?php echo date('Y-m-d H:i:s', $value['pat_etime']);?> </div>
					<?php }?>
					<?php }?>
				</td>
			</tr>
			<tr class="histoty_box all">
				<th class="right">已有广告</th>
				<td colspan="2">
					<div class="history_head"><button type="button" id="addNew" class="btn btn-primary btn-xs">添加新广告</button></div>
					<div id="shop_history" class="mart10"></div>
				</td>
			</tr>
			<tr id="place_word" class="config all">
				<th class="right  info">关键字</th>
				<td colspan="2">
					<table class="table table-bordered set-word">
						<thead>
							<tr>
								<th width="10px"><i class="icon2 icon2_add" onclick="addAds.addWord();"></i></th>
								<th width="50px">关键字</th>
								<th>可选时间段</th>
							</tr>
						</thead>
						<tbody>
							<tr>
								<td width="50px"  colspan="2"><input type="text" disabled="" data-key="-1" name="pak[keyword][-1]" class="form-control word" value=""></td>
								<td id="wor_box-1"></td>
							</tr>
						</tbody>
					</table>
				</td>
			</tr>
			<tr class="time_limit_box all">
				<th class="right">时间段</th>
				<td colspan="2" >
					<div id="time_limit" class="clearfix"></div>
				</td>
			</tr>
			<tr class="all main">
				<th class="right">广告名称</th>
				<td colspan="2"><input type="text" disabled="" name="ads[name]" class="form-control" value="<?php echo $baseArr['ads_name'];?>"></td>
			</tr>
			<tr class="all main">
				<th class="right">广告链接</th>
				<td colspan="2"><input type="text" disabled="" name="ads[url]" class="form-control" value="<?php echo $baseArr['ads_url'];?>"></td>
			</tr>
			
			<tr id='place_title' class="config all">
				<th class="right  info">展示标题</th>
				<td colspan="2"><input type="text" disabled="" name="ads[title]" class="form-control" value="<?php echo $baseArr['ads_title'];?>"></td>
			</tr>
			<tr id="place_des" class="config all">
				<th class="right  info">展示描叙</th>
				<td colspan="2"><input type="text" disabled="" class="form-control" name="ads[des]" value="<?php echo $baseArr['ads_des']?>" size="100"/></td>
			</tr>
			
			<tr id="place_proid" class="config all">
				<th class="right  info">配件ID</th>
				<td colspan="2"><input type="text" disabled="" name="ads[proid]" class="form-control" value="<?php echo $baseArr['ads_proid'];?>"></td>
			</tr>
			<tr id='place_css' class="config all">
				<th class="right  info">自定义样式</th>
				<td colspan="2"><input type="text" disabled="" class="form-control" name="ads[css]" value="<?php echo $baseArr['ads_css']?>" size="100"/></td>
			</tr>
			<tr id='place_price' class="config all">
				<th class="right  info">展示价格</th>
				<td colspan="2"><input type="text" disabled="" name="ads[price]" class="form-control" value="<?php echo $baseArr['ads_price']?>"></td>
			</tr>
			<tr id="place_orgPrice" class="config all">
				<th class="right  info">原价价格</th>
				<td colspan="2"><input type="text" disabled="" name="ads[org_price]" class="form-control" value="<?php echo $baseArr['ads_org_price']?>"></td>
			</tr>
			<tr id='place_img' class="config all">
				<th class="right  info">图片</th>
				<td>
					<div class="adsImgBox">展示图：
						<input type="hidden" disabled="" name="ads[img]" id="valImg0" value="<?php echo $baseArr['ads_img']?>"/>
						<a href="<?php if(!empty($baseArr['ads_img'])) echo mvc::$cfg['FILE_CENTER']['bna']['url_get'].'&c=bna&f='.$baseArr['ads_img'].mvc::$cfg['FILE_CENTER']['bna']['get_uri']; else echo '#'?>" target="_blank">
							<img class="adsImg" src="<?php if(!empty($baseArr['ads_img'])) echo mvc::$cfg['FILE_CENTER']['bna']['url_get'].'&c=bna&f='.$baseArr['ads_img'].mvc::$cfg['FILE_CENTER']['bna']['get_uri']; else echo mvc::$cfg['ADMIN_URL'].'static/images/no_img.gif';?>" id="Img0"/>
						</a>
						<span class="uploadImg" id="uploadImg0">上传</span>
					</div>
				</td>
				<td>
					<div class="adsImgBox">设计图：
						<input type="hidden" disabled="" name="ads[org_img]" id="valImg1" value="<?php echo $baseArr['ads_org_img']?>"/>
						<a href="<?php if(!empty($baseArr['ads_org_img'])) echo mvc::$cfg['FILE_CENTER']['bna']['url_get'].'&c=bna&f='.$baseArr['ads_org_img'].mvc::$cfg['FILE_CENTER']['bna']['get_uri']; else echo '#'?>" target="_blank">
							<img class="adsImg" src="<?php if(!empty($baseArr['ads_org_img'])) echo mvc::$cfg['FILE_CENTER']['bna']['url_get'].'&c=bna&f='.$baseArr['ads_org_img'].mvc::$cfg['FILE_CENTER']['bna']['get_uri']; else echo mvc::$cfg['ADMIN_URL'].'static/images/no_img.gif';?>" id="Img1"/>
						</a>
						<span class="uploadImg" id="uploadImg1">上传</span>
					</div>
				</td>
			</tr>
			<tr class="all main">
				<th class="right">排序</th>
				<td colspan="2">
					<input type="text" name="ads[seq]" disabled="" class="form-control" value="999">
				</td>
			</tr>
			<tr>
				<th class="right">状态</th>
				<td colspan="2">
					<input type="radio" name="pal[status]" value="1" <?php if ($baseArr['pal_status']){echo 'checked';}?>>启用
					<input type="radio" name="pal[status]" <?php if (!$baseArr['pal_status']){echo 'checked';}?> value="0">停用
				</td>
			</tr>
			<tr>
				<td colspan="3" class="text-center">
					<button type="submit" class="btn btn-info">保存</button>
				</td>
			</tr>
		</table>
		<input type="hidden" name="type" value="">
	</form>
</div>
<?php include_once(mvc::$cfg['PATH_TPL'].'public/footBase.php');?>
<script type="text/javascript" src="<?php echo mvc::$cfg['ADMIN_URL'];?>static/js/place.js"></script>
<script type="text/javascript" src="<?php echo mvc::$cfg['ADMIN_URL'];?>static/bootstrap-3.3.7-dist/js/bootstrap3-typeahead.js"></script>
<script type="text/javascript">
	var dataSource=<?php echo json_encode($shopArr);?>;
	$(function(){
		addAds.placeId=0;
		<?php if($baseArr['placeId']){?>
			addAds.placeId=<?php echo $baseArr['placeId'];?>;
		<?php }?>
		addAds.placeAdsId=0;
		<?php if($baseArr['placeAdsId']){?>
			addAds.placeAdsId=<?php echo $baseArr['placeAdsId'];?>;
		<?php }?>
		addAds.shopId=0;
		<?php if($baseArr['ads_shop_id']){?>
			addAds.shopId=<?php echo $baseArr['ads_shop_id'];?>;
		<?php }?>
		addAds.adsId=<?php echo $_GET['adsId'];?>;

		addAds.userId=0;
		<?php if($baseArr['ads_u_id']){?>
			addAds.userId=<?php echo $baseArr['ads_u_id'];?>;
		<?php }?>

		addAds.username='';
		<?php if($baseArr['u_name']){?>
			addAds.username='<?php echo $baseArr['u_name'];?>';
		<?php }?>

		addAds.init();
		<?php if (!empty($paddr)){?>
			addAds.provinveClick(<?php echo json_encode($paddr);?>);
		<?php }?>
		$('#shop').typeahead({
	        source: dataSource, // 数据源
	        afterSelect:function(value){
	        	$('input[name="ads[shop_id]"]').val(value.id);
	        	// addAds.changeShop(value.id);
	        	$('#user_name').parents('tr').eq(0).hide();
	        },
	        showHintOnFocus:true,
	        fitToElement:true,
	        items:8
	    });
	    $('#shop').keyup(function(){
	    	if(event.keyCode !== 13){
		    	$('input[name="ads[shop_id]"]').val('');
		    	$('#user_name').parents('tr').eq(0).show();
	    	}
	    });

	    $('#user_name').typeahead({
	        source: function(name, process){
	        	if (name != '')
	        	{
	        		var returnData = {};
	        		$.ajaxSetup({async:false});
	        		$.get(ADMIN_URI+'ads/getUserInfoByWord?isAjax=1',{'name':name},function(res){
						if(MESSAGE.ajaxError(res)){
							returnData = res.data;
						}
					},'json');
					return process(returnData);
	        	}
	        }, // 数据源
	        afterSelect:function(value){
	        	$('input[name="ads[u_id]"]').val(value.id);
	        	$('input[name="ads[u_id]"]').val(value.id);
	        	addAds.changeShop(value.id);
	        	$('#shop').parents('tr').eq(0).hide();
	        },
	        showHintOnFocus:true,
	        fitToElement:true,
	        items:8
	    });
	    $('#user_name').keyup(function(){
	    	if(event.keyCode !== 13){
		    	$('input[name="ads[u_id]"]').val('');
		    	$('#shop').parents('tr').eq(0).show();
	    	}
	    });
	});
</script>