carsoft.js 10.4 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454
/*车牌号键盘 start*/
var provinces = new Array("京","津","渝","沪","冀","晋","辽","吉","黑","苏",
"浙","皖","闽","赣","鲁","豫","鄂","湘","粤","琼",
"川","贵","云","陕","甘","青","蒙","桂","宁","新",
"ABC","藏","学","澳","港","警","W","delete");

var keyNums = new Array("1","2","3","4","5","6","7","8","9","0",
"Q","W","E","R","T","Y","U","I","O","P",
"A","S","D","F","G","H","J","K","L",
"Z","X","C","返回","V","B","N","M","学","delete");
var keyNumss = new Array("1","2","3","4","5","6","7","8","9","0",
"京","津","渝","沪","冀","晋","辽","吉","黑","苏",
"浙","皖","闽","赣","鲁","豫","鄂","湘","粤","琼",
"川","贵","云","陕","甘","青","蒙","桂","宁","新",
"藏","delete");


var choseno = new Array("Q","W","E","R","T","Y","U","I","O","P",
"A","S","G","H","J","K","L",
"Z","X","C","V","B","N","M");

var chosenum = new Array("Q","W","E","R","T","Y","U","I","O","P",
"A","S","D","F","G","H","J","K","L",
"Z","X","C","V","B","N","M","学");

var xinnengyuan = false;
//当input聚焦时候
/*function onfocusinput(){
	var sin = $('#input').val();
	if(sin.length<1){
		openprovice(1);
	}else{
		openprovice(2);
	}
}*/
$("#input").focus(function(){
	var val = $("#input").val();
	document.activeElement.blur();
	var sin = $(this).val();
	console.log(" sin "+sin);
	if(sin.length<1){
		console.log(" sin1 ");
		openprovice(1);
	}else if(val=='WJ'){
		console.log(" sin2 ");
		openprovice(3);
	}else{
		console.log(" sin3 ");
		openprovice(2);
	}
	
});
$('#carsoft').click(function(){
	var val = $("#input").val();
	var sin = $(this).val();
	console.log(" sin "+sin);
	if(val.length<1){
		openprovice(1);
	}else if(val=='WJ'){
		openprovice(3);
	}else{
		openprovice(2);
	}
});


function setdiv(){
	var inputnum = $('#input').val();
	var carsoft = $('#carsoft');
	if(carsoft){
		for(var i=0;i<inputnum.length;i++){
			carsoft.children('span').eq(i).children('div').text(inputnum[i]);
		}
		if(xinnengyuan&&inputnum.length<8){
			for(var i=inputnum.length;i<8;i++){
				carsoft.children('span').eq(i).children('div').html('&nbsp;');
			}
			/*if(carsoft.children('span').eq(i+1)){
				carsoft.children('span').eq(i+1).children('div').addClass('active');
				carsoft.children('span').eq(i+1).siblings().children('div').removeClass('active');
			}*/
			
		}else if(!xinnengyuan&&inputnum.length<7){
			for(var i=inputnum.length;i<7;i++){
				carsoft.children('span').eq(i).children('div').html('&nbsp;');
			}
		}
		if(carsoft.children('span').eq(inputnum.length)){
			carsoft.children('span').eq(inputnum.length).addClass('active');
			carsoft.children('span').eq(inputnum.length).siblings().removeClass('active');
		}
	}
}

$(document).bind('click',function(e){
    var e = e || window.event; //浏览器兼容性
    var elem = e.target || e.srcElement;
    while (elem) { //循环判断至跟节点,防止点击的是div子元素
    	console.log("elem.id "+elem.id);
      if (elem.id && elem.id=='pro'||elem.id=='input'||elem.id=='carsoft'||elem.id=='qiehuan') {
      	console.log("elem.id "+elem.id);
        return;
      }
      elem = elem.parentNode;
    }
    $("#pro").html('');
    layer.closeAll();
    
});
    	
