<?php
	session_start();
	if(!isset($_SESSION['admin'])){
		header("location:/page/login.php");
		die();
	}
?>
<?php
include_once("jssdk.php");
include_once("../config.php");
$appId='wxa9ede96755f3575c';
$appSecret='f01307340605639e7024c380c4a23273';
$jssdk = new JSSDK($appId, $appSecret);
$sp = $jssdk->GetSignPackage();
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
	<meta charset="utf-8">
	<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">
	<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">
	<title>添加资产-文登税务资产管理系统</title>
	<script src="https://res2.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
	<script src="/lib/jquery-3.4.1/jquery-3.4.1.min.js"></script>
	<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>
	
	<script type="text/javascript">
		wx.config({
			debug: false,
			appId: '<?php echo $sp["appId"];?>',
			timestamp: <?php echo $sp["timestamp"];?>,
			nonceStr: '<?php echo $sp["nonceStr"];?>',
			signature: '<?php echo $sp["signature"];?>',
			jsApiList: [
				'checkJsApi',
				'chooseImage',
				'uploadImage',
				'previewImage',
				'scanQRCode'
			]
		});

		wx.ready(function () {
			document.querySelector('#scanxlh').onclick = function () {
				wx.scanQRCode({
				  needResult: 1, // 默认为0，扫描结果由微信处理，1则直接返回扫描结果，
				  scanType: ["qrCode","barCode"], // 可以指定扫二维码还是一维码，默认二者都有
				  success: function (res) {
					var result = res.resultStr; // 当needResult 为 1 时，扫码返回的结果
					result = result.replace("CODE_128,","");
					result = result.replace("CODE_25,","");
					result = result.replace("EAN_13,","");
					result = result.replace("UPC_E,","");
					$("#xlh").val(result);
				  }
				});
			};
			document.querySelector('#upzcimg').onclick = function () {
                wx.chooseImage({
                  count: 1, // 默认9
                  sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
                  sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
                  success: function (res) {
                  var localIds = res.localIds; // 
                  //alert(localIds);
                    wx.uploadImage({
                      localId: localIds.toString(), // 需要上传的图片的本地ID，由chooseImage接口获得
                      isShowProgressTips: 1, // 默认为1，显示进度提示
                      success: function (res) {
                        var serverId = res.serverId; // 返回图片的服务器端ID
                        //alert(serverId);
                        $("#img").val(serverId);
                        $("#zcimg").attr("src",localIds);
                        $("#imgdiv").show();
                      }
                    });
                  }
                });
			    
			    
			};
		});
		

		
		
	</script>
</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">
			<div class="layui-inline">
				<label class="layui-form-label">资产类型*</label>
				<div class="layui-input-inline">
					<select name="zclx" lay-verify="required" lay-search="" lay-filter="changeleibie">
						<?php
							$sql = "select id,name from zclx where status=1 and zcfl=1";
							$requ = mysqli_query($con,$sql);
							while($rs = mysqli_fetch_array($requ)){
								echo '<option value="'.$rs['id'].'">'.$rs['name'].'</option>';
							}
						?>
					</select>
				</div>
			</div>
			<div class="layui-inline">
				<label class="layui-form-label">资产状态*</label>
				<div class="layui-input-inline">
					<select name="zczt" lay-verify="required" lay-search="">
						<?php
							$sql = "select id,name from zhuangtai where status=1";
							$requ = mysqli_query($con,$sql);
							while($rs = mysqli_fetch_array($requ)){
								echo '<option value="'.$rs['id'].'">'.$rs['name'].'</option>';
							}
						?>
					</select>
				</div>
			</div>
			<div class="layui-inline">
				<label class="layui-form-label">财务资产名</label>
				<div class="layui-input-inline">
					<input type="text" name="cw" 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="zcbh" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-inline">
				<label class="layui-form-label" id="scanxlh">序列号*<i class="layui-icon layui-icon-camera" style="font-size: 25px;color:#1E9FFF;margin-left:5px;"></i></label>
				<div class="layui-input-inline">
					<input type="text" name="xlh" id="xlh" lay-verify="required" 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="bgr" lay-verify="required" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-inline">
				<label class="layui-form-label">单位*</label>
				<div class="layui-input-inline">
					<select name="bm" lay-verify="required" lay-search="">
						<?php
							$sql = "select id,name from danwei where status=1";
							$requ = mysqli_query($con,$sql);
							while($rs = mysqli_fetch_array($requ)){
								echo '<option value="'.$rs['id'].'">'.$rs['name'].'</option>';
							}
						?>
					</select>
				</div>
			</div>
			<div class="layui-inline">
				<label class="layui-form-label">地址*</label>
				<div class="layui-input-inline">
					<input type="text" name="dz" 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="cgsj" id="cgsj" value="<?php echo date("Y-m-d",time()); ?>" lay-verify="date" 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="rzsj" id="rzsj" value="<?php echo date("Y-m-d",time()); ?>" lay-verify="date" 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="number" name="zbsc" value="0" 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="number" name="sysc" value="0" lay-verify="number" 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="pp" lay-verify="required" 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="xh" autocomplete="off" class="layui-input">
				</div>
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">规格</label>
			<div class="layui-input-block">
				<input type="text" name="gg" autocomplete="off" class="layui-input">
			</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="zcly" value="自购" 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="zcjz" value="0.00" lay-verify="huobi" autocomplete="off" class="layui-input">
				</div>
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">备注</label>
			<div class="layui-input-block">
				<input type="text" name="bz" autocomplete="off" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">资产图片</label>
			<button type="button" class="layui-btn layui-btn-normal" id="upzcimg">上传图片</button>
			<input type="hidden" name="img" id="img" class="layui-input">
		</div>
		
		<div class="layui-form-item" style="display:none;" id="imgdiv">
			<label class="layui-form-label">图片预览</label>
			<img style="width:100px;height:60px;" id="zcimg">
			<i class="layui-icon layui-icon-close" title="删除图片" id="delimg"></i>
		</div>
		
		<div class="layui-form-item" id="wlxx">
			<div class="layui-inline">
				<label class="layui-form-label">网络标识</label>
				<div class="layui-input-inline">
					<select name="wlbs" lay-verify="required" lay-search="">
						<option value="0" selected="">未分配</option>
						<option value="1">内网</option>
						<option value="2">外网</option>
					</select>
				</div>
			</div>
			<div class="layui-inline">
				<label class="layui-form-label">IP地址</label>
				<div class="layui-input-inline">
					<input type="text" name="ip" autocomplete="off" class="layui-input">
				</div>
			</div>
		</div>
		<div class="layui-form-item" id="dnpz">
			<div class="layui-inline">
				<label class="layui-form-label">显示器</label>
				<div class="layui-input-inline">
					<input type="text" name="xsq" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-inline">
				<label class="layui-form-label">硬盘(G)</label>
				<div class="layui-input-inline">
					<input type="number" name="yp" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-inline">
				<label class="layui-form-label">内存(G)</label>
				<div class="layui-input-inline">
					<input type="number" name="nc" 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>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
    layui.use(['form', 'laydate'], function () {
        var form = layui.form
            , layer = layui.layer
            , laydate = layui.laydate
			//, upload = layui.upload
			, $ = layui.$;

        laydate.render({
            elem: '#cgsj'
        });
        laydate.render({
            elem: '#rzsj'
        });

        form.verify({
            huobi: [
                /^(([1-9]\d*)|0)(\.\d{1,2})?$/
                , '请正确输入资产价值'
            ]
        });
		

		
		$("#zcimg").click(function(){
			var t = $(this).attr("src");
			layer.open({
				type: 1,
				title: false,
				closeBtn: 0,
				area: '300px',
				skin: 'layui-layer-nobg',
				shadeClose: true,
				content: '<img style="display: inline-block; width: 100%; height: 100%;" src="'+t+'">'
			});
		})
		
		$("#delimg").click(function(){
			var t = $("#img").val();
			t = t.replace(/\/uploads\//,"");
			console.log(t);
			$("#zcimg").attr("src","");
			$("#img").val('');
			$("#imgdiv").hide();
		});
		
		/*
		  var uploadInst = upload.render({
			elem: '#upzcimg'
			,url: '../upload.php'
			,done: function(res){
				//var r = JSON.stringify(res[0]);
				//console.log(r);
				if(res[0].status==1){
					//location.reload();
					$("#zcimg").attr("src","/uploads/" + res[0].file);
					$("#img").val("/uploads/" + res[0].file);
					$("#imgdiv").show();
				}else{
					layer.alert(res[0].msg);
				}
			}
			,error: function(){

			}
		  });
		*/

        form.on('submit(demo1)', function (data) {
			var d = JSON.stringify(data.field);
			d=d.replace(/\'/g,"’");
			$.post("./action.php",{data:d},function(result){
				//alert(result);
				var r = JSON.parse(result);
				if(r.status==1){
					var index = layer.alert('添加成功',function () {
						layer.close(index);
						$("#zcimg").attr("src","");
						$("#img").val('');
						$("#imgdiv").hide();
					});
				}else{
					layer.alert(r.msg);
				}
			});
            return false;
        });
		
	  form.on('select(changeleibie)', function(data){
		console.log(data);
	  });

    });
</script>

</body>
</html>