<?php
require '../conn/conn.php';
require '../conn/function.php';
require '../conn/sendmail.php';
require 'member_check.php';

$action=$_GET["action"];
$P_id=intval($_GET["P_id"]);
$S_count=intval(getrs("select count(S_id) as S_count from sl_psort where S_mid=".$M_id,"S_count"));

if($P_id!=""){
  $aa="edit&P_id=".$P_id;
  $P=getrs("select * from sl_product where P_mid=$M_id and P_id=".$P_id);
  $P_title=$P["P_title"];
  $P_from=$P["P_from"];
  $P_pic=$P["P_pic"];
  $P_content=$P["P_content"];
  $P_piccontent=$P["P_piccontent"];
  $P_price=$P["P_price"];
  $P_price2=$P["P_price2"];
  $P_sort=$P["P_sort"];
  $P_time=$P["P_time"];
  $P_sell=$P["P_sell"];
  $P_selltype=$P["P_selltype"];
  $P_card=$P["P_card"];
  $P_use=$P["P_use"];
  $P_notify=$P["P_notify"];
  $title="编辑";
}else{
  $aa="add";
  $title="新增";
  $P_from=0;
  $P_selltype=0;
  $P_pic="nopic.png";
  $P_piccontent="nopic.png";
  $P_price=1;
  $P_price2=0;
  $P_time=date('Y-m-d H:i:s');
  $P_card="[]";
}

if($action=="add"){
    $P_tab=intval($_POST["P_tab"]);
    $P_from=intval($_POST["P_from"]);
    if($P_tab==1){
      if($C_pay==0){
        die("{\"msg\":\"当前平台收款模式为“商户自行收款”，不支持商品对接！\"}");
      }
      $P=getrs("select * from sl_product where P_del=0 and P_id=".$P_from);
      if($P==""){
        die("{\"msg\":\"对接商品ID有误，请重新检查！\"}");
      }else{
        if($P["P_mid"]==$M_id){
          die("{\"msg\":\"不支持对接自己店铺的商品！\"}");
        }else{
          if($P["P_from"]>0){
            die("{\"msg\":\"该商品非自建商品，无法对接！\"}");
          }else{
            if($P["P_sh"]==0){
              die("{\"msg\":\"该商品尚未通过审核，无法对接！\"}");
            }else{
              if($P_price>$P["P_price2"]){
                
              }else{
                die("{\"msg\":\"出售价需大于成本价！\"}");
              }
            }
          }
        }
      }
    }

    foreach ($_POST as $x=>$value) {
      if(splitx($x,"_",0)=="picpic1"){
          $pic=$pic.$_POST[$x]."|";
      }
    }
    $P_piccontent=substr($pic,0,strlen($pic)-1);
    $P_title=t($_POST["P_title"]);
    $P_pic=$_POST["P_pic"];
    $P_content=$_POST["P_content"];
    $P_price=round($_POST["P_price"],2);
    $P_price2=round($_POST["P_price2"],2);
    $P_sort=intval($_POST["P_sort"]);
    $P_time=$_POST["P_time"];
    $P_sell=$_POST["P_sell"];
    $P_use=$_POST["P_use"];
    $P_notify=$_POST["P_notify"];
    $P_selltype=intval($_POST["P_selltype"]);
    if($C_sh==1){
      $P_sh=0;
    }else{
      $P_sh=1;
    }
    $content=explode("||",$_POST["contents"]);
    $sell=explode("||",$_POST["sells"]);

    for($i=0;$i<count($content);$i++){
      if($content[$i]!=""){
           $arr=array(
            "content"=>$content[$i],
            "sell"=>$sell[$i]
            );
           $c=$c.json_encode($arr).",";
       }
    }
	$c= substr($c,0,strlen($c)-1);
	$P_card="[".$c."]";
	$P_card=str_replace("\\","\\\\",$P_card);
	
if($P_price-$P_price2>=0){
  if($P_price>0){
    if($P_title!="" && $P_content!=""){
      sql("insert into sl_product(P_from,P_title,P_pic,P_piccontent,P_content,P_price,P_price2,P_sort,P_time,P_sell,P_selltype,P_card,P_use,P_notify,P_mid,P_sh) values($P_from,'$P_title','$P_pic','$P_piccontent','$P_content',$P_price,$P_price2,$P_sort,'$P_time','$P_sell',$P_selltype,'$P_card','$P_use','$P_notify',$M_id,$P_sh)");
      $P_id=getrs("select * from sl_product where P_title='$P_title'  and P_sort=$P_sort","P_id");
      if($C_sh==1){
          sendmail("商品审核通知","<p>您的网站《".$C_webtitle."》有用户发布商品，请尽快审核</p><p>商品名称：$P_title</p><p>商品价格：$P_price</p><p>发布时间：$P_time</p>",$C_recieve);
      }
      die("{\"msg\":\"success\",\"id\":\"".$P_id."\"}");
    }else{
      die("{\"msg\":\"请填全信息\"}");
    }
  }else{
      die("{\"msg\":\"商品售价需大于0元\"}");
  }
}else{
  die("{\"msg\":\"成本价不得高于售价\"}");
}

}