//初始化省键盘
function initprovice(){
	$("#pro").html('');
	var p = document.createElement('div');
	p.className = 'province';
	var ul = document.createElement('ul');
	for(var i=0;i<provinces.length;i++){
		var li = document.createElement('li');
		li.setAttribute('data-value',provinces[i]);
		li.setAttribute('onclick','choosep(this)');
		//choosep(obj)
		if(xinnengyuan&&provinces[i]=='W'){
			li.style.color = '#999';
			li.setAttribute('onclick','');
		}
		if(provinces[i]=='ABC'||i==provinces.length-1){
			li.className = 'ts';
		}
		if(i==provinces.length-1){
			li.innerHTML = '<i class="icon iconfont ">&#xe638;</i>';
		}else{
			li.innerText = provinces[i];
		}
		//ul.innerHTML += li;
		ul.appendChild(li);    		
	}
	//p.innerHTML += ul;
	p.appendChild(ul);
	$("#pro").html(p);
}
    
    
    
//初始化字母数字键盘
function keynumbord(){
	//$("#pro").html('');
	var p = document.createElement('div');
	p.className = 'province zimjianp';
	var sin = $('#input').val();
	var ul = document.createElement('ul');
	for(var i=0;i<keyNums.length;i++){
		var li = document.createElement('li');
		li.setAttribute('data-value',keyNums[i]);
		li.setAttribute('onclick','chooseabc(this)');
		if(i<10){
			li.className = 'fontcolor';
			if(sin.length<=1){
				li.style.color = '#999';
				li.setAttribute('onclick','');
			}
			
		}
		if(keyNums[i]=='I'){
			li.style.color = '#999';
			li.setAttribute('onclick','');
		}
		if(sin.length>=2&&keyNums[i]=='O'){
			li.style.color = '#999';
			li.setAttribute('onclick','');
		}
		if(sin.length==2&&xinnengyuan){
			//console.log('长度为2时'+keyNums[i]+"  sin  "+sin);
			for(var ch = 0;ch<choseno.length;ch++){
				if(keyNums[i]==choseno[ch]){
					console.log('物质性');
					li.style.color = '#999';
					li.setAttribute('onclick','');
				}
			}
		}
		if(sin.length==4&&xinnengyuan){
			for(var ch = 0;ch<chosenum.length;ch++){
				if(keyNums[i]==chosenum[ch]){
					console.log('物质性');
					li.style.color = '#999';
					li.setAttribute('onclick','');
				}
			}
		}
		
		if(keyNums[i]=='学'){
			li.className = 'tshu';
			if(sin.length<=6){
				li.style.color = '#999';
				li.setAttribute('onclick','');
			}	
		}
		if(keyNums[i]=='返回'||i==keyNums.length-1){
			li.className = 'ts';
		}
		if(i==keyNums.length-1){
			li.innerHTML = '<i class="icon iconfont ">&#xe638;</i>';
		}else{
			li.innerText = keyNums[i];
		}
		ul.appendChild(li);    		
	}
	p.appendChild(ul);
	$("#pro").html(p);
}
//初始化数字汉字车牌
function initkeyNumss(){
	$("#pro").html('');
	var p = document.createElement('div');
	p.className = 'province keynumh';
	var sin = $('#input').val();
	var ul = document.createElement('ul');
	for(var i=0;i<keyNumss.length;i++){
		var li = document.createElement('li');
		li.setAttribute('data-value',keyNumss[i]);
		li.setAttribute('onclick','choosenumorh(this)');
		if(i<10){
			li.className = 'fontcolor';
			if(sin.length<=1){
				li.style.color = '#999';
			}
		}
		if(i==keyNumss.length-1){
			li.className = 'ts';li.innerHTML = '<i class="icon iconfont ">&#xe638;</i>';
		}else{
			li.innerText = keyNumss[i];
		}
		ul.appendChild(li);    		
	}
	p.appendChild(ul);
	$("#pro").html(p);
}


//点击打开键盘
function openprovice(n){
	console.log(n);
	
	layer.open({
		type: 1,
		content: '<div id="pro"></div>',
		anim: 'up',
		shade :false,
		title:false,
		closeBtn:false,
		style: 'position:fixed; bottom:0; left:0; width: 100%; height: auto; padding:0; border:none;'
	});
	//keynumbord();
	if(n==1){
		initprovice();
	}
	else if(n==2){
		keynumbord();
	}
    else if(n==3){
		initkeyNumss();
	}
}

