<?php include_once(mvc::$cfg['PATH_TPL'].'public/headBase.php');?>
<div class="marauto marlists">
	<div class="searchParam">
		<form method="get" id="sform">
			<b>VIN：</b><textarea name="viz_vin" class="form-control textrow input-any-row" rows="1" cols="23" placeholder="多个用;分割或者换行"><?php echo !empty($_POST['viz_vin']) ? $_POST['viz_vin']: $Params['viz_vin'];?></textarea>&nbsp;&nbsp;&nbsp;
			<b>工信部：</b><textarea name="viz_gxb_code" class="form-control textrow input-any-row" rows="1" cols="20" placeholder="多个用;分割或者换行"><?php echo $Params['viz_gxb_code'];?></textarea>&nbsp;&nbsp;&nbsp;
			<b>品牌：</b><input type="text" class="form-control" name="viz_brand" value="<?php echo $Params['viz_brand'];?>" size="10">&nbsp;&nbsp;&nbsp;
			<b>发动机：</b><input type="text" class="form-control" name="viz_engine" value="<?php echo $Params['viz_engine'];?>" size="12">&nbsp;&nbsp;&nbsp;
			<b>尺寸：</b><input type="text" name="viz_length" placeholder="长" title="支持粘贴：5012*1855*1485" class="form-control sizetxt" value="<?php echo $Params['viz_length'];?>">
			*
			<input type="text" name="viz_width" placeholder="宽" class="form-control sizetxt" value="<?php echo $Params['viz_width'];?>">
			*
			<input type="text" name="viz_height" placeholder="高" class="form-control sizetxt" value="<?php echo $Params['viz_height'];?>">
			<a href="javascript:;" onclick="$('.sizetxt').val('')" class="a_blue">清</a>&nbsp;&nbsp;&nbsp;
			<input type="text" name="viz_wheel" placeholder="轴距" class="form-control" style="width: 45px;" value="<?php echo $Params['viz_wheel'];?>">
			&nbsp;&nbsp;&nbsp;
			<button type="submit" class="btn btn-primary"> 查 询 </button>&nbsp;&nbsp;&nbsp;
			<button type="button" class="btn btn-info" onclick="showZdApiCatchBox()">采集VIN</button>&nbsp;&nbsp;&nbsp;
			<span>剩余<b><?=$zdtotal?></b>条</span>
		</form>
	</div>
	<?php if(!empty($vinArr)){?>
	<table class="table table-bordered YpTable">
		<thead class="Filter Sortable">
			<tr>
				<th width="160px" class="Sort"><span>VIN</span></th></th>
				<th width="90px" class="Sort"><span>V1-8</span></th>
				<th width="50px" class="Sort"><span>10</span></th>
				<th width="50px" class="Sort"><span>11</span></th>
				<th width="60px" class="Sort"><span>12-17</span></th>
				<th width="120px" class="Sort"><span>品牌</span></th>
				<th width="120px" class="Sort"><span>车系</span></th>
				<th width="150px" class="Sort"><span>工信部</span></th>
				<th width="100px" class="Sort"><span>发动机</span></th>
				<th width="50px" class="Sort" sort="float"><span>功率</span></th>
				<th width="50px" class="Sort" sort="float"><span>排量</span></th>
				<th width="50px" class="Sort" sort="float"><span>长</span></th>
				<th width="50px" class="Sort" sort="float"><span>宽</span></th>
				<th width="50px" class="Sort" sort="float"><span>高</span></th>
				<th width="50px" class="Sort" sort="float"><span>轴距</span></th>
				<th width="50px" class="Sort" sort="float"><span>整备</span></th>
				<th width="50px" class="Sort" sort="float"><span>载客</span></th>
				<th width="100px" class="Sort"><span>类型</span></th>
				<th width="80px" class="Sort"><span>制造</span></th>
				<th width="100px" class="Sort"><span>轮胎</span></th>
				<th width="80px" class="Sort"><span>车速</span></th>
				<th width="" class="Sort"><span>排放</span></th>
				<th width="" class="Sort"><span>备注</span></th>
			</tr>
			<tr>
				<td><input type="text" class="FilterTxt form-control" style="width:140px"></td>
				<td><input type="text" class="FilterTxt form-control" style="width:60px"></td>
				<td><input type="text" class="FilterTxt form-control" style="width:30px"></td>
				<td><input type="text" class="FilterTxt form-control" style="width:30px"></td>
				<td><input type="text" class="FilterTxt form-control" style="width:40px"></td>
				<td><input type="text" class="FilterTxt form-control" style="width:100px"></td>
				<td><input type="text" class="FilterTxt form-control" style="width:100px"></td>
				<td><input type="text" class="FilterTxt form-control" style="width:30px"></td>
				<td><input type="text" class="FilterTxt form-control" style="width:40px"></td>
				<td><input type="text" class="FilterTxt form-control" style="width:40px"></td>
				<td><input type="text" class="FilterTxt form-control" style="width:40px"></td>
				<td><input type="text" class="FilterTxt form-control" style="width:30px"></td>
				<td><input type="text" class="FilterTxt form-control" style="width:30px"></td>
				<td><input type="text" class="FilterTxt form-control" style="width:30px"></td>
				<td><input type="text" class="FilterTxt form-control" style="width:30px"></td>
				<td><input type="text" class="FilterTxt form-control" style="width:30px"></td>
				<td><input type="text" class="FilterTxt form-control" style="width:30px"></td>
				<td><input type="text" class="FilterTxt form-control" style="width:50px"></td>
				<td><input type="text" class="FilterTxt form-control" style="width:50px"></td>
				<td><input type="text" class="FilterTxt form-control" style="width:50px"></td>
				<td><input type="text" class="FilterTxt form-control" style="width:50px"></td>
				<td><input type="text" class="FilterTxt form-control" style="width:50px"></td>
				<td><input type="text" class="FilterTxt form-control" style="width:50px"></td>
			</tr>
		</thead>
		<tbody>
			<?php foreach($vinArr as $v){?>
			<tr>
				<td><a href="<?php echo mvc::$cfg['ADMIN_URI'];?>ypcCar/standModelAnyAdd?smaId=<?php echo $v['sma_id']?>" target="_blank" ><?php echo $v['viz_vin'];?></a></td>
				<td><?php echo $v['viz_vin1_8'];?></td>
				<td><?php echo substr($v['viz_vin'], 9, 1);?></td>
				<td><?php echo substr($v['viz_vin'], 10, 1);?></td>
				<td><?php echo substr($v['viz_vin'], 11);?></td>
				<td><?php echo $v['viz_brand'];?></td>
				<td><?php echo $v['viz_mod1'];?></td>
				<td><?php echo $v['viz_gxb_code_show'];?></td>
				<td><?php echo $v['viz_engine'];?></td>
				<td><?php echo $v['viz_kw'];?></td>
				<td><?php echo $v['viz_cc'];?></td>
				<td><?php echo $v['viz_length'] > 0 ? $v['viz_length'] : '';?></td>
				<td><?php echo $v['viz_width'] > 0 ? $v['viz_width'] : '';?></td>
				<td><?php echo $v['viz_height'] > 0 ? $v['viz_height'] : '';?></td>
				<td><?php echo $v['viz_wheel'] > 0 ? $v['viz_wheel'] : '';?></td>
				<td><?php echo $v['viz_weight'] > 0 ? $v['viz_weight'] : '';?></td>
				<td><?php echo $v['viz_passenger'] > 0 ? $v['viz_passenger'] : '';?></td>
				<td><?php echo $v['viz_vtype'];?></td>
				<td><?php echo $v['viz_year'];?></td>
				<td><?php echo $v['viz_ltgg'];?></td>
				<td><?php echo $v['viz_zgcs'];?></td>
				<td><?php echo $v['viz_pfbz'];?></td>
				<td><div style="overflow-y:scroll;max-height:36px;"><?php echo $v['viz_json']['BZ'];?></div></td>
			</tr>
			<?php }?>
		</tbody>
	</table>
	 <?php if($hidePage){?>
		<div class="page-box"><div class="page-all">共<b><?php echo count($vinArr);?></b>条记录</div></div>
	 <?php }else{ echo $Page;}?>
	<?php }?>
