1const API = { 2 'RU': { 3 url: 'https://suggestions.dadata.ru/suggestions/api/4_1/rs/suggest/party', 4 urlById: 'https://suggestions.dadata.ru/suggestions/api/4_1/rs/findById/party', 5 //urlOkved: 'https://suggestions.dadata.ru/suggestions/api/4_1/rs/suggest/okved2', 6 token: 'c15ea0aa728c8167aa788102e384b17b978599ea', 7 companyLabel: 'ÐведиÑе название, адÑеÑ, ÑÑководиÑелÑ, ÑÑÑедиÑелÑ, ÐÐÐ Ð, ÐÐÐ, ÑелеÑон', 8 fieldId: 'inn', 9 fieldName: 'INN', 10 fieldCountId: 'EmpNumber', 11 fieldCountName: 'EmpNumber', 12 fieldOkvedId: 'okved', 13 fieldOkvedName: 'OKVED' 14 }, 15 'BY': { 16 url: 'https://suggestions.dadata.ru/suggestions/api/4_1/rs/suggest/party_by', 17 urlById: 'https://suggestions.dadata.ru/suggestions/api/4_1/rs/findById/party_by', 18 token: 'c15ea0aa728c8167aa788102e384b17b978599ea', 19 companyLabel: 'ÐведиÑе название, адÑеÑ, ÑÑководиÑелÑ, ÑÑÑедиÑелÑ, УÐÐ, ÑелеÑо', 20 fieldId: 'unp', 21 fieldName: 'UNP', 22 fieldOkvedId: 'okved', 23 fieldOkvedName: 'OKVED' 24 } 25} 26let country = localStorage.getItem('country') || 'RU'; 27 28// ÐÐЯ Ð ÐÐÐТЫ С ÐШÐÐÐÐÐÐ 29function showInnError(message) { 30 const errorId = country === 'RU' ? 'inn-error' : 'unp-error'; 31 const innError = document.getElementById(errorId); 32 if (innError) { 33 innError.textContent = message; 34 innError.classList.remove('inn-error-hidden'); 35 innError.hidden = false; 36 } 37} 38 39function hideInnError() { 40 // СкÑÑваем обе возможнÑе оÑибки 41 ['inn-error', 'unp-error'].forEach(errorId => { 42 const errorElement = document.getElementById(errorId); 43 if (errorElement) { 44 errorElement.textContent = ''; 45 errorElement.classList.add('inn-error-hidden'); 46 errorElement.hidden = true; 47 } 48 }); 49} 50 51// ÐÐЯ Ð ÐÐÐТЫ С ÐÐÐÐÐ 52function createOkvedField(okvedData) { 53 if (!okvedData || !okvedData.Code) { 54 const fieldId = API[country].fieldOkvedId; 55 const existingOkved = document.getElementById(fieldId); 56 if (existingOkved) { 57 existingOkved.remove(); 58 localStorage.removeItem('okved'); 59 } 60 return; 61 } 62 63 const fieldId = API[country].fieldOkvedId; 64 const fieldName = API[country].fieldOkvedName; 65 let okvedInput = document.getElementById(fieldId); 66 const mainInput = document.getElementById(API[country].fieldId); 67 68 if (!okvedInput) { 69 okvedInput = document.createElement('input'); 70 okvedInput.setAttribute('name', fieldName); 71 okvedInput.setAttribute('id', fieldId); 72 okvedInput.setAttribute('type', 'hidden'); 73 okvedInput.setAttribute('autocomplete', 'off'); 74 75 if (country === 'RU') { 76 const organizationTypeInput = document.getElementById('organization_type'); 77 if (organizationTypeInput) { 78 organizationTypeInput.after(okvedInput); 79 } else { 80 const ogrnInput = document.getElementById('ogrn'); 81 if (ogrnInput) { 82 ogrnInput.after(okvedInput); 83 } else { 84 const kppInput = document.getElementById('kpp'); 85 if (kppInput) { 86 kppInput.after(okvedInput); 87 } else { 88 mainInput.after(okvedInput); 89 } 90 } 91 } 92 } else { 93 // ÐÐ»Ñ ÐелаÑÑÑи вÑÑавлÑем поÑле УÐÐ 94 mainInput.after(okvedInput); 95 } 96 } 97 98 const okvedJson = JSON.stringify(okvedData); 99 okvedInput.value = okvedJson; 100 localStorage.setItem('okved', okvedJson); 101} 102 103function fetchOkvedByInn(identifier) { 104 if (!identifier) return; 105 106 const link = API[country].urlById; 107 const token = API[country].token; 108 109 var options = { 110 method: "POST", 111 mode: "cors", 112 headers: { 113 "Content-Type": "application/json", 114 "Accept": "application/json", 115 "Authorization": "Token " + token 116 }, 117 body: JSON.stringify({query: identifier, count: 1}) 118 } 119 120 fetch(link, options) 121 .then(response => response.json()) 122 .then(result => { 123 if (result.suggestions && result.suggestions.length > 0) { 124 const data = result.suggestions[0].data; 125 126 if (country === 'RU') { 127 const okveds = data.okveds || []; 128 129 if (okveds.length > 0) { 130 // ÐÐ°Ñ Ð¾Ð´Ð¸Ð¼ оÑновной ÐÐÐÐÐ (main === true) 131 const mainOkved = okveds.find(item => item.main === true); 132 // ÐÑли оÑновной не найден, беÑем пеÑвÑй из ÑпиÑка 133 const selectedOkved = mainOkved || okveds[0]; 134 135 const okvedData = { 136 Type: selectedOkved.type || "2014", 137 Code: selectedOkved.code, 138 Name: selectedOkved.name || "" 139 }; 140 createOkvedField(okvedData); 141 } 142 } else if (country === 'BY') { 143 const okedCode = data.oked; 144 const okedName = data.oked_name || ''; 145 146 if (okedCode) { 147 const okedData = { 148 Code: okedCode, 149 Name: okedName 150 }; 151 createOkvedField(okedData); 152 } 153 } 154 } 155 }) 156 .catch(error => console.log("error fetching okved for existing company", error)); 157} 158 159updateInnUnp(); 160initUpdateInnUnp(); 161 162const selectCompanyWrap = document.querySelector('.select__company'); 163const selectCompanyBox = document.querySelector('.select__company-box'); 164 165const companyAutoComplete = document.getElementById('company')||document.getElementById('company-trial')||document.getElementById('company1'); 166const innInput = document.getElementById(API[country].fieldId); 167const inputBox = document.querySelectorAll('.input-box'); 168 169companyAutoComplete.addEventListener('keyup', onKeyup);
170inputBox.forEach(item => { 171 item.addEventListener('click', onCLick) 172}) 173 174function onCLick(e) { 175 const innInput = document.getElementById(API[country].fieldId); 176 177 if (e.target.className === 'show-cards') { 178 return; 179 } 180 else if (e.target.className !== 'select__company-box__options') { 181 selectCompanyWrap.classList.remove('active'); 182 return; 183 } 184 185 const company = e.target.textContent; 186 let name = e.target.dataset.name; 187 const inn = country === 'RU' ? e.target.dataset.inn : e.target.dataset.unp; 188 const kpp = e.target.dataset.ogrn; 189 const management = e.target.dataset.management; 190 const address = e.target.dataset.address; 191 companyAutoComplete.value = company; 192 innInput.value = inn; 193 innInput.readOnly = true; 194 selectCompanyWrap.classList.remove('active'); 195 196 hideInnError(); 197 198 // ÐÑзÑваем Ð´Ð»Ñ Ð¾Ð±ÐµÐ¸Ñ ÑÑÑан 199 fetchDataById(inn); 200 201 const innError = document.getElementById('inn-error'); 202 var innErrorText = document.querySelector('.form-row__subtext_signature'); 203 if (innErrorText.classList.contains('company-hidden')) { 204 innErrorText.classList.remove('company-hidden'); 205 } 206 207 if (innError) { 208 innError.classList.add('inn-error-hidden'); 209 document.getElementById('inn-error').hidden = true; 210 } 211} 212 213function onKeyup(e) { 214 const innInput = document.getElementById(API[country].fieldId); 215 216 const query = event.target.value; 217 if (query) { 218 innInput.readOnly = false; 219 fetchData(query) 220 } else { 221 innInput.value = ''; 222 innInput.readOnly = false; 223 fetchData(''); 224 } 225} 226 227function fetchData(query) { 228 const link = API[country].url; 229 const token = API[country].token; 230 231 var options = { 232 method: "POST", 233 mode: "cors", 234 headers: { 235 "Content-Type": "application/json", 236 "Accept": "application/json", 237 "Authorization": "Token " + token 238 }, 239 body: JSON.stringify({query: query, count: 20, "status": ["ACTIVE"]}) 240 } 241 242 fetch(link, options) 243 .then(response => response.json()) 244 .then(result => renderOptions(result)) 245 .catch(error => console.log("error", error)); 246} 247 248function fetchDataById(query) { 249 const link = API[country].urlById; 250 const token = API[country].token; 251 252 var options = { 253 method: "POST", 254 mode: "cors", 255 headers: { 256 "Content-Type": "application/json", 257 "Accept": "application/json", 258 "Authorization": "Token " + token 259 }, 260 body: JSON.stringify({query: query, count: 20, "status": ["ACTIVE"]}) 261 } 262 263 fetch(link, options) 264 .then(response => response.json()) 265 .then(result => { 266 createCountField(result); 267 268 if (country === 'RU' && result.suggestions.length > 0) { 269 const data = result.suggestions[0].data; 270 const kpp = data.kpp; 271 const ogrn = data.ogrn; 272 const organizationType = data.type; 273 const okveds = data.okveds || []; 274 const kppInput = document.getElementById('kpp'); 275 const ogrnInput = document.getElementById('ogrn'); 276 const organizationTypeInput = document.getElementById('organization_type'); 277 278 if (kpp) { 279 localStorage.setItem('kpp', kpp); 280 if (!kppInput) { 281 const newKppInput = document.createElement('input'); 282 newKppInput.setAttribute('type', 'hidden'); 283 newKppInput.setAttribute('id', 'kpp'); 284 newKppInput.setAttribute('name', 'KPP'); 285 newKppInput.setAttribute('autocomplete', 'off'); 286 newKppInput.value = kpp; 287 const innInput = document.getElementById(API.RU.fieldId); 288 innInput.after(newKppInput); 289 } else { 290 kppInput.value = kpp; 291 } 292 } else if (kppInput) { 293 kppInput.remove(); 294 } 295 296 if (ogrn) { 297 localStorage.setItem('ogrn', ogrn); 298 if (!ogrnInput) { 299 const newOgrnInput = document.createElement('input'); 300 newOgrnInput.setAttribute('type', 'hidden'); 301 newOgrnInput.setAttribute('id', 'ogrn'); 302 newOgrnInput.setAttribute('name', 'OGRN'); 303 newOgrnInput.setAttribute('autocomplete', 'off'); 304 newOgrnInput.value = ogrn;
305 const kppExistingInput = document.getElementById('kpp'); 306 if (kppExistingInput) { 307 kppExistingInput.after(newOgrnInput); 308 } else { 309 const innInput = document.getElementById(API.RU.fieldId); 310 innInput.after(newOgrnInput); 311 } 312 } else { 313 ogrnInput.value = ogrn; 314 } 315 } else if (ogrnInput) { 316 ogrnInput.remove(); 317 } 318 319 if (organizationType) { 320 localStorage.setItem('organization_type', organizationType); 321 if (!organizationTypeInput) { 322 const newOrganizationTypeInput = document.createElement('input'); 323 newOrganizationTypeInput.setAttribute('type', 'hidden'); 324 newOrganizationTypeInput.setAttribute('id', 'organization_type'); 325 newOrganizationTypeInput.setAttribute('name', 'organization_type'); 326 newOrganizationTypeInput.setAttribute('autocomplete', 'off'); 327 newOrganizationTypeInput.value = organizationType; 328 const ogrnExistingInput = document.getElementById('ogrn'); 329 if (ogrnExistingInput) { 330 ogrnExistingInput.after(newOrganizationTypeInput); 331 } else { 332 const kppExistingInput = document.getElementById('kpp'); 333 if (kppExistingInput) { 334 kppExistingInput.after(newOrganizationTypeInput); 335 } else { 336 const innInput = document.getElementById(API.RU.fieldId); 337 innInput.after(newOrganizationTypeInput); 338 } 339 } 340 } else { 341 organizationTypeInput.value = organizationType; 342 } 343 } else if (organizationTypeInput) { 344 organizationTypeInput.remove(); 345 } 346 347 // ÐолÑÑаем оÑновной ÐÐÐÐРиз маÑÑива okveds 348 if (okveds.length > 0) { 349 // ÐÐ°Ñ Ð¾Ð´Ð¸Ð¼ оÑновной ÐÐÐÐÐ (main === true) 350 const mainOkved = okveds.find(item => item.main === true); 351 // ÐÑли оÑновной не найден, беÑем пеÑвÑй из ÑпиÑка 352 const selectedOkved = mainOkved || okveds[0]; 353 354 if (selectedOkved) { 355 const okvedData = { 356 Type: selectedOkved.type || "2014", 357 Code: selectedOkved.code, 358 Name: selectedOkved.name || "" 359 }; 360 createOkvedField(okvedData); 361 } 362 } 363 } else if (country === 'BY' && result.suggestions.length > 0) { 364 // ÐÐ»Ñ ÐелаÑÑÑи полÑÑаем ÐÐÐÐ 365 const data = result.suggestions[0].data; 366 const okedCode = data.oked; 367 const okedName = data.oked_name || ''; 368 369 if (okedCode) { 370 const okedData = { 371 Code: okedCode, 372 Name: okedName 373 }; 374 createOkvedField(okedData); 375 } 376 } 377 }) 378 .catch(error => console.log("error", error)); 379} 380 381function createCountField(data) { 382 const {suggestions} = data; 383 const count = suggestions[0].data.employee_count; 384 let countInput = document.getElementById(API[country].fieldCountId); 385 386 if (count === null) { 387 if (countInput) { 388 countInput.remove(); 389 } 390 return; 391 } 392 393 const innInput = document.getElementById(API[country].fieldId); 394 395 if (!countInput) { 396 countInput = document.createElement('input'); 397 countInput.setAttribute('name', API[country].fieldCountName); 398 countInput.setAttribute('id', API[country].fieldCountId); 399 countInput.setAttribute('type', 'hidden'); 400 } 401 402 countInput.value = count; 403 404 innInput.after(countInput); 405} 406 407function renderOptionRu(item) { 408 const optionElem = document.createElement('div'); 409 optionElem.classList.add('select__company-box__options_no'); 410 411 let management = ''; 412 if (item.data.type == 'LEGAL'){ 413 management = item.data.management?.name || '' 414 } else if (item.data.type == 'INDIVIDUAL') { 415 management = item.data.name.full 416 } 417 418 const value = item.value; 419 const employee_count = item.data.employee_count; 420 const inn = item.data.inn;
421 const ogrn = item.data.ogrn; 422 const address = item.data.address.unrestricted_value; 423 const okved = item.data.okved || ''; 424 425 optionElem.dataset.value = value; 426 optionElem.dataset.inn = inn; 427 optionElem.dataset.management = management; 428 optionElem.dataset.ogrn = ogrn; 429 optionElem.dataset.address = address; 430 optionElem.dataset.employee_count = employee_count; 431 optionElem.dataset.okved = okved; 432 433 optionElem.innerHTML = ('<div class="select__company-box__options" data-inn="'+inn+'">')+value+('</div><div class="select__company-box__descriptions"><p class="select__company-box__descriptions_line"><span class="lowercase">инн ')+inn+('</span><span class="lowercase">огÑн ')+ogrn+('</span></p><p class="select__company-box__descriptions_line"><span>')+address+('</span></p><p class="select__company-box__descriptions_line"><span>')+management+('</span></p></div>'); 434 435 return optionElem; 436} 437 438function renderOptionBy(item) { 439 const optionElem = document.createElement('div'); 440 optionElem.classList.add('select__company-box__options_no'); 441 442 let management = ''; 443 if (item.data.type == 'LEGAL'){ 444 management = item.data.full_name_ru 445 } else if (item.data.type == 'INDIVIDUAL') { 446 management = item.data.fio_ru 447 } 448 449 const value = item.data.short_name_ru || item.data.full_name_ru; 450 const unp = item.data.unp; 451 const address = item.data.address || ''; 452 optionElem.dataset.value = value; 453 optionElem.dataset.unp = unp; 454 optionElem.dataset.management = management; 455 optionElem.dataset.address = address; 456 457 optionElem.innerHTML = ('<div class="select__company-box__options" data-unp="'+unp+'">')+value+('</div><div class="select__company-box__descriptions"><p class="select__company-box__descriptions_line"><span class="lowercase">Ñнп ')+unp+('</span></p><p class="select__company-box__descriptions_line"><span>')+address+('</span></p><p class="select__company-box__descriptions_line"><span>')+management+('</span></p></div>'); 458 459 return optionElem; 460} 461 462function renderOptions(result) { 463 464 const { suggestions } = result; 465 selectCompanyBox.innerHTML = ""; 466 console.log(suggestions); 467 468 const div = document.createElement("div"); 469 div.textContent = 'ÐÑбеÑиÑе ваÑÐ¸Ð°Ð½Ñ Ð¸Ð»Ð¸ пÑодолжиÑе ввод'; 470 div.classList.add('searchinn-head'); 471 const wrapper = document.querySelector('.select__company-box'); 472 const wrapperInner = document.createElement('div'); 473 wrapperInner.classList.add('select__company-box-inner'); 474 wrapper.prepend(div); 475 wrapper.appendChild(wrapperInner); 476 477 if (suggestions.length) { 478 suggestions.forEach(item => { 479 const optionElem = country === 'RU' ? renderOptionRu(item) : renderOptionBy(item); 480 wrapperInner.appendChild(optionElem); 481 selectCompanyWrap.classList.add('active'); 482 }) 483 484 } else { 485 return; 486 } 487 const showMoreResult = document.createElement('div'); 488 showMoreResult.classList.add('show-cards'); 489 selectCompanyBox.appendChild(showMoreResult); 490 showMoreResult.innerHTML = ('ÐоказаÑÑ ÐµÑе'); 491 492 $(document).ready(function(){ 493 var list = $(".select__company-box__options_no"); 494 var numToShow = 10; 495 var button = $(".show-cards"); 496 var numInList = list.length; 497 list.hide(); 498 if (numInList > numToShow) { 499 button.show(); 500 } else if (numInList < numToShow){ 501 button.hide(); 502 } 503 list.slice(0, numToShow).show(); 504 505 button.click(function(){ 506 var showing = list.filter(':visible').length;
507 list.slice(showing - 1, showing + numToShow).fadeIn(); 508 var nowShowing = list.filter(':visible').length; 509 if (nowShowing >= numInList) { 510 button.hide(); 511 } 512 console.log('нажаÑа кнопка'); 513 }); 514 515 $(document).mouseup(function (e) { 516 var container = $(".select__company-box"); 517 if (container.has(e.target).length === 0){ 518 selectCompanyWrap.classList.remove('active'); 519 } 520 }); 521 }); 522} 523 524const companyIdList = ['company', 'company-trial', 'company1']; 525 526companyIdList.forEach((selectorId) => { 527 const companyInput = document.getElementById(selectorId); 528 if (!companyInput) { 529 return; 530 } 531 532 companyInput.onclick = function() { 533 const innInput = document.getElementById(API[country].fieldId); 534 console.log(innInput) 535 this.value = ''; 536 innInput.value = ''; 537 538 // ÐÑиÑаем ÐÐÐÐÐ Ð´Ð»Ñ Ð¾Ð±ÐµÐ¸Ñ ÑÑÑан 539 const okvedInput = document.getElementById(API[country].fieldOkvedId); 540 if (okvedInput) { 541 okvedInput.remove(); 542 localStorage.removeItem('okved'); 543 } 544 545 const innError = document.getElementById('inn-error'); 546 if (innError || innInput.value) { 547 innError.hidden = true; 548 innError.setAttribute('style', ''); 549 const subtextError = document.getElementsByClassName('form-row__subtext_signature')[0]; 550 } 551 } 552}); 553 554function updateInnUnp() { 555 $('#company').siblings('.form-row__subtext_signature').text(API[country].companyLabel); 556 $('#company-trial').siblings('.form-row__subtext_signature').text(API[country].companyLabel); 557 558 $('#kpp').remove(); 559 $('#ogrn').remove(); 560 $('#organization_type').remove(); 561 $('#okved').remove(); 562 563 switch (country) { 564 case 'BY': 565 $('#' + API.RU.fieldId).attr('id', API.BY.fieldId).attr('name', API.BY.fieldName).val(''); 566 $('#' + API.RU.fieldCountId).remove(); 567 break; 568 case 'RU': 569 $('#' + API.BY.fieldId).attr('id', API.RU.fieldId).attr('name', API.RU.fieldName).val(''); 570 let kppInput = document.getElementById('kpp'); 571 let ogrnInput = document.getElementById('ogrn'); 572 let organizationTypeInput = document.getElementById('organization_type'); 573 let okvedInput = document.getElementById('okved'); 574 575 if (!kppInput) { 576 kppInput = document.createElement('input'); 577 kppInput.setAttribute('type', 'hidden'); 578 kppInput.setAttribute('id', 'kpp'); 579 kppInput.setAttribute('name', 'KPP'); 580 kppInput.setAttribute('placeholder', ' '); 581 kppInput.setAttribute('autocomplete', 'off'); 582 const innInput = document.getElementById(API.RU.fieldId); 583 innInput.after(kppInput); 584 } 585 586 if (!ogrnInput) { 587 ogrnInput = document.createElement('input'); 588 ogrnInput.setAttribute('type', 'hidden'); 589 ogrnInput.setAttribute('id', 'ogrn'); 590 ogrnInput.setAttribute('name', 'OGRN'); 591 ogrnInput.setAttribute('placeholder', ' '); 592 ogrnInput.setAttribute('autocomplete', 'off'); 593 const kppExistingInput = document.getElementById('kpp'); 594 if (kppExistingInput) { 595 kppExistingInput.after(ogrnInput); 596 } else { 597 const innInput = document.getElementById(API.RU.fieldId); 598 innInput.after(ogrnInput); 599 } 600 } 601 602 if (!organizationTypeInput) { 603 organizationTypeInput = document.createElement('input'); 604 organizationTypeInput.setAttribute('type', 'hidden'); 605 organizationTypeInput.setAttribute('id', 'organization_type'); 606 organizationTypeInput.setAttribute('name', 'organization_type'); 607 organizationTypeInput.setAttribute('placeholder', ' '); 608 organizationTypeInput.setAttribute('autocomplete', 'off');
609 const ogrnExistingInput = document.getElementById('ogrn'); 610 if (ogrnExistingInput) { 611 ogrnExistingInput.after(organizationTypeInput); 612 } else { 613 const kppExistingInput = document.getElementById('kpp'); 614 if (kppExistingInput) { 615 kppExistingInput.after(organizationTypeInput); 616 } else { 617 const innInput = document.getElementById(API.RU.fieldId); 618 innInput.after(organizationTypeInput); 619 } 620 } 621 } 622 623 if (!okvedInput) { 624 okvedInput = document.createElement('input'); 625 okvedInput.setAttribute('type', 'hidden'); 626 okvedInput.setAttribute('id', API.RU.fieldOkvedId); 627 okvedInput.setAttribute('name', API.RU.fieldOkvedName); 628 okvedInput.setAttribute('placeholder', ' '); 629 okvedInput.setAttribute('autocomplete', 'off'); 630 const organizationTypeExistingInput = document.getElementById('organization_type'); 631 if (organizationTypeExistingInput) { 632 organizationTypeExistingInput.after(okvedInput); 633 } else { 634 const ogrnExistingInput = document.getElementById('ogrn'); 635 if (ogrnExistingInput) { 636 ogrnExistingInput.after(okvedInput); 637 } else { 638 const kppExistingInput = document.getElementById('kpp'); 639 if (kppExistingInput) { 640 kppExistingInput.after(okvedInput); 641 } else { 642 const innInput = document.getElementById(API.RU.fieldId); 643 innInput.after(okvedInput); 644 } 645 } 646 } 647 } 648 break; 649 } 650} 651 652function initUpdateInnUnp() { 653 654 switch (country) { 655 case 'BY': 656 $('#' + API.BY.fieldId).val(localStorage.getItem('unp')); 657 $('#kpp').remove(); 658 $('#ogrn').remove(); 659 $('#organization_type').remove(); 660 $('#okved').remove(); 661 662 // ÐоÑÑÑановление ÐÐÐÐ Ð´Ð»Ñ ÐелаÑÑÑи 663 const savedOkved = localStorage.getItem('okved'); 664 if (savedOkved) { 665 try { 666 const parsedData = JSON.parse(savedOkved); 667 setTimeout(() => { 668 createOkvedField(parsedData); 669 }, 100); 670 } catch (e) { 671 console.log("Error parsing okved data for BY", e); 672 } 673 } else { 674 const savedUnp = localStorage.getItem('unp'); 675 if (savedUnp && savedUnp.trim() !== '') { 676 setTimeout(() => { 677 fetchOkvedByInn(savedUnp); 678 }, 500); 679 } 680 } 681 break; 682 case 'RU': 683 const savedInn = localStorage.getItem('inn'); 684 $('#' + API.RU.fieldId).val(savedInn); 685 686 const kppValue = localStorage.getItem('kpp'); 687 const ogrnValue = localStorage.getItem('ogrn'); 688 const organizationTypeValue = localStorage.getItem('organization_type'); 689 const okvedValue = localStorage.getItem('okved'); 690 691 if (kppValue) { 692 let kppInput = document.getElementById('kpp'); 693 if (!kppInput) { 694 kppInput = document.createElement('input'); 695 kppInput.setAttribute('type', 'hidden'); 696 kppInput.setAttribute('id', 'kpp'); 697 kppInput.setAttribute('name', 'KPP'); 698 kppInput.setAttribute('autocomplete', 'off'); 699 kppInput.value = kppValue; 700 const innInput = document.getElementById(API.RU.fieldId); 701 innInput.after(kppInput); 702 } else { 703 kppInput.value = kppValue; 704 } 705 } 706 707 if (ogrnValue) { 708 let ogrnInput = document.getElementById('ogrn'); 709 if (!ogrnInput) { 710 ogrnInput = document.createElement('input'); 711 ogrnInput.setAttribute('type', 'hidden'); 712 ogrnInput.setAttribute('id', 'ogrn'); 713 ogrnInput.setAttribute('name', 'OGRN'); 714 ogrnInput.setAttribute('autocomplete', 'off'); 715 ogrnInput.value = ogrnValue;
716 const kppExistingInput = document.getElementById('kpp'); 717 if (kppExistingInput) { 718 kppExistingInput.after(ogrnInput); 719 } else { 720 const innInput = document.getElementById(API.RU.fieldId); 721 innInput.after(ogrnInput); 722 } 723 } else { 724 ogrnInput.value = ogrnValue; 725 } 726 } 727 728 if (organizationTypeValue) { 729 let organizationTypeInput = document.getElementById('organization_type'); 730 if (!organizationTypeInput) { 731 organizationTypeInput = document.createElement('input'); 732 organizationTypeInput.setAttribute('type', 'hidden'); 733 organizationTypeInput.setAttribute('id', 'organization_type'); 734 organizationTypeInput.setAttribute('name', 'organization_type'); 735 organizationTypeInput.setAttribute('autocomplete', 'off'); 736 organizationTypeInput.value = organizationTypeValue; 737 const ogrnExistingInput = document.getElementById('ogrn'); 738 if (ogrnExistingInput) { 739 ogrnExistingInput.after(organizationTypeInput); 740 } else { 741 const kppExistingInput = document.getElementById('kpp'); 742 if (kppExistingInput) { 743 kppExistingInput.after(organizationTypeInput); 744 } else { 745 const innInput = document.getElementById(API.RU.fieldId); 746 innInput.after(organizationTypeInput); 747 } 748 } 749 } else { 750 organizationTypeInput.value = organizationTypeValue; 751 } 752 } 753 754 if (okvedValue) { 755 let okvedInput = document.getElementById(API.RU.fieldOkvedId); 756 if (!okvedInput) { 757 okvedInput = document.createElement('input'); 758 okvedInput.setAttribute('type', 'hidden'); 759 okvedInput.setAttribute('id', API.RU.fieldOkvedId); 760 okvedInput.setAttribute('name', API.RU.fieldOkvedName); 761 okvedInput.setAttribute('autocomplete', 'off'); 762 const organizationTypeInput = document.getElementById('organization_type'); 763 if (organizationTypeInput) { 764 organizationTypeInput.after(okvedInput); 765 } else { 766 const ogrnInput = document.getElementById('ogrn'); 767 if (ogrnInput) { 768 ogrnInput.after(okvedInput); 769 } else { 770 const kppInput = document.getElementById('kpp'); 771 if (kppInput) { 772 kppInput.after(okvedInput); 773 } else { 774 const innInput = document.getElementById(API.RU.fieldId); 775 innInput.after(okvedInput); 776 } 777 } 778 } 779 } 780 781 try { 782 const parsedOkved = JSON.parse(okvedValue); 783 okvedInput.value = okvedValue; 784 785 // ÐÑовеÑÑем, ÑÑо Ñ Ð½Ð°Ñ ÐµÑÑÑ Ð¿Ð¾Ð»Ð½Ñе даннÑе 786 if (parsedOkved.Code && parsedOkved.Name) { 787 // ÐаннÑе полнÑе, ниÑего не делаем 788 } else if (parsedOkved.Code && !parsedOkved.Name) { 789 // СÑаÑÑй ÑоÑÐ¼Ð°Ñ (ÑолÑко код) - обновлÑем 790 fetchOkvedByInn(savedInn); 791 } 792 } catch (e) { 793 // ÐÑли ÑÐ¾Ñ Ñанен ÑолÑко код как ÑÑÑока 794 fetchOkvedByInn(okvedValue); 795 } 796 } else if (savedInn && savedInn.trim() !== '') { 797 setTimeout(() => { 798 fetchOkvedByInn(savedInn); 799 }, 500); 800 } 801 break; 802 } 803} 804 805$("[name*=country]").on("change", function(e) { 806 country = e.target.value; 807 updateInnUnp(); 808 const companyAutoComplete = document.getElementById('company')||document.getElementById('company-trial')||document.getElementById('company1'); 809 companyAutoComplete.value = ''; 810 811 localStorage.removeItem('okved'); 812 813 hideInnError(); 814 815 setTimeout(() => { 816 if (typeof updateAllPlaceholders === 'function') { 817 updateAllPlaceholders(); 818 } 819 }, 100); 820}); 821 822// ÐÐÐ ÐÐЯ ÐÐÐÐСХÐÐÐÐÐ ÐÐ 823document.addEventListener('DOMContentLoaded', function() { 824 const inputs = document.querySelectorAll('.js-placeholder-truncate'); 825 826 function updateAllPlaceholders() { 827 const inputs = document.querySelectorAll('.js-placeholder-truncate'); 828
829 inputs.forEach(input => { 830 const isActiveAndEmpty = document.activeElement === input && input.value.trim() === ''; 831 const hasError = input.classList.contains('error'); 832 833 if (isActiveAndEmpty || hasError) { 834 const fullText = country === 'RU' 835 ? input.dataset.fullRu 836 : input.dataset.fullBy; 837 838 if (fullText) { 839 input.placeholder = calculatePlaceholderForElement(input, fullText); 840 841 if (isActiveAndEmpty) { 842 input.classList.remove('placeholder-hidden'); 843 input.classList.add('placeholder-visible'); 844 } 845 } 846 } 847 }); 848 } 849 850 window.calculatePlaceholderForElement = function(input, fullText) { 851 if (window.innerWidth > 1921) return fullText; 852 853 const measure = document.createElement('span'); 854 measure.style.cssText = ` 855 position: absolute; 856 visibility: hidden; 857 white-space: nowrap; 858 font-family: inherit; 859 font-size: inherit; 860 font-weight: inherit; 861 letter-spacing: inherit; 862 left: -9999px; 863 top: -9999px; 864 `; 865 measure.textContent = fullText; 866 document.body.appendChild(measure); 867 868 const style = window.getComputedStyle(input); 869 870 const paddingLeft = parseFloat(style.paddingLeft) || 0; 871 const paddingRight = parseFloat(style.paddingRight) || 0; 872 const borderLeft = parseFloat(style.borderLeftWidth) || 0; 873 const borderRight = parseFloat(style.borderRightWidth) || 0; 874 875 const inputRect = input.getBoundingClientRect(); 876 const availableWidth = inputRect.width - paddingLeft - paddingRight - borderLeft - borderRight - 2; 877 878 if (availableWidth <= 0) { 879 document.body.removeChild(measure); 880 return fullText; 881 } 882 883 const fullWidth = measure.offsetWidth; 884 885 if (fullWidth <= availableWidth) { 886 document.body.removeChild(measure); 887 return fullText; 888 } 889 890 const ellipsis = '...'; 891 let truncated = fullText; 892 let lastValidText = ''; 893 894 let low = 0; 895 let high = fullText.length; 896 897 while (low <= high) { 898 const mid = Math.floor((low + high) / 2); 899 truncated = fullText.substring(0, mid) + ellipsis; 900 measure.textContent = truncated; 901 902 if (measure.offsetWidth <= availableWidth) { 903 lastValidText = truncated; 904 low = mid + 1; 905 } else { 906 high = mid - 1; 907 } 908 } 909 910 document.body.removeChild(measure); 911 912 return lastValidText || (fullText.substring(0, 3) + ellipsis); 913 }; 914 915 window.setInputError = function(inputElement, message) { 916 if (!inputElement) return; 917 918 inputElement.classList.add('error'); 919 920 if (inputElement.value.trim() === '') { 921 const fullText = country === 'RU' 922 ? inputElement.dataset.fullRu 923 : inputElement.dataset.fullBy; 924 925 if (fullText) { 926 inputElement.placeholder = calculatePlaceholderForElement(inputElement, fullText); 927 inputElement.classList.add('placeholder-visible'); 928 inputElement.classList.remove('placeholder-hidden'); 929 } 930 } 931 932 const errorElement = inputElement.parentElement.querySelector('.error_company'); 933 if (errorElement && message) { 934 errorElement.textContent = message; 935 errorElement.style.display = 'block'; 936 } 937 }; 938 939 window.clearInputError = function(inputElement) { 940 if (!inputElement) return; 941 942 inputElement.classList.remove('error'); 943 944 const errorElement = inputElement.parentElement.querySelector('.error_company'); 945 if (errorElement) { 946 errorElement.textContent = ''; 947 errorElement.style.display = 'none'; 948 } 949 950 if (document.activeElement !== inputElement && inputElement.value.trim() === '') { 951 inputElement.placeholder = ''; 952 inputElement.classList.remove('placeholder-visible'); 953 inputElement.classList.add('placeholder-hidden'); 954 } 955 }; 956 957 function showPlaceholderWithDelay(input) { 958 if (!input) return; 959 960 const fullText = country === 'RU' 961 ? input.dataset.fullRu 962 : input.dataset.fullBy; 963 964 if (!fullText) return; 965 966 setTimeout(() => { 967 if (document.activeElement === input && input.value.trim() === '') { 968 input.placeholder = calculatePlaceholderForElement(input, fullText); 969 input.classList.remove('placeholder-hidden'); 970 input.classList.add('placeholder-visible'); 971 } 972 }, 10); 973 } 974
975 inputs.forEach(input => { 976 const fullText = input.dataset.fullRu; 977 if (!fullText) return; 978 979 input.placeholder = ''; 980 input.classList.add('placeholder-hidden'); 981 982 function getPlaceholderText() { 983 return country === 'RU' 984 ? input.dataset.fullRu 985 : input.dataset.fullBy; 986 } 987 988 function calculatePlaceholder() { 989 const text = getPlaceholderText(); 990 return calculatePlaceholderForElement(input, text); 991 } 992 993 let wasCleared = false; 994 let originalValue = ''; 995 996 input.addEventListener('focus', function() { 997 originalValue = this.value; 998 999 if (this.value.trim() === '') { 1000 this.placeholder = calculatePlaceholder(); 1001 this.classList.remove('placeholder-hidden'); 1002 this.classList.add('placeholder-visible'); 1003 } else { 1004 wasCleared = false; 1005 } 1006 }); 1007 1008 input.addEventListener('blur', function() { 1009 wasCleared = false; 1010 1011 if (!this.classList.contains('error')) { 1012 this.placeholder = ''; 1013 this.classList.remove('placeholder-visible'); 1014 this.classList.add('placeholder-hidden'); 1015 } 1016 }); 1017 1018 input.addEventListener('input', function(e) { 1019 if (this.classList.contains('error')) { 1020 clearInputError(this); 1021 } 1022 1023 if (originalValue !== '' && this.value.trim() === '') { 1024 wasCleared = true; 1025 } 1026 1027 if (this.value.trim() !== '') { 1028 this.placeholder = ''; 1029 this.classList.remove('placeholder-visible'); 1030 this.classList.add('placeholder-hidden'); 1031 } else if (document.activeElement === this) { 1032 this.placeholder = calculatePlaceholder(); 1033 this.classList.remove('placeholder-hidden'); 1034 this.classList.add('placeholder-visible'); 1035 } 1036 }); 1037 1038 input.addEventListener('mousedown', function() { 1039 if (document.activeElement === this && this.value.trim() !== '') { 1040 this.dataset.wasFocused = 'true'; 1041 } 1042 }); 1043 1044 input.addEventListener('click', function() { 1045 if (this.dataset.wasFocused === 'true' && this.value.trim() !== '') { 1046 setTimeout(() => { 1047 if (document.activeElement === this && this.value.trim() === '') { 1048 this.placeholder = calculatePlaceholder(); 1049 this.classList.remove('placeholder-hidden'); 1050 this.classList.add('placeholder-visible'); 1051 } 1052 }, 100); 1053 } 1054 delete this.dataset.wasFocused; 1055 }); 1056 1057 input.addEventListener('keydown', function(e) { 1058 if ((e.key === 'Delete' || e.key === 'Backspace') && this.value.trim() !== '') { 1059 setTimeout(() => { 1060 if (document.activeElement === this && this.value.trim() === '') { 1061 this.placeholder = calculatePlaceholder(); 1062 this.classList.remove('placeholder-hidden'); 1063 this.classList.add('placeholder-visible'); 1064 } 1065 }, 10); 1066 } 1067 }); 1068 1069 input.addEventListener('cut', function() { 1070 setTimeout(() => { 1071 if (document.activeElement === this && this.value.trim() === '') { 1072 this.placeholder = calculatePlaceholder(); 1073 this.classList.remove('placeholder-hidden'); 1074 this.classList.add('placeholder-visible'); 1075 } 1076 }, 10); 1077 }); 1078 1079 window.addEventListener('resize', function() { 1080 updateAllPlaceholders(); 1081 }); 1082 }); 1083 1084 function updateHideninnHeight() { 1085 var containers = document.querySelectorAll('.hideninn'); 1086
1087 containers.forEach(function(container) { 1088 var innError = container.querySelector('#inn-error'); 1089 var unpError = container.querySelector('#unp-error'); 1090 var hasInnError = innError && innError.textContent && innError.textContent.trim() !== ''; 1091 var hasUnpError = unpError && unpError.textContent && unpError.textContent.trim() !== ''; 1092 var hasError = hasInnError || hasUnpError; 1093 1094 if (hasError) { 1095 container.classList.add('error-visible'); 1096 } else { 1097 container.classList.remove('error-visible'); 1098 } 1099 }); 1100 } 1101 1102 window.refreshPlaceholders = function() { 1103 inputs.forEach(input => { 1104 if (document.activeElement === input && input.value.trim() === '') { 1105 const fullText = country === 'RU' 1106 ? input.dataset.fullRu 1107 : input.dataset.fullBy; 1108 1109 if (fullText) { 1110 input.placeholder = calculatePlaceholderForElement(input, fullText); 1111 input.classList.remove('placeholder-hidden'); 1112 input.classList.add('placeholder-visible'); 1113 } 1114 } 1115 }); 1116 }; 1117 1118 setInterval(updateHideninnHeight, 200); 1119 document.addEventListener('input', updateHideninnHeight); 1120 document.addEventListener('change', updateHideninnHeight); 1121 document.addEventListener('click', function() { 1122 updateHideninnHeight(); 1123 setTimeout(refreshPlaceholders, 50); 1124 }); 1125 setTimeout(updateHideninnHeight, 500); 1126 1127 setTimeout(function() { 1128 inputs.forEach(input => { 1129 if (document.activeElement === input && input.value.trim() === '') { 1130 const fullText = country === 'RU' 1131 ? input.dataset.fullRu 1132 : input.dataset.fullBy; 1133 1134 if (fullText) { 1135 input.placeholder = calculatePlaceholderForElement(input, fullText); 1136 input.classList.remove('placeholder-hidden'); 1137 input.classList.add('placeholder-visible'); 1138 } 1139 } 1140 }); 1141 }, 1000); 1142});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.