if($action=="edit"){
    $P_tab=intval($_POST["P_tab"]);
    $P_from=intval($_POST["P_from"]);
    if($P_tab==1){
      if($C_pay==0){
        die("{\"msg\":\"当前平台收款模式为“商户自行收款”，不支持商品对接！\"}");
      }
      $P=getrs("select * from sl_product where P_del=0 and P_id=".$P_from);
      if($P==""){
        die("{\"msg\":\"对接品ID有误，请重新检查！\"}");
      }else{
        if($P["P_mid"]==$M_id){
          die("{\"msg\":\"不支持对接自己店铺的商品！\"}");
        }else{
          if($P["P_from"]>0){
            die("{\"msg\":\"该商品非自建商品，无法对接！\"}");
          }else{
            if($P["P_sh"]==0){
              die("{\"msg\":\"该商品尚未通过审核，无法对接！\"}");
            }else{
              if($P_price>$P["P_price2"]){
                
              }else{
                die("{\"msg\":\"出售价需大于成本价！\"}");
              }
            }
          }
        }
      }
    }

    foreach ($_POST as $x=>$value) {
      if(splitx($x,"_",0)=="picpic1"){
          $pic=$pic.$_POST[$x]."|";
      }
    }
    $P_piccontent=substr($pic,0,strlen($pic)-1);
    $P_title=t($_POST["P_title"]);
    $P_pic=$_POST["P_pic"];
    $P_content=$_POST["P_content"];
    $P_price=round($_POST["P_price"],2);
    $P_price2=round($_POST["P_price2"],2);
    $P_sort=intval($_POST["P_sort"]);
    $P_time=$_POST["P_time"];
    $P_sell=$_POST["P_sell"];
    $P_use=$_POST["P_use"];
    $P_notify=$_POST["P_notify"];
    $P_selltype=intval($_POST["P_selltype"]);

    if($C_sh==1){
      $P_sh=0;
    }else{
      $P_sh=1;
    }

    $content=explode("||",$_POST["contents"]);
    $sell=explode("||",$_POST["sells"]);

    for($i=0;$i<count($content);$i++){
      if($content[$i]!=""){
           $arr=array(
            "content"=>$content[$i],
            "sell"=>$sell[$i]
            );
           $c=$c.json_encode($arr).",";
       }
    }
	$c= substr($c,0,strlen($c)-1);
	$P_card="[".$c."]";
	$P_card=str_replace("\\","\\\\",$P_card);
if($P_price-$P_price2>=0){
if($P_price>0){
  if($P_title!="" && $P_content!=""){
    sql("update sl_product set 
    P_from=$P_from,
    P_title='$P_title',
    P_pic='$P_pic',
    P_piccontent='$P_piccontent',
    P_content='$P_content',
    P_price=$P_price,
    P_price2=$P_price2,
    P_sort=$P_sort,
    P_sh=$P_sh,
    P_selltype=$P_selltype,
    P_time='$P_time',
    P_sell='$P_sell',
    P_use='$P_use',
    P_notify='$P_notify',
    P_card='$P_card'
    where P_id=$P_id");
    if($C_sh==1){
        sendmail("商品审核通知","<p>您的网站《".$C_webtitle."》有用户发布商品，请尽快审核</p><p>商品名称：$P_title</p><p>商品价格：$P_price</p><p>发布时间：$P_time</p>",$C_recieve);
    }
    die("{\"msg\":\"success\",\"id\":\"".$P_id."\"}");
  }else{
    die("{\"msg\":\"请填全信息\"}");
  }
}else{
    die("{\"msg\":\"商品售价需大于0元\"}");
}
}else{
  die("{\"msg\":\"成本价不得高于售价\"}");
}
}

if($action=="get"){
  $id=intval($_GET["id"]);
  $P=getrs("select * from sl_product where P_id=".$id);
  if($P==""){
    die("{\"msg\":\"对接商品ID有误，请重新检查！\"}");
  }else{
    if($P["P_mid"]==$M_id){
      die("{\"msg\":\"不支持对接自己的商品！\"}");
    }else{
      if($P["P_from"]>0){
        die("{\"msg\":\"该商品非自建商品，无法对接！\"}");
      }else{
        if($P["P_sh"]==0){
          die("{\"msg\":\"该商品尚未通过审核，无法对接！\"}");
        }else{
          $P["P_sell"]="";
          $P["msg"]="success";
          die(json_encode($P));
        }
      }
    }
  }
}

?>
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
<title>商品管理 - 卖家中心</title>
<link rel="icon" href="../media/<?php echo $C_ico?>" type="image/ico">
<link href="../css/bootstrap.min.css" rel="stylesheet">
<link href="../css/materialdesignicons.min.css" rel="stylesheet">
<link href="../css/style.min.css" rel="stylesheet">
<script type="text/javascript" src="../upload/upload.js"></script>
<link rel="stylesheet" href="../js/jconfirm/jquery-confirm.min.css">
<style type="text/css">
.showpic{height: 80px;width:80px;border: solid 1px #DDDDDD;padding: 5px;}
.showpicx{width: 100%;max-width: 500px}
.list-group a{text-decoration:none}
.part{display:inline-block;width:100%;overflow:hidden;text-overflow:ellipsis;white-space: nowrap;}
.pagination{margin: 0px;}

.buy label {
  text-align: center;
  width:calc(50% - 10px);
  padding: 5px 10px;
  cursor: pointer;
  border: #CCCCCC solid 1px;
  -moz-border-radius: 3px;
  -webkit-border-radius: 3px;
  border-radius: 3px;
}

.buy .checked {
	border: #33cabb solid 1px;
	-moz-border-radius: 3px;
	-webkit-border-radius: 3px;
	border-radius: 3px;
	color: #33cabb;
	background: #F1FCFA;
}

.buy input[type="radio"] {
	display: none;
}
.table-wrapper {
  overflow-y: auto;
}
.table-wrapper table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}
.table-wrapper th,
.table-wrapper td {
  text-align: center;
}
.table-wrapper thead {
  position: sticky;
  top: 0;
  z-index: 1;
  background-color: #000;
  color: #fff;
}
</style>
</head>

<body>
<div class="lyear-layout-web">
  <div class="lyear-layout-container">
  <?php require 'nav.php';?>
    <main class="lyear-layout-content">
      <div class="container-fluid">
        <div class="row">
                <div class="col-lg-3">
                  <div class="card card-primary">
                    <div class="card-header">
                      <h4>商品列表</h4>
                    </div>
                        <ul class="list-group">
                        <?php 
                        $list=getlist("select * from sl_product where P_del=0 and P_mid=$M_id  order by P_id desc limit 10");
                        foreach($list as $row){
                          if($row["P_id"]==$P_id){
                            $active="active";
                          }else{
                            $active="";
                          }

                          echo "<a id=\"".$row["P_id"]."\" href=\"?P_id=".$row["P_id"]."\" class=\"list-group-item ".$active."\">
                          <div class=\"part\">".$row["P_title"]."</div> 
                          </a>";
                        }
                        ?>
                          
                        </ul>
                  </div>
                  <a href="product_add.php" class="btn btn-sm btn-primary"><i class="fa fa-plus-circle"></i> 新增商品</a>
                  <a href="psort.php" class="btn btn-sm btn-info"><i class="fa fa-plus-circle"></i> 新增分类</a>
                </div>
                
                <div class="col-lg-9">
                  <div class="card card-primary">
                    <div class="card-header ">
                      <h4>编辑商品</h4>
                    </div>
                    <div class="card-body">
                      <form id="form">
                      <?php if($C_pay==1){?>
                      <div class="form-group row">
                          <label class="col-md-2 col-form-label" >商品类型</label>
                          <div class="col-md-4 buy">
                          <label aa="P_from" <?php if($P_from==0){echo "class='checked'";}?>><input type="radio" name="P_tab" value="0" onclick="product_add_abutment(0)" <?php if($P_from==0){echo "checked='checked'";}?>> 自建商品</label>
                          <label aa="P_from" <?php if($P_from>0){echo "class='checked'";}?>><input type="radio" name="P_tab" value="1" onclick="product_add_abutment(1)" <?php if($P_from>0){echo "checked='checked'";}?>> 对接商品</label>
                          </div>
                        </div>
                        <div class="form-group row f2">
                          <label class="col-md-2 col-form-label" >对接商品ID</label>
                          <div class="col-md-10">
                            <div class="input-group">
                    <input type="text" name="P_from" id="P_from" class="form-control" value="<?php echo $P_from?>">
                    <span class="input-group-btn">
                        <button class="btn btn-info" type="button" onclick="product_add_get()">获取信息</button>
                    </span>
                </div>
                <div style="font-size: 12px;margin-top: 10px;color: #33cabb">*对接商品ID可以从 <a href="market.php" class="btn btn-xs btn-info" target="_blank">货源市场</a> 获取，了解更多请点击 <a href="https://www.7-card.cn/newsinfo.html?id=12" class="btn btn-xs btn-success" target="_blank">帮助文档</a></div>

                        </div>
</div>
                        <hr>
<?php }?>

                      
<div class="form-group row">
                    <label class="col-md-2" for="example-email-input">商品图片</label>
                    <div class="col-md-10">
                      <div class="row">
                      <div class="col-xs-3">
                      <img src="../media/<?php echo $P_pic?>" id="P_picx" class="showpic" onClick="showUpload('P_pic','../media');">
                    </div>
                     <div class="col-xs-9">
                            <div class="input-group">
                              <input type="text" id="P_pic" name="P_pic" class="form-control" value="<?php echo $P_pic?>">
                              <span class="input-group-btn">
                                      <button class="btn btn-primary m-b-5 m-t-5" type="button" onClick="showUpload('P_pic','../media');">上传</button>
                              </span>
                      </div>
                    </div>
                    </div>
                  </div>
                  </div>
                          <div class="form-group row">
                            <label class="col-md-2 col-form-label" >商品标题</label>
                            <div class="col-md-4">
                              <input type="text"  name="P_title" class="form-control" value="<?php echo $P_title?>">
                            </div>
                            
                            

                            <label class="col-md-2 col-form-label" >商品分类</label>
                            <div class="col-md-4">
                              <select name="P_sort" class="form-control">
									<?php
										$list=getlist("select * from sl_psort where S_del=0 and S_mid=$M_id order by S_order,S_id desc");
                    foreach($list as $row){
												if($P_sort==$row["S_id"]){
													$selected="selected";
												}else{
													$selected="";
												}
												echo "<option value=\"".$row["S_id"]."\" ".$selected.">".$row["S_title"]."</option>";
										}
									?>
								</select>
								
                            </div>

                          </div>

                          <div class="form-group row">

                            <label class="col-md-2 col-form-label" >商品价格</label>
                            <div class="col-md-4">

                              <div class="input-group">
                                <span class="input-group-addon">出售价</span>
                            <input type="text"  name="P_price" class="form-control" value="<?php echo $P_price?>">
                            <span class="input-group-addon">元</span>
                          </div>
<?php if($C_pay==1){?>
                          <div class="input-group f1">
                            <span class="input-group-addon">成本价</span>
                            <input type="text"  name="P_price2" class="form-control" value="<?php echo $P_price2?>">
                            <span class="input-group-addon">元</span>
                          </div>
                          <p class="f1" style="font-size:12px;color:#999;margin-top:5px">说明：如果商品被其他用户对接，则以成本价进行结算</p>
<?php }?>
                            </div>


                            <label class="col-md-2 col-form-label" >发布时间</label>
                            <div class="col-md-4">
                            <div class="input-group">
                                        <input type="text"  name="P_time" id="P_time" class="form-control" value="<?php echo $P_time?>">
                                        <span class="input-group-btn">
                                            <button class="btn btn-info" type="button" onclick="product_add_getdate('P_time')">获取</button>
                                        </span>
                                    </div>
                            </div>
                          </div>

                        <div class="form-group row f2">
                          <label class="col-md-2 col-form-label" >发货内容</label>
                          <div class="col-md-10" style="color:#f60">
                            发货内容及售后均由对接的商品店铺提供。
                          </div>
                        </div>
                          

                        <div class="f1">

                         <div class="form-group row">
                          <label class="col-md-2 col-form-label" >发货类型</label>
                          <div class="col-md-4 buy">
                              
                            <label aa="P_selltype" <?php if($P_selltype==0){echo "class='checked'";}?>><input type="radio" name="P_selltype" value="0" onclick="product_add_show(0)" <?php if($P_selltype==0){echo "checked='checked'";}?>> 固定内容-重复发货</label>
                            
                            <label aa="P_selltype" <?php if($P_selltype==1){echo "class='checked'";}?>><input type="radio" name="P_selltype" value="1" onclick="product_add_show(1)" <?php if($P_selltype==1){echo "checked='checked'";}?>> 卡密内容-不重复发货</label>
                            
                          </div>
                        </div>
                        
                        <div class="form-group row" id="P_sell0">
                          <label class="col-md-2 col-form-label" >发货内容</label>
                          <div class="col-md-10">
                            <textarea class="form-control" rows="5" name="P_sell" placeholder="在发货页展示"><?php echo $P_sell;?></textarea>
                          </div>
                        </div>
                        
                        
                        <div class="form-group row" id="P_sell1">
                          <label class="col-md-2 col-form-label" >发货内容</label>
                          <div class="col-md-10">
                              <div style="max-height:300px;overflow:auto;margin-bottom:10px;border-radius:5px;border:solid 1px #DDD" id="card_area">
                              <table class="table table-striped table-hover table-condensed table-wrapper" style="margin-bottom:0px">
                                  <thead><tr><th>卡密内容</th><th>是否发放</th><th>删除</th></tr></thead>
                                  <tbody id="card_table">
                                  <?php
                                  $card=json_decode($P_card,true);
                                  for($i=0;$i<count($card);$i++){
                                      
                                      if($card[$i]["sell"]==0){
                                          $sell0="selected=\"selected\"";
                                          $sell1="";
                                      }else{
                                          $sell0="";
                                          $sell1="selected=\"selected\"";
                                      }
                                      
                                      echo "<tr id=\"tr_".($i+1)."\"><td><input type=\"text\"  class=\"form-control input-sm contents\" value=\"".$card[$i]["content"]."\"></td><td><select class=\"form-control input-sm sells\"><option value=\"0\" $sell0>未发放</option><option value=\"1\" $sell1>已发放</option></select></td><td><button onclick=\"product_add_del(".($i+1).")\" class=\"btn btn-xs btn-danger\">删除</button></td></tr>";
                                  }
                                  ?>
                                </tbody>
                              </table>
                              </div>

                              <button class="btn btn-warning btn-sm btn-label" type="button" onclick="product_add_add()"><label><i class="mdi mdi-plus-box"></i></label>增加卡密</button>
                              <button class="btn btn-info btn-sm btn-label" type="button" data-toggle="modal" data-target=".bs-example-modal-lg"><label><i class="mdi mdi-library-plus"></i></label>批量增加卡密</button>
                              <button type="button" class="btn btn-sm btn-danger btn-label" onclick="clearall()"><label><i class="mdi mdi-close-circle"></i></label>清空</button>
                          </div>
                        </div>
</div>


                          <div class="form-group row">
                          <label class="col-md-2 col-form-label" >商品文字介绍</label>
                          <div class="col-md-10">
                            <textarea class="form-control" rows="15" name="P_content" placeholder="在介绍页展示"><?php echo $P_content?></textarea>
                          </div>
                        </div>

                        <div class="form-group row">
                          <label class="col-md-2 col-form-label" >商品图片介绍</label>
                          <div class="col-md-10" style="border: solid 1px #EEEEEE;padding-bottom: 10px;border-radius: 5px;background: #f9f9f9">
<table class="table" id="pic1">
                              <?php
                              $pic=explode("|",$P_piccontent);
                              for($i=0;$i<count($pic);$i++){
                                echo "<tr id=\"pp".$i."\"><td><div class=\"row\">
                                <div class=\"col-md-3\">
                                <img src=\"../media/".$pic[$i]."\" id=\"picpic1_".$i."x\" class=\"showpic\" onClick=\"showUpload('picpic1_".$i."','../media');\" alt=\"<img src='../media/".$pic[$i]."' class='showpicx'>
                                \"></div>

                                <div class=\"col-md-9\">
                                <div class=\"input-group\">
                                                    <input type=\"text\" id=\"picpic1_".$i."\" name=\"picpic1_".$i."\" class=\"form-control\" value=\"".$pic[$i]."\">
                                                    <span class=\"input-group-btn\">
                                                            <button class=\"btn btn-primary m-b-5 m-t-5\" type=\"button\" onClick=\"showUpload('picpic1_".$i."','../media');\">上传</button>
                                                    </span>
                                            </div>
                                            <button class=\"btn btn-danger btn-sm\" type=\"button\" onclick=\"DelPic(".$i.")\">- 删除该图</button>
                                            </div>
                                            </div></td></tr>";
                              }

                              ?>
</table>
<button class="btn btn-info btn-sm" type="button" onclick="AddPic()">+ 新增一个图片</button>
                          </div>
                        </div>
                        
                        <div class="form-group row">
                          <label class="col-md-2 col-form-label" >使用方法</label>
                          <div class="col-md-10">
                            <textarea class="form-control" rows="5" name="P_use" placeholder="在发货页展示"><?php echo $P_use?></textarea>
                          </div>
                        </div>

                        <div class="form-group row">
                          <label class="col-md-2 col-form-label" >支付后通知URL</label>
                          <div class="col-md-10">
                            <input type="text" name="P_notify" class="form-control" value="<?php echo $P_notify?>" placeholder="可留空">
                            <div style="font-size: 12px;margin-top: 10px;color: #33cabb">*如果您不知道如何填写，请点击 <a href="https://www.7-card.cn/newsinfo.html?id=11" class="btn btn-xs btn-success" target="_blank">帮助文档</a> </div>
                          </div>
                        </div>

                        <div class="form-group row">
                          <label class="col-md-2 col-form-label" ></label>
                          <div class="col-md-10">
                            <button class="btn btn-info" type="button" onClick="product_add_save('<?php echo $aa?>')"><?php echo $title?></button>
                            <?php if($C_sh==1){echo "<span style=\"font-size:12px;color:#33cabb\">说明：需管理员审核后才可发布</span>";}?>
                          </div>
                        </div>
                    

                  </form>
                  </div>
                  </div>
                </div>
              </div>
        
      </div>
      
    </main>
  </div>
</div>

<div class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
  <div class="modal-dialog modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
        <h4 class="modal-title" id="myLargeModalLabel">批量增加卡密</h4>
      </div>
      <div class="modal-body">
          <textarea class="form-control" rows="20" placeholder="支持批量增加，每行一条，空行无效" id="card_content"></textarea>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
        <button type="button" class="btn btn-primary" data-dismiss="modal" onclick="product_add_addcard()">点击保存</button>
      </div>
    </div>
  </div>
</div>
                
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script type="text/javascript" src="../js/bootstrap.min.js"></script>
<script type="text/javascript" src="../js/perfect-scrollbar.min.js"></script>
<script type="text/javascript" src="../js/main.min.js"></script>
<script src="../js/bootstrap-notify.min.js"></script>
<script type="text/javascript" src="../js/lightyear.js"></script>
<script src="../js/jqPaginator.min.js" type="text/javascript"></script>
<script src="../js/help.js" type="text/javascript"></script>
<script src="../js/jconfirm/jquery-confirm.min.js"></script>
<script src="../js/member.js?v=0803"></script>
<script type="text/javascript">
function AddPic()
{
 var i =pic1.rows.length;
 var newTr = pic1.insertRow();
 var _id='pp'+i;
 var newTd0 = newTr.insertCell();
 newTr.id=_id;
 newTd0.innerHTML ='<div class="row"><div class="col-md-3"><img src="../media/nopic.png" id="picpic1_'+i+'x" class="showpic" onClick="showUpload(\'picpic1_'+i+'\',\'../media\');" alt="<img src=\'../media/nopic.png\' class=\'showpicx\'>"></div><div class="col-md-9"><div class="input-group"><input type="text" id="picpic1_'+i+'" name="picpic1_'+i+'" class="form-control" value="nopic.png"><span class="input-group-btn"><button class="btn btn-primary m-b-5 m-t-5" type="button" onClick="showUpload(\'picpic1_'+i+'\',\'../media\');">上传</button></span></div><button class="btn btn-danger btn-sm" type="button" onclick="DelPic('+i+')">- 删除该图</button></div></div>';
}

function DelPic(i){
  var Container = document.getElementById("pic1");    
    var _tr=document.getElementById("pp"+i);  
    row=_tr.rowIndex;
    Container.deleteRow(row); 
}
function clearall(){
  $("#card_table").html("");
}
$(function() { $('.buy label').click(function(){var aa = $(this).attr('aa');$('[aa="'+aa+'"]').removeAttr('class') ;$(this).attr('class','checked');});});
var S_sount=<?php echo $S_count?>;
if(S_sount==0){
    $.alert({
        title: '无商品分类',
        content: '请先新增商品分类',
    buttons: {
      confirm: {
        text: '确认',
        btnClass: 'btn-primary',
        action: function(){
          window.location.href="psort.php";
        }
      },
      cancel: {
        text: '取消',
        action: function () {
            window.location.href="psort.php";
        }
      }
    }
    });
}
function product_add_get(){
  $.ajax({
    url:'?action=get&id='+$("#P_from").val(),
    type:'get',
    success:function(data) {
        data = JSON.parse(data);
        if(data.msg=="success"){
          $("[name='P_title']").val(data.P_title);
          $("[name='P_pic']").val(data.P_pic);
          $("#P_picx").attr("src","../media/"+data.P_pic);
          $("[name='P_content']").val(data.P_content);
          $("[name='P_use']").val(data.P_use);
          var $a="";
          $pic=data.P_piccontent.split("|");
          
          for(var $i=0;$i<$pic.length;$i++){
              if($pic[$i]!=""){
                $a=$a+"<tr id=\"pp"+$i+"\"><td><div class=\"row\"><div class=\"col-md-3\"><img src=\"../media/"+$pic[$i]+"\" id=\"picpic1_"+$i+"x\" class=\"showpic\" onClick=\"showUpload('picpic1_"+$i+"','../media');\" alt=\"<img src='../media/"+$pic[$i]+"' class='showpicx'>\"></div><div class=\"col-md-9\"><div class=\"input-group\"><input type=\"text\" id=\"picpic1_"+$i+"\" name=\"picpic1_"+$i+"\" class=\"form-control\" value=\""+$pic[$i]+"\"><span class=\"input-group-btn\"><button class=\"btn btn-primary m-b-5 m-t-5\" type=\"button\" onClick=\"showUpload('picpic1_"+$i+"','../media');\">上传</button></span></div><button class=\"btn btn-danger btn-sm\" type=\"button\" onclick=\"DelPic("+$i+")\">- 删除该图</button></div></div></td></tr>"
              }
          }
          $("#pic1").html($a);
          lightyear.notify('获取成功！', 'success', 100);
        }else{
          lightyear.notify(data.msg, 'danger', 100);
        }
    }
  });
}
function product_add_abutment(i){
  if(i==0){
    $(".f1").show();
    $(".f2").hide();
  }
  if(i>0){
    $(".f1").hide();
    $(".f2").show();
  }
}

product_add_show(<?php echo $P_selltype;?>);
product_add_abutment(<?php echo $P_from;?>);
      Date.prototype.format = function (fmt) {
          var o = {
              "M+": this.getMonth() + 1, //月份
              "d+": this.getDate(), //日
              "h+": this.getHours(), //小时
              "m+": this.getMinutes(), //分
              "s+": this.getSeconds(), //秒
              "q+": Math.floor((this.getMonth() + 3) / 3), //季度
              "S": this.getMilliseconds() //毫秒
          };
          if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
          for (var k in o)
              if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
          return fmt;
      }
</script>
</body>
</html>