<?php include_once(mvc::$cfg['PATH_TPL'].'public/headBase.php');?>
<div class="marauto open-shop-apply" style="margin-left:5px;padding-top: 10px;">
	<div class="searchParam">
		<form method="get">
			<b>VIN：</b><textarea name="sma_vin" class="form-control textrow input-any-row" rows="1" cols="23" placeholder="多个用;分割或者换行"><?php echo $Params['sma_vin'];?></textarea>&nbsp;&nbsp;&nbsp;
			<b>工信部：</b><textarea name="sma_gxb_code" class="form-control textrow input-any-row" rows="1" cols="20" placeholder="多个用;分割或者换行"><?php echo $Params['sma_gxb_code'];?></textarea>&nbsp;&nbsp;&nbsp;
			<b>品牌：</b><input type="text" class="form-control" name="sma_brand" value="<?php echo $Params['sma_brand'];?>" size="10">&nbsp;&nbsp;&nbsp;
			<b>发动机：</b><input type="text" class="form-control" name="sma_engine" value="<?php echo $Params['sma_engine'];?>" size="12">&nbsp;&nbsp;&nbsp;
			<b>尺寸：</b><input type="text" name="sma_length" placeholder="长" title="支持粘贴：5012*1855*1485" class="form-control sizetxt" value="<?php echo $Params['sma_length'];?>">
			*
			<input type="text" name="sma_width" placeholder="宽" class="form-control sizetxt" value="<?php echo $Params['sma_width'];?>">
			*
			<input type="text" name="sma_height" placeholder="高" class="form-control sizetxt" value="<?php echo $Params['sma_height'];?>">
			<a href="javascript:;" onclick="$('.sizetxt').val('')" class="a_blue">清</a>&nbsp;&nbsp;&nbsp;
			<input type="text" name="sma_wheel" placeholder="轴距" class="form-control" style="width: 45px;" value="<?php echo $Params['sma_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</a>
		</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="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="120px" class="Sort"><span>外调型号</span></th>
				<th width="50px" class="Sort"><span>外调</span></th>
				<th width="120px" 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: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:30px"></td>
				<td><input type="text" class="FilterTxt form-control" style="width:80px"></td>
				<td><input type="text" class="FilterTxt form-control" style="width:20px"></td>
				<td><input type="text" class="FilterTxt form-control" style="width:80px"></td>
				<td><input type="text" class="FilterTxt form-control" style="width:20px"></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['sma_vin'];?></a></td>
				<td><?php echo $v['sma_vin1_8'];?></td>
				<td><?php echo substr($v['sma_vin'], 9, 1);?></td>
				<td><?php echo substr($v['sma_vin'], 10, 1);?></td>
				<td><?php echo substr($v['sma_vin'], 11);?></td>
				<td><?php echo $v['sma_brand'];?></td>
				<td><?php echo $v['sma_gxb_code_show'];?></td>
				<td><?php echo $v['sma_engine'];?></td>
				<td><?php echo $v['sma_kw'];?></td>
				<td><?php echo $v['sma_cc'];?></td>
				<td><?php echo $v['sma_length'] > 0 ? $v['sma_length'] : '';?></td>
				<td><?php echo $v['sma_width'] > 0 ? $v['sma_width'] : '';?></td>
				<td><?php echo $v['sma_height'] > 0 ? $v['sma_height'] : '';?></td>
				<td><?php echo $v['sma_wheel'] > 0 ? $v['sma_wheel'] : '';?></td>
				<td><?php echo $v['sma_weight'] > 0 ? $v['sma_weight'] : '';?></td>
				<td><?php echo $v['sma_passenger'] > 0 ? $v['sma_passenger'] : '';?></td>
				<td><?php echo $v['sma_vtype'];?></td>
				<td><?php echo $v['sgs_gxb_soupei'];?></td>
				<td><?php if(!empty($v['sgs_gxb_soupei_format']) && !empty($v['sma_gxb_code'])) echo $v['sgs_gxb_soupei_format'] == $v['sma_gxb_code']? '<span class="green">Y</span>': '<span class="red">N</span>';?></td>
				<td><?php echo $v['sgs_gxb_yp'];?></td>
				<td><?php if(!empty($v['sgs_gxb_yp_format']) && !empty($v['sma_gxb_code'])) echo $v['sgs_gxb_yp_format'] == $v['sma_gxb_code']? '<span class="green">Y</span>': '<span class="red">N</span>';?></td>
			</tr>
			<?php }?>
		</tbody>
	</table>
	<?php 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, '*').split('*');
		if(sizeArr.length >= 3){
			$('.sizetxt').each(function(i, e){
				$(this).val($.trim(sizeArr[i]));
			})
		}
	});
});

function showZdApiCatchBox()
{
	var tpl = '<textarea id="catchvins" class="form-control input-any-row" rows="20" cols="50" placeholder="多个用;分割或者换行"></textarea><div class="mart5">过滤：<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><span class="filterjs" data-val="50">1/50</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-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('外调SP采集', tpl, btns, 'wdspApiCatch');
	autoFormatStr();
	$('#wdspApiCatch .ok').unbind('click').click(function(){
		$this = $(this);
		var vins  = $('#catchvins').val();
		if(vins == ''){
			alert('车架号不能为空');
			return false;
		}
		var vinArr = vins.split("\n");
		var cattype = $(':radio[name="cattype"]:checked').val();
		var tempVin = new Array();
		$('#wdspApiCatch .res').html('处理中...');
		$('#wdspApiCatch .null-vins').html('');
		var x = 0;
		for(var i in vinArr){
			tempVin.push(vinArr[i]);
			i = parseInt(i);
			if(i%3 == 2 || (i+1) == vinArr.length){
				var vins = tempVin;
				tempVin = new Array();
				$.ajax({
					url:ADMIN_URI+'ypcCar/catchWdspApiVin',
					data: {'vins': vins, 'isAjax':1, 'ignore': $this.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'){
							$('#wdspApiCatch .res').html('已加入采集任务');
						}else{
							for(tvin in res.data){
								x++;
								var  t = '<div>'+tvin+' <span class="red">N</span></div>';
								if(res.data[tvin]){
									if(res.data[tvin].sma_id) t = '<div>'+tvin+' <span class="green">Y</span>';
									else if(res.data[tvin].sma_id) t = '<div>'+tvin+' <span class="green">has</span>';
								}
								$('#wdspApiCatch .null-vins').append(t);
							}
							$('#wdspApiCatch .res').html('处理进度<b class="green">'+x+'</b>/'+vinArr.length);
							if(x == vinArr.length){
								var go = ADMIN_URI + 'ypcCar/wdspApiVinList?sma_vin='+vinArr.join(";");
								$('#wdspApiCatch .res').append(' <a href="'+go+'" target="_blank" class="a_blue">查看详情</a>');
							}
						}
					}
				});
			}
		}
	});

	$('.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"));
	});
}
</script>