<?php echo $this->fetch('header.html'); ?>
<script language="javascript" src="/static/js/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript" src="/plugin/ueditor/ueditor.config.js"></script>
<script language="javascript" src="/plugin/ueditor/ueditor.all.min.js?v=<?php echo time(); ?>"></script>

<script language="javascript">
options={
		initialFrameWidth:"100%",
		imageUrl:"/index.php?m=upload&a=UeImg&dir=product&id=<?php echo $this->_var['data']['id']; ?>" ,
		fileUrl:"/index.php?m=upload&a=UeFile&dir=product&id=<?php echo $this->_var['data']['id']; ?>",
		catcherUrl:"/index.php?m=upload&a=UeRemote&dir=product&id=<?php echo $this->_var['data']['id']; ?>"
		 
};
var editor=UE.getEditor('content',options)
</script>
<script language="javascript" src="/static/js/ajaxfileupload.js"></script>
<script language="javascript">
   function uploadgoodsimg()
    {
        //starting setting some animation when the ajax starts and completes
        $("#loading")
        .ajaxStart(function(){
            $(this).show();
        })
        .ajaxComplete(function(){
            $(this).hide();
        });

        $.ajaxFileUpload
        (
            {
                url:'/index.php?m=upload&a=uploadtao&dir=product&id=<?php echo $this->_var['data']['id']; ?>&t='+Math.random(), 
                secureuri:false,
                fileElementId:'upimg',
                dataType: 'json',
                success: function (data, status)
                {
                    if(typeof(data.error) != 'undefined')
                    {
                        if(data.error != '')
                        {
                           alert(data.msg);
                        }else
                        {
                             $("#imgShow").html("<img src='/"+data.imgurl+".100x100.jpg' width='100'>");
							 $("#imgurl").val(data.imgurl);
                        }
                    }
                },
                error: function (data, status, e)
                {
					alert(data.msg)
  
                }
            }
        )
        
        return false;

    }
</script>
<div class="row">
<div class="span12">
<?php echo $this->fetch('admin_product_nav.html'); ?>
<h2>产品编辑<?php if ($this->_var['data']['id']): ?><small><a href="/index.php?m=show&a=default&id=<?php echo $this->_var['data']['id']; ?>" target="_blank">查看前台</a></small><?php endif; ?></h2>
<form action="<?php echo APPADMIN; ?>?m=admin_product&a=save" method="post" onkeypress="javascript:return NoSubmit(event);" enctype="multipart/form-data">
<input type="hidden" name="id" value="<?php echo $this->_var['data']['id']; ?>">
<input type="hidden" name="goodsid" id="goodsid" value="<?php echo $this->_var['data']['goodsid']; ?>" />

<ul class="nav nav-tabs" id="myTab">
<li class="active"><a href="#p_base">基本信息</a></li>

<li><a href="#p_other">其他信息</a></li>
 <li ><a href="#p_attr">商品属性</a></li>
  
</ul>

<div class="tab-content">
 <div class="tab-pane active" id="p_base">
<table width="100%" border="0" class="table table-bordered">
  <tr>
    <td align="right">商品地址：</td>
    <td><label for="goodsurl"></label>
      <input name="goodsurl" type="text" id="goodsurl" class="w600 h20" value="<?php echo $this->_var['data']['goodsurl']; ?>"><br />
      <input type="button"  id="getTaobao" class="btn btn-warning" value="获取淘宝信息" />
      <input type="button" value="查看淘宝"  id="goTaobao" class="btn" />  内容 <input type="checkbox" id="getContent" value="1" /> 图片 <input type="checkbox" id="getImg" value="1" />
      </td>
   </tr>
   
   <tr>
	<td>分类：</td>
	<td><select name="catid[]" id="catid">
    <option value="0">无分类</option>
    	<?php $_from = $this->_var['cat_1_list']; if (!is_array($_from) && !is_object($_from)) { $_from=array();}; $this->push_vars('', 'c');if (count($_from)):
    foreach ($_from AS $this->_var['c']):
?>
        <option value="<?php echo $this->_var['c']['id']; ?>" <?php if ($this->_var['parent_1_id'] == $this->_var['c']['id']): ?> selected="selected"<?php endif; ?>><?php echo $this->_var['c']['cname']; ?></option>
        <?php endforeach; endif; unset($_from); ?><?php $this->pop_vars();; ?>
    </select>
    	二级分类：
    	<select name="catid[]" id="catid_2nd">
        <option value="0">无分类</option>
    	<?php $_from = $this->_var['cat_2_list']; if (!is_array($_from) && !is_object($_from)) { $_from=array();}; $this->push_vars('', 'c');if (count($_from)):
    foreach ($_from AS $this->_var['c']):
