<!DOCTYPE html>

<html>

<head>
<meta charset="utf-8">
<title>日志管理</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
<link rel="stylesheet"
	href="<?= RESOURCES ?>/layuiadmin/layuiadmin/layui/css/layui.css" media="all">
<link rel="stylesheet"
	href="<?= RESOURCES ?>/layuiadmin/layuiadmin/style/admin.css" media="all">
</head>

<body>
	<div class="layui-fluid">
		<div class="layui-row layui-col">
			<div class="layui-col-md12">
				<div class="layui-card">

					<div
						class="layui-form layui-card-header layuiadmin-card-header-auto">
						<div class="layui-form-item">

							<div class="layui-inline">
								<label class="layui-form-label">默认价格</label>
								<div class="layui-input-inline">
									<input type="text" name="goods_price" id="goods_price"
										value="0" placeholder="请输入价格" lay-verify="number" autocomplete="off"
										class="layui-input">
								</div>
							</div>
							<div class="layui-inline">
								<label class="layui-form-label">默认库存</label>
								<div class="layui-input-inline">
									<input type="text" name="goods_stock" id="goods_stock" value="0"
										placeholder="请输入库存" lay-verify="number"  autocomplete="off" class="layui-input">
								</div>
							</div>
							<div class="layui-inline" style="display:none">
								<label class="layui-form-label">商品规格</label>
								<div class="layui-input-inline">
									<input type="text" name="goods_number" id="goods_number"
										value="<?=$goods_number?>" autocomplete="off"
										class="layui-input">
								</div>
							</div>
							<div class="layui-inline">
								<button class="layui-btn layui-btn-sm layui-btn-normal layuiadmin-btn-list" lay-submit=""
									lay-filter="LAY-app-contlist-search">
									<i class="layui-icon layui-icon-refresh layuiadmin-button-btn">生成</i>
								</button>
							</div>

						</div>
					</div>
					<!--<div class="layui-card-header">操作日志</div>-->
					<div class="layui-card-body">
						<table class="layui-hide" id="test-table-operate"
							lay-filter="test-table-operate"></table>
					</div>
				</div>
			</div>
		</div>
	</div>

	<script src="<?= RESOURCES ?>/layuiadmin/layuiadmin/layui/layui.js"></script>
	<script>
			layui.config({
				base: '<?= RESOURCES ?>/layuiadmin/layuiadmin/' //静态资源所在路径
			}).extend({
				index: 'lib/index' //主入口模块
			}).use(['index', 'form', 'table'], function() {
				var $ = layui.$,
					table = layui.table,
					form = layui.form,
					admin = layui.admin;

				form.render(null, 'component-form-group');
				
				table.render({
					elem: '#test-table-operate',
					url: '/<?= ADMIN_NAME ?>/inc/getgoodspricelist?goods_number=<?=$goods_number?>',
					cellMinWidth: 80, //全局定义常规单元格的最小宽度，layui 2.2.1 新增
					height: '400',
					cols: [
						[{
								field: 'id',
								width: 80,
								title: 'ID',
								sort: true,
								fixed: 'left'
							}, {
								field: 'goodsparameter_names',
								width: 250,
								title: '商品规格'
							}, {
								field: 'goods_stock',
								width: 120,
								title: '商品库存',
								edit: 'text'
							}, {
								field: 'goods_price',
								width: 120,
								title: '商品价格',
								edit: 'text'
							}

						]
					],
					page: true,
					limit: 20,
				});

				//监听表格复选框选择
				table.on('checkbox(test-table-operate)', function(obj) {
					console.log(obj)
				});
				//监听刷新按钮
				table.on('tool(test-table-operate)', function(obj) {
					var data = obj.data;
					if(obj.event === 'del') {
						layer.confirm('真的删除么', function(index) {
							layer.close(index);
							var id = data.id;
							window.location.href="/<?= ADMIN_NAME ?>/group/delete?id="+id;
						});
					} else if(obj.event === 'edit') {
						var id = data.id;
						layOpen("修改用户组权限","/<?= ADMIN_NAME ?>/group/edit?id="+id);
						
					}
				});
				
				
				
				//监听单元格编辑
			    table.on('edit(test-table-operate)', function(obj){
			      var value = obj.value //得到修改后的值
			      ,data = obj.data //得到所在行所有键值
			      ,field = obj.field; //得到字段
			       
			      var postData = {"id":data.id,"field":field,"value":value};
			      myAjax("/<?= ADMIN_NAME ?>/inc/updategoodspriceByid",  "post", postData)
			       
			      
			    });
				
				
			    /* 监听提交 */
			    
			    form.on('submit(LAY-app-contlist-search)', function(data){
			      var field = data.field;
			      //refresh_goods_price('<?=$goods_number?>');
			      layer.confirm('重现生成价格会清空原来的价格记录，且不可恢复，确认重新生成？', function(index) {
						$.ajax({          
							  url: "/<?= ADMIN_NAME ?>/inc/refreshgoodspricelist",
					          type: "get",
					          data: field,
					          dataType: 'JSON',
				          success: function(data) {            
							if(data.status) {              
								parent.layer.msg(data.msg, {
									icon: 6,
									time: 1000
								}); //添加成功后提示
								            
								//location.reload() //刷父界面
								//执行重载
							    table.reload('test-table-operate', {
							        
							    });
								            
							} else {              
								parent.layer.msg(data.msg, {
									icon: 5,
									time: 1000
								});            
							}          
						}
						})
						layer.close(index);
					});
			      
			      
			    });
			    
				 


			});
		</script>

</body>

</html>