</div>
<?php include_once(mvc::$cfg['PATH_TPL'].'public/footBase.php');?>
<script type="text/javascript">
$(document).ready(function(){
	$('.sizetxt').change(function(){
		var $this = $(this);
		var sizeArr = $this.val().replace(/[\*\-\x\X\×\t]/g, '*').replace(/^\*{1,}/g, '').split('*');
		if(sizeArr.length >= 3){
			$('.sizetxt').each(function(i, e){
				$(this).val($.trim(sizeArr[i]));
			})
		}
	});

	$('#sform [type="submit"]').click(function(){
		var valArr = $.trim($('[name="viz_vin"]').val()).replace(/[\,，\;\；]/g, "\n").split("\n");
		var realArr = new Array();
		for(var i in valArr)
		{
			var val = $.trim(valArr[i]);
			if(val != '' && $.inArray(val, realArr) === -1) realArr.push(val);
		}
		if(realArr.length >= 2)
			$('#sform').attr('method', 'post');
		else
			$('#sform').attr('method', 'get');
	});
});

function showZdApiCatchBox()
{
	var tpl = '<textarea id="catchvins" class="form-control input-any-row" rows="20" cols="50" placeholder="多个用;分割或者换行"></textarea><div class="txtcount"></div><div class="mart5">过滤：<span class="filterjs" data-val="2">1/2</span><span class="filterjs" data-val="3">1/3</span><span class="filterjs" data-val="5">1/5</span><span class="filterjs" data-val="8">1/8</span><span class="filterjs" data-val="10">1/10</span><span class="filterjs" data-val="15">1/15</span><span class="filterjs" data-val="20">1/25</span></div><div class="mart5">采集方式：<lable><input type="radio" name="cattype" value="shishi" checked/>实时</lable>&nbsp;&nbsp;&nbsp;<lable><input type="radio" name="cattype" value="task"/>加入任务</lable></div><h3 class="res mart10"></h3><div class="null-vins" style="max-height: 100px;overflow: auto;"></div>';
	var btns = '<button type="button" class="btn btn-default getvin">取车架号</button>&nbsp;&nbsp;&nbsp;<button type="button" class="btn btn-primary ok" data-ignore="0">采集</button>&nbsp;&nbsp;&nbsp;<button type="button" class="btn btn-info ok" data-ignore="1" title="不采集600w存在的">采集[剔除]</button>&nbsp;&nbsp;&nbsp;<button type="button" class="btn btn-default message_close">关闭</button>';
	MESSAGE.show('泽达API采集', tpl, btns, 'zdApiCatch');
	autoFormatStr();

	$('#zdApiCatch .input-any-row').bind('blur', function(){
		var valArr = $.trim($(this).val()).replace(/[\,，\;\；]/g, "\n").split("\n");
		var realArr = new Array();
		for(var i in valArr)
		{
			var val = $.trim(valArr[i]);
			if(val != '' && $.inArray(val, realArr) === -1) realArr.push(val);
		}
		$(this).val(realArr.join("\n"));
		$('#zdApiCatch .txtcount').html(realArr.length);
	});

	$('#zdApiCatch .ok').unbind('click').click(function(){
		$this = $(this);
		var vins  = $('#catchvins').val();
		if(vins == ''){
			alert('车架号不能为空');
			return false;
		}
		var vinArr = vins.split("\n");
		$('#zdApiCatch .res').html('处理中...');
		$('#zdApiCatch .null-vins').html('');
		catchZd($this, vinArr, 0);
	});

	$('#zdApiCatch .getvin').unbind('click').click(function(){
		$this = $(this);
		$this.html('查询...');
		$('#zdApiCatch .txtcount').html('');
		var vins  = $('#catchvins').val();
		if(vins == ''){
			alert('车架号不能为空');
			return false;
		}
		var vinArr = vins.split("\n");
		$.ajax({
			url:ADMIN_URI+'vin/getCatchVinByVinreg',
			data: {'vin': vins, 'isAjax':1},
			dataType:'JSON',													
			type:'POST',												
			success:function(res){
				$this.html('取车架号');
				if(!MESSAGE.ajaxError(res)) return false;
				$('#catchvins').val(res.data.join("\n"));
				$('#zdApiCatch .txtcount').html(res.data.length);
			}
		});
		
	});

	$('.filterjs').unbind('click').click(function(){
		$this = $(this);
		var per = $this.data('val');
		var vins  = $('#catchvins').val();
		if(vins == ''){
			alert('车架号不能为空');
			return false;
		}
		var vinArr = vins.split("\n");
		vinArr = filterVin(vinArr, per);
		$('#catchvins').val(vinArr.join("\n"));
	});
}