?>
        <option value="<?php echo $this->_var['c']['id']; ?>" <?php if ($this->_var['parent_2_id'] == $this->_var['c']['id']): ?> selected="selected"<?php endif; ?>><?php echo $this->_var['c']['cname']; ?></option>
        <?php endforeach; endif; unset($_from); ?><?php $this->pop_vars();; ?>
    </select>
    
    三级分类：
    	<select name="catid[]" id="catid_3nd">
        <option value="0">无分类</option>
    	<?php $_from = $this->_var['cat_3_list']; if (!is_array($_from) && !is_object($_from)) { $_from=array();}; $this->push_vars('', 'c');if (count($_from)):
    foreach ($_from AS $this->_var['c']):
?>
        <option value="<?php echo $this->_var['c']['id']; ?>" <?php if ($this->_var['parent_3_id'] == $this->_var['c']['id']): ?> selected="selected"<?php endif; ?>><?php echo $this->_var['c']['cname']; ?></option>
        <?php endforeach; endif; unset($_from); ?><?php $this->pop_vars();; ?>
    </select>
    
    </td>    
</tr>
  
<tr>
    <td align="right">标题：</td>
    <td> 
      <input name="title" type="text" id="title"   onfocus="if($(this).val()=='<?php echo $this->_var['lang']['write_title']; ?>')
      {
      $(this).val('') } " class="w600 h20" value="<?php echo $this->_var['data']['title']; ?>"></td>
  </tr>
  
  <tr>
  	<td align="right">原价：</td>
    <td><input type="text" name="price" id="price" class="w30 h20" value="<?php echo $this->_var['data']['price']; ?>" /></td>
  </tr>
  
  <tr>
  	<td align="right">口味：</td>
    <td><select name="weiid" id="weiid">
 
      <option>请选择味道</option>
      <?php $_from = $this->_var['weilist']; if (!is_array($_from) && !is_object($_from)) { $_from=array();}; $this->push_vars('k', 't');if (count($_from)):
    foreach ($_from AS $this->_var['k'] => $this->_var['t']):
?>
      <option value="<?php echo $this->_var['k']; ?>" <?php if ($this->_var['data']['weiid'] == $this->_var['k']): ?> selected="selected"<?php endif; ?>><?php echo $this->_var['t']; ?></option>
      <?php endforeach; endif; unset($_from); ?><?php $this->pop_vars();; ?>
      </select></td>
  </tr>
  
  <tr>
  	<td align="right">工艺</td>
    <td><select name="doid" id="doid">
        
      <option>请选择做法</option>
      <?php $_from = $this->_var['dolist']; if (!is_array($_from) && !is_object($_from)) { $_from=array();}; $this->push_vars('k', 't');if (count($_from)):
    foreach ($_from AS $this->_var['k'] => $this->_var['t']):
