<?php include_once 'init-lite.php'; 
?>
<script type="text/javascript">
  function updateCfg(var1){
	//var SQL_CategoryID =encodeURIComponent($("#CategoryID"+var1).val());
	var CategoryID =encodeURIComponent($("#CategoryID"+var1).val());
	var SQL_UserCode =encodeURIComponent($("#UserCode"+var1).val());
	var SQL_ProductName =encodeURIComponent($("#ProductName"+var1).val());
	var SQL_UnitPrice =$("#UnitPrice"+var1).val();
	var limitQty=new Number($("#limitQty"+var1).val());
	var Step=new Number($("#Step"+var1).val());
//alert ("_dc="+new Date().getTime()+"&UserCode=" + SQL_UserCode+"&ProductName=" + SQL_ProductName+"&UnitPrice=" + SQL_UnitPrice+ SQL_UnitPrice+"&limitQty=" + limitQty +"&Step=" + Step);

 	$.ajax({
		type: "POST", //提交的类型
		url: "admin-menu-save.php",//提交地址
		data: "_dc="+new Date().getTime()+"&CategoryID=" + CategoryID+"&UserCode=" + SQL_UserCode+"&ProductName=" + SQL_ProductName+"&UnitPrice=" + SQL_UnitPrice+ SQL_UnitPrice+"&limitQty=" + limitQty +"&Step=" + Step,//参数
		success: function(data){ //回调方法
			$("#myDiv").html(data);
		}
	});
  }
 </script>


<form class="ui-filterable">
      <input id="myFilter" placeholder="根据名称搜索"  data-type="search" data-clear-btn="true">
    </form>
    <span id="myDiv"></span>
  <table data-role="table" id="myTable"  data-mode="columntoggle" class="ui-responsive table-stroke" data-filter="true" data-input="#myFilter" data-autodividers="true" data-column-btn-text="列" >
      <tbody>
<?php
$sql = "SELECT Products.UserCode,Products.ProductName,Products.ProductName2,UnitPrice,Products.CategoryID,Step,limitQty,CategoryName  FROM Products LEFT OUTER JOIN Categories  ON Categories.CategoryID = Products.CategoryID";
if (!empty($_POST['CategoryID']) && strlen($_POST['CategoryID'])>0) 
			$sql .= " where Products.CategoryID=".$_POST['CategoryID'];    
$sql .= " order by Products.CategoryID,Products.UnitsOnOrder,LEN(Products.UserCode),Products.UserCode";  

$values = $orders->query($sql);
if (is_iterable($values)){
  foreach ($values as $pProductsAddMenu){ 
$Line1++; 
$pProductsAddMenu['UserCode']=loadFromMssql($pProductsAddMenu['UserCode']);
$pProductsAddMenu['ProductName']=loadFromMssql($pProductsAddMenu['ProductName']);
$pProductsAddMenu['ProductName2']=loadFromMssql($pProductsAddMenu['ProductName2']);
$pProductsAddMenu['CategoryName']=loadFromMssql($pProductsAddMenu['CategoryName']);
//$pProductsAddMenu['limitQty']=loadFromMssql($pProductsAddMenu['limitQty']);

 if ($pProductsAddMenu['limitQty']=='') 
 	$pProductsAddMenulimitQty=-1;
	else
	$pProductsAddMenulimitQty=$pProductsAddMenu['limitQty'];
?>                         
<tr>
<td>
菜号
<input name="ProductName<?php echo $Line1; ?>" type="text" id="ProductName<?php echo $Line1; ?>" value="<?php echo $pProductsAddMenu['ProductName']; ?>" size="25"/>
<span style='color:red;display: none;'><?php echo $pProductsAddMenu['ProductName']?></span>

类别:
<?php echo $pProductsAddMenu['CategoryName']; ?>
<input name="CategoryID<?php echo $Line1; ?>" type="text" id="CategoryID<?php echo $Line1; ?>" value="<?php echo $pProductsAddMenu['CategoryID']; ?>" size="1"/>
菜号<input name="UserCode<?php echo $Line1; ?>" type="text" id="UserCode<?php echo $Line1; ?>" value="<?php echo $pProductsAddMenu['UserCode']; ?>" size="3"/>
价格<label for="number-1">价格</label>
<input name="UnitPrice<?php echo $Line1; ?>" type="number" data-clear-btn="false" id="UnitPrice<?php echo $Line1; ?>" value="<?php echo $pProductsAddMenu['UnitPrice']; ?>" size="5"/>


<label for="slider">库存（-1表示不限量供应）<?php if ($pProductsAddMenulimitQty==0) echo "<b><span style='color:red; text-align:center ;'>已售罄！</span></b>";else if ($pProductsAddMenulimitQty==-1) echo "<b><span style='color:green; text-align:center ;'>不限量供应</span></b>";?></label>
<input type="range" name="limitQty<?php echo $Line1; ?>" id="limitQty<?php echo $Line1; ?>" value="<?php echo $pProductsAddMenulimitQty; ?>" min="-1" max="900">
<label for="slider-fill">最小数量</label>
<input type="range" name="Step<?php echo $Line1; ?>" id="Step<?php echo $Line1; ?>" value="<?php echo $pProductsAddMenu['Step']; ?>" min="0.5" max="5" step="0.5" data-highlight="true">

<button type="button" class="ui-btn ui-btn-inline" onclick="updateCfg(<?php echo $Line1; ?>);">保存</button></td>
</tr> <?php } } ?>
      </tbody>
    </table>
    
    