function catchZd(ethis, vinArr, x)
{
	var vins = new Array();
	var len = vinArr.length;
	if(x >= len) return false;
	var max = len - x - 5 >= 0? x + 4: len - 1;
	for(var i in vinArr){
		if(i >= x && i <= max){
			vins.push(vinArr[i]);
		}else if(i > max){
			break;
		}
	}
	if(vins.length > 0){
		var cattype = $(':radio[name="cattype"]:checked').val();
		//console.log(vins);
		$.ajax({
			url:ADMIN_URI+'vin/catchZdApiVin',
			data: {'vins': vins, 'isAjax':1, 'ignore': ethis.data('ignore'), 'cattype': cattype},
			dataType:'JSON',													
			type:'POST',
			success:function(res){
				if(!MESSAGE.ajaxError(res))return false;
				if(res.data.task && res.data.task == 'ok'){
					$('#zdApiCatch .res').html('已加入采集任务');
				}else{
					for(tvin in res.data){
						var  t = '<div>'+tvin+' <span class="red">N</span></div>';
						if(res.data[tvin]){
							if(res.data[tvin].viz_id) t = '<div>'+tvin+' <span class="green">Y</span>';
							else if(res.data[tvin].sma_id) t = '<div>'+tvin+' <span class="green">has</span>';
						}
						$('#zdApiCatch .null-vins').append(t);
					}
					max++;
					$('#zdApiCatch .res').html('处理进度<b class="green">'+max+'</b>/'+len);
					if(max == vinArr.length)
					{
						$('#zdApiCatch .res').append('<form method="post" action="'+ADMIN_URI + 'vin/zdApiVinList" target="_blank"><textarea name="viz_vin" style="display:none">'+vinArr.join("\r\n")+'</textarea><button type="submit" class="btn btn-primary">查看详情</button>');
					}
					catchZd(ethis, vinArr, max);
				}
			}
		});
	}
}
</script>