//选择省份
function choosep(obj){
	var pname = obj.getAttribute('data-value');
	
	var str = $('#input').val();
	var inp = str;
	if(xinnengyuan&&str.length>=7&&pname!='delete'){
		if(str.length==7){
			inp +=pname;
		}
		if(func){
			try{
				
				func.userallorders(inp);
			}catch(e){}
		}
		layer.closeAll();
		console.log('关闭');
	}else if(!xinnengyuan&&str.length>=6&&pname!='delete'){
		if(str.length==6){
			inp +=pname;
		}
		try{
			if(func){
				try{
					func.userallorders(inp);
				}catch(e){}
			}
		}catch(e){}
		
		layer.closeAll();
		console.log('关闭');
	}else{
		if(pname=='delete'){
			inp = str.substring(0,str.length-1);
		}else if(pname=='ABC'){
			if(str.length>=1){
				setTimeout(function(){
		    		openprovice(2);
		    	},100);
			}
		}else{
			inp +=pname;
			var nt = 2;
			if(pname=='W'){
				nt = 3;
				inp +='J';
			}
			setTimeout(function(){
	    		openprovice(nt);
	    	},100);
			
		}
		$('#input').val(inp);	
		setdiv();
	
	}
	
}
//选择字母或数字
function chooseabc(obj){
	var pname = obj.getAttribute('data-value');
	var fontcolor = obj.style.color;
	var str = $('#input').val();
	console.log(str);
	var inp = str;
	if(xinnengyuan&&str.length>=7&&pname!='delete'){
		if(str.length==7){
			inp +=pname;
		}
		if(func){
			//if(func.userallorders())
			try{
				func.userallorders(inp);
			}catch(e){
				
			}
		}
		layer.closeAll();
		console.log('关闭');
	}else if(!xinnengyuan&&str.length>=6&&pname!='delete'){
		if(str.length==6){
			inp +=pname;
		}
		//mui.toast('车牌号第二位为字母');
		try{
			if(func){
				//if(func.userallorders())
				try{
					func.userallorders(inp);
				}catch(e){
					
				}
			}
		}catch(e){
			
		}
		
		layer.closeAll();
		console.log('关闭');
	}else{
		if(pname=='delete'){
			if($('#input').val().length==2||$('#input').val().length==3){
				//$(".fontcolor").css('color','#999');
				setTimeout(function(){
					keynumbord();
					console.log('初始化');
				},100);
			}
    		inp = str.substring(0,str.length-1);
    		console.log(str.length+"  "+str.substring(0,str.length-1));
    		if(str.length<2){
    			setTimeout(function(){
		    		openprovice(1);
		    	},100);
    		}else if(str.length==3&&str.substring(0,str.length-1)=='WJ'){
    			setTimeout(function(){
		    		openprovice(3);
		    	},100);
	    	}
    		
    	}else if(pname=='返回'){
    		layer.closeAll();
    	}else{
    		if(str.length==1){
    			if(pname=='0'||pname=='1'||pname=='2'||pname=='3'||pname=='4'||pname=='5'||pname=='6'||pname=='7'||pname=='8'||pname=='9'){
    				$.toptip('车牌号第二位为字母','warning');
    				//$.toast('车牌号第二位为字母');
    				return;
    			}
    		}
    		/*if(fontcolor=='rgb(153, 153, 153)'){
    			console.log('颜色是不可点击');
    			return false;
    		}*/
    		setTimeout(function(){
					keynumbord();
					console.log('初始化');
				},100);
    		console.log('颜色  '+fontcolor);
    		inp +=pname;
    	}
    	
    	if($('#input').val().length==2){
			$(".fontcolor").css('color','#000');
		}
    	if($('#input').val().length==6){
			$(".tshu").css('color','#000');
		}else{
			$(".tshu").css('color','#999');
		}
    	
	}
	$('#input').val(inp);
	setdiv();
 	/*setTimeout(function(){
					keynumbord();
					console.log('初始化');
				},100);*/
	
	//openprovice(2);
}
//选择汉字或数字
function choosenumorh(obj){
	var pname = obj.getAttribute('data-value');
	
	var str = $('#input').val();
	var inp = str;
	if(pname=='delete'){
		if($('#input').val()=="WJ"){
			inp ='';
			setTimeout(function(){
	    		openprovice(1);
	    	},100);
		}
		
	}else if(pname=='返回'){
		layer.closeAll();
	}else{
		inp +=pname;
		setTimeout(function(){
    		openprovice(2);
    	},100);
		//openprovice(2);
	}
	$('#input').val(inp);
	//openprovice(2);
	setdiv()
}
/*end*/