?>
      <option value="<?php echo $this->_var['k']; ?>" <?php if ($this->_var['data']['doid'] == $this->_var['k']): ?> selected="selected"<?php endif; ?>><?php echo $this->_var['t']; ?></option>
      <?php endforeach; endif; unset($_from); ?><?php $this->pop_vars();; ?>
      </select></td>
  </tr>
  
  <tr>
  	<td>星期属性：</td>
    <td>
    <input name="week1" type="checkbox" id="week1" class="weeksele" value="1" <?php if ($this->_var['data']['week1'] == 1): ?> checked="checked"<?php endif; ?> />周一
    &nbsp; 
        <input name="week2" type="checkbox" id="week2" class="weeksele" value="1" <?php if ($this->_var['data']['week2'] == 1): ?> checked="checked"<?php endif; ?>/>周二 &nbsp; 
        <input name="week3" type="checkbox" id="week3" class="weeksele" value="1" <?php if ($this->_var['data']['week3'] == 1): ?> checked="checked"<?php endif; ?>/>周三 &nbsp; 
        <input name="week4" type="checkbox" id="week4" class="weeksele" value="1" <?php if ($this->_var['data']['week4'] == 1): ?> checked="checked"<?php endif; ?>/>周四&nbsp; 
        <input name="week5" type="checkbox" id="week5" class="weeksele" value="1" <?php if ($this->_var['data']['week5'] == 1): ?> checked="checked"<?php endif; ?>/>
        周五&nbsp;  
        <input name="week6" type="checkbox" id="week6" class="weeksele" value="1" <?php if ($this->_var['data']['week6'] == 1): ?> checked="checked"<?php endif; ?>/>周六 &nbsp; 
        <input name="week7" type="checkbox" id="week7" class="weeksele" value="1" <?php if ($this->_var['data']['week7'] == 1): ?> checked="checked"<?php endif; ?>/>
        周日&nbsp; 
        <a href="javascript:;" onclick="$('.weeksele').attr('checked',true)">全选</a>
    </td>
 </tr>
  
   <tr>
    <td align="right">图片：</td>
    <td>
    <div class="btn-upload">
      <input type="file" name="upimg" class="btn-upload-file" id="upimg" onChange="uploadgoodsimg()">
      </div>
      <label  id="loading" style="color:red; display:none;">正在上传中...</label>
      <input type="hidden" name="imgurl" id="imgurl" value="<?php echo $this->_var['data']['imgurl']; ?>">
      <span id="imgShow">
      <?php if ($this->_var['data']['imgurl']): ?>
      <img src="/<?php echo $this->_var['data']['imgurl']; ?>.100x100.jpg">
      <?php endif; ?>
      </span>
      </td>
  </tr>
   
  <tr>
    <td width="15%" align="right">描述：</td>
    <td width="85%"><label for="description"></label>
      <textarea name="description" id="description"  class="w600 h100"><?php echo $this->_var['data']['description']; ?></textarea></td>
    </tr>
  <tr>
    <td align="right">关键词：</td>
    <td><label for="keywords"></label>
      <input name="keywords" type="text" id="keywords" class="w600 h20" value="<?php echo $this->_var['data']['keywords']; ?>"></td>
  </tr>
  
  
 
  <tr>
    <td align="right">内容：</td>
    <td>
    <script type="text/plain" id="content" name="content" ><?php echo $this->_var['data']['content']; ?></script>
    </td>
  </tr>
  
  </table>
  </div>
  
  <div class="tab-pane" id="p_attr">
  	<div id="attr_html"><input type="hidden" name="attr_cat_id" id="attr_cat_id" value="<?php echo $this->_var['attr']['attr_cat_id']; ?>" /></div>
  
  </div>
  <!--产品相册开始-->
  <div class="tab-pane" id="p_other">
   <table class="table table-bordered">
   
      
  
  
  
  <tr class="success">
  	<td align="right">优惠价：</td>
    <td><input type="text" name="lower_price" id="lower_price" class="w30 h20" value="<?php echo $this->_var['data']['lower_price']; ?>" /><font style="color:red;">*注：可以是钱、积分、金币等，表格绿色框内的可不填，只对参与活动的产品有效</font></td>
  </tr>
  
  <tr class="success">
  	<td align="right">开始时间：</td>
    <td><input type="text" name="start_time" id="start_time" class="h20" value="<?php if ($this->_var['data']['start_time']): ?><?php echo date("Y-m-d H:i",$this->_var['data']['start_time']); ?><?php endif; ?>"  onClick="WdatePicker({startDate:'%y-%M-%d',dateFmt:'yyyy-MM-dd HH:mm'})"  /></td>
  </tr>
  
  <tr class="success">
  	<td align="right">结束时间：</td>
    <td><input type="text" name="end_time" id="end_time" class=" h20" value="<?php if ($this->_var['data']['start_time']): ?><?php echo date("Y-m-d H:i",$this->_var['data']['end_time']); ?><?php endif; ?>"   onClick="WdatePicker({startDate:'%y-%M-%d',dateFmt:'yyyy-MM-dd HH:mm'})"  /></td>
  </tr>
  
  <tr class="success">
  	<td align="right">产品总数：</td>
    <td><input type="text" name="total_num" id="total_num" class="w50 h20" value="<?php if ($this->_var['data']): ?><?php echo $this->_var['data']['total_num']; ?><?php else: ?>999<?php endif; ?>" /></td>
  </tr>
  
  <tr class="success">
  	<td align="right">已购买总数：</td>
    <td><input type="text" name="buy_num" id="buy_num" class="w50 h20" value="<?php echo $this->_var['data']['buy_num']; ?>" /></td>
  </tr>
   
   <tr>
    <td align="right">喜欢数：</td>
    <td><label for="loves"></label>
      <input name="loves" type="text" id="loves" class="w50 h20" value="<?php echo $this->_var['data']['loves']; ?>"></td>
    </tr>
  <tr>
    <td align="right">讨厌数：</td>
    <td><label for="hates"></label>
      <input name="hates" type="text" id="hates" class="w50 h20" value="<?php echo $this->_var['data']['hates']; ?>"></td>
  </tr>
  
  
  
  <tr>
    <td align="right">积分：</td>
    <td><label for="grade"></label>
      <input name="grade" type="text" id="grade" class="w50 h20" value="<?php if ($this->_var['data']): ?><?php echo $this->_var['data']['grade']; ?><?php else: ?>60<?php endif; ?>"></td>
  </tr>
   </table>
  </div>
  <!--产品相册结束-->
  
 
  </div>
  
  <div>
   
    <input type="submit" name="button" id="button" class="btn btn-large btn-success" value="提交"> 
  </div>
</form>
</div>
</div>
<script language="javascript">
$(document).ready(function(){
	$('#myTab a').click(function (e) {
	  e.preventDefault();
	  $(this).tab('show');
	})
	
	/*初始化载入属性*/
	$.get("<?php echo $this->_var['appadmin']; ?>?m=admin_product&a=attr&id=<?php echo $this->_var['data']['id']; ?>&cat_id="+$("#attr_cat_id").val(),function(data){
				$("#attr_html").html(data);	
		});
	/*属性载入完毕*/
	
	$("#attr_cat_id").bind("change",function(){
		$.get("<?php echo $this->_var['appadmin']; ?>?m=admin_product&a=attr&id=<?php echo $this->_var['data']['id']; ?>&cat_id="+$(this).val(),function(data){
				$("#attr_html").html(data);	
		});
	});
	
	$(".attr_item_add").live("click",function(e){
		var obj=$(this).parent(".attr_item");
		var o_t=obj.find(".attr_item_list");
		var a_len=obj.find(".attr_item_li").length;
		var html=obj.find(".attr_item_copy").html();
		html = html.replace(/\[@\]/,"["+a_len+"]");
		obj.find(".attr_item_list").append('<div class="attr_item_li">'+html+'</li>');
	});
	
	$(".attr_item_remove").live("click",function(e){
		$(this).parents(".attr_item_li").remove();
	});
	
	/*****属性完毕****/
	$("#getTaobao").click(function(){
		var  goodsurl=$("#goodsurl").val();
		if($("#getImg").attr("checked")=="true" || $("#getImg").attr("checked")=="checked"){
			var getImg=1;
		}else{
			var getImg=0;
		}
		$.get("/index.php?m=tao&a=GetByurl&getImg="+getImg+"&dir=product&id=<?php echo $this->_var['data']['id']; ?>&goodsurl="+encodeURIComponent(goodsurl),function(data){
			if(!data.error){
				$("#goodsurl").val(data.click_url);
				$("#title").val(data.title);
				$("#keywords").val(data.title);
				$("#price").val(data.price);
				$("#description").val(data.title);
				if($("#getImg").attr("checked")=="true" || $("#getImg").attr("checked")=="checked"){
					$("#imgurl").val(data.imgurl);
					$("#imgShow").html('<img src="/'+data.imgurl+'.100x100.jpg">');
				}
				if($("#getContent").attr("checked")=="true" || $("#getContent").attr("checked")=="checked"){
					editor.setContent(data.content);
				}
				$("#goodsid").val(data.num_iid);
				$("#getImg").attr("checked",false);
				$("#getContent").attr("checked",false);
			
			}else{
				alert(data.message);
			}
			 
		},"json");
	});
	$("#goTaobao").click(function(){
		var  goodsurl=$("#goodsurl").val();
		$("#cgoTaobao").parent("a").attr("href",goodsurl);
		$("#cgoTaobao").click();
	
	});
	
	$("#catid").bind("change",function(){
		var v=$(this).val();
		$.get("<?php echo APPADMIN; ?>?m=admin_product&a=catChild",{id:v},function(data){
			$("#catid_2nd").empty().append(data);
			$("#catid_3nd").empty();
		});
		$.get("<?php echo $this->_var['appadmin']; ?>?m=admin_product&a=attrByCat",{id:v},function(data){
			$("#attr_html").html(data);	
		})
	});
	$("#catid_2nd").bind("change",function(){
		var v=$(this).val();
		$.get("<?php echo APPADMIN; ?>?m=admin_product&a=catChild",{id:v},function(data){
			$("#catid_3nd").empty().append(data);
		});
		if(parseInt(v)==0){
			v=$("#catid").val();
		}
		$.get("<?php echo $this->_var['appadmin']; ?>?m=admin_product&a=attrByCat",{id:v},function(data){
			$("#attr_html").html(data);	
		});
	});
	
	$("#catid_3nd").bind("change",function(){
		var v=$(this).val();
		if(parseInt(v)==0){
			v=$("#catid_2nd").val();
		}
		$.get("<?php echo $this->_var['appadmin']; ?>?m=admin_product&a=attrByCat",{id:v},function(data){
			$("#attr_html").html(data);	
		})
	});
	
});
</script>
<a href="http://www.taobao.com"  target="_blank" style="display:none;"><span id="cgoTaobao">xx</span></a>
<?php echo $this->fetch('footer.html'); ?>