<?php
	include_once("../config.php");
	$sql = "select id,name from danwei where status=1";
	$requs=mysqli_query($con,$sql);
?>
<!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, maximum-scale=1">
    <link rel="stylesheet" href="../lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="../css/public.css" media="all">
	<style type="text/css">
		#delimg{color:#f00;width:20px;height:20px;font-size:20px;border:1px solid #f00;border-radius:10px;}
	</style>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
	<form class="layui-form" action="" id="addxzxform" lay-filter="example">
			<div class="layui-form-item">
				<label for="username" class="layui-form-label">
					<span class="x-red">*</span>选择耗材</label>
				<div class="layui-input-inline">
					<input type="text" id="sear" name="sear" readonly autocomplete="off" class="layui-input">
				</div>
			</div>
			<input type="hidden" id="hc" name="hc" />
			<div class="layui-form-item">
				<label for="username" class="layui-form-label">
					<span class="x-red">*</span>选择单位</label>
				<div class="layui-input-inline">
					<select name="dw" id="dw">
						<option value="0" selected="">选择单位</option>
						<?php
						while($rss=mysqli_fetch_array($requs)){
							echo '<option value="'.$rss['name'].'">'.$rss['name'].'</option>';
						}
						?>
					</select>
				</div>
			</div>
	
		<div class="layui-form-item">
			<div class="layui-inline">
				<label class="layui-form-label"><span class="x-red">*</span>领用人</label>
				<div class="layui-input-inline">
					<input type="text" name="lyr" lay-verify="required" autocomplete="off" class="layui-input">
				</div>
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-inline">
				<label class="layui-form-label">领用数量</label>
				<div class="layui-input-inline">
					<input type="text" name="num" value="1" lay-verify="number" autocomplete="off" class="layui-input">
				</div>
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-input-block">
				<button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
				<button type="reset" class="layui-btn layui-btn-primary">重置</button>
			</div>
		</div>
	</form>
    </div>
</div>
<script src="../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="../js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script>
    layui.use(['table', 'form', 'tableSelect'], function () {

        var $ = layui.jquery,
            table = layui.table,
            form = layui.form,
			layer = layui.layer,
            tableSelect = layui.tableSelect;
			
        tableSelect.render({
            elem: '#sear',
            checkedKey: 'selectid',
            table: {
                url: '../action.php?mode=gethaocailist&fun=chuku',
                cols: [[
					{type: 'radio' },
                    {field: 'id', width: 80, title: 'ID', sort: true, align: "center"},
					{field: 'name', width: 200, title: '名称', align: "center"},
					{field: 'pp', width: 200, title: '品牌', align: "center"},
					{field: 'gg', width: 200, title: '规格型号', align: "center"},
					{field: 'num', width: 100, title: '剩余数量', align: "center"},
					{field: 'dj', width: 100, title: '单价', align: "center"},
					{field: 'zs', width: 100, title: '入库数量', align: "center"},
					{field: 'rksj', width: 220, title: '入库时间', sort: true, align: "center"}
                ]]
            },
            done: function (elem, data) {
                var NEWJSON = []
                layui.each(data.data, function (index, item) {
                    NEWJSON.push(item.name);
					$("#hc").val(item.id);
                })
                elem.val(NEWJSON.join(","))
            }
        })

        form.on('submit(demo1)', function (data) {
			var d = JSON.stringify(data.field);
			d=d.replace(/\'/g,"’");
			$.post("../action.php?mode=haocaichuku",{data:d},function(result){
				console.log(result);
				var r = JSON.parse(result);
				if(r.status==1){
					var index = layer.alert('出库成功',function () {
						$("#addxzxform")[0].reset();
                        layui.form.render();
						layer.close(index);
					});
				}else{
					layer.alert(r.msg);
				}
			});
            return false;
        });
		
	  form.on('select(changeleibie)', function(data){
		console.log(data);
	  });
    });
</script>

</body>
</html>