<?php
    include_once("../config.php");

	session_start();
	if(!isset($_SESSION['admin'])){
		header("location:/page/login.php");
		die();
	}

    include_once("jssdk.php");
    $jssdk = new JSSDK($appId, $appSecret);
    $sp = $jssdk->GetSignPackage();

?>
<!DOCTYPE html>
<html lang="zh-CN">
	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width, initial-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>
        <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',
        			'scanQRCode'
        		]
        	});
        
        	wx.ready(function () {
        		document.querySelector('#chooseImage').onclick = function () {
        			wx.scanQRCode({
        			  needResult: 1, // 默认为0，扫描结果由微信处理，1则直接返回扫描结果，
        			  scanType: ["qrCode","barCode"], // 可以指定扫二维码还是一维码，默认二者都有
        			  success: function (res) {
        				var result = res.resultStr; // 当needResult 为 1 时，扫码返回的结果
        			    var r=JSON.stringify(res);
        				//alert(r);
        				result = result.replace("CODE_128,","");
        				result = result.replace("CODE_25,","");
        				result = result.replace("EAN_13,","");
        				result = result.replace("UPC_E,","");
        				//alert(result);
        				$.post("../action.php",{mode:"wxscancha",code:result},function(res){
        					var r = JSON.parse(res);
        					if(r.id!=0){
        					    window.location.href="/page/editxxzichan.php?id=" + r.id
        					}else{
        					    //document.querySelector('#mdiv').innerText = "无效码";
        					    alert("无效码");
        					}
        					//document.querySelector('#mdiv').innerText = res;
        			    })
        				//document.querySelector('#mdiv').innerText = result;
        			  }
        			});
        		};
        	});
        </script>
</head>
<body style="margin:0;padding:0;width:100vw;height:100vh;">
    <div style="font-size:40px;width:100%;text-align:center;margin-top:40%;">
        <a href="#" id="chooseImage" style="text-decoration:none;">查询&修改</a>
        <br><br>
        <a href="add.php" style="text-decoration:none;">录入</a>
    </div>
<br><br>
        <input type="text" name="ssint" id="ssint" style="margin-left:5px;color:#678;width:70%;height:26px;background-color:#ccc;font-size:18px;line-height:26px;" />
        <div id="searc" style="border:1px solid #888;float:right;background-color:#1296db;color:#fff;font-size:21px;height:28px;line-height:28px;margin-right:5px;">模糊搜索</div>
<script type="text/javascript">
    $("#searc").click(function(){
        var mh=$("#ssint").val();
		$.post("../action.php",{mode:"wxmhscancha",code:mh},function(res){
			var r = JSON.parse(res);
			if(r.id!=0){
			    window.location.href="/page/editxxzichan.php?id=" + r.id
			}else{
			    document.querySelector('#mdiv').innerText = "无效码";
			}
			//document.querySelector('#mdiv').innerText = res;
	    })
    });
</script>
</body>
</html>