Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $(document).ready(function () {
- $("#select_bank img,.chooseBanks").click(function(){
- $(this).toggleClass("active");
- })
- })
- // функция отрисовки
- function drawChecbox(arr, type, insertInDiv) {
- for (let i = 0; i < arr.length; i++) {
- let div_checkbox = document.createElement("div");
- div_checkbox.setAttribute("class", type)
- let checkbox = document.createElement("input");
- checkbox.setAttribute("type", "checkbox");
- checkbox.setAttribute("id", type + arr[i]["id"]);
- let label = document.createElement("label");
- label.setAttribute("for", arr[i]["id"]);
- if (type == "bank") {
- label.innerHTML = label.innerHTML = "<img id='img-"+ arr[i].id +"'src='http://osno.online/"+arr[i]['logo']+"'>";
- } else if (type=="tag") {
- label.innerHTML = arr[i]["name"];
- }
- div_checkbox.appendChild(checkbox);
- div_checkbox.appendChild(label);
- document.getElementById(insertInDiv).appendChild(div_checkbox);
- }
- }
- // рисую банки и таги
- drawChecbox(banks, "bank", "select_bank");
- drawChecbox(tags, "tag", "tags");
- // функция отрисовки выбранного
- function drawChoose(i, innerDiv) {
- var div_rate = document.createElement("div");
- div_rate.setAttribute("class", "rate");
- var name_rate = document.createElement("h5");
- name_rate.innerHTML = "[" + rates[i].id + "]" + rates[i].name;
- var p_rate = document.createElement("p");
- p_rate.innerHTML = rates[i].description+"<br><br><strong> Обслуживание: "+rates[i].price+" руб.</strong>";
- var bank_rate = document.createElement("p");
- bank_rate.setAttribute("class", "bank_logo");
- bank_rate.innerHTML = "<img src='http://osno.online/"+banks[rates[i].id_bank-1].logo+"'>";
- var a_rate = document.createElement("a");
- a_rate.innerHTML = "Подробнее" + "[" + rates[i].tags + "]";
- div_rate.appendChild(name_rate);
- div_rate.appendChild(bank_rate);
- div_rate.appendChild(p_rate);
- div_rate.appendChild(a_rate);
- document.getElementById(innerDiv).appendChild(div_rate);
- }
- for (let i = 0, end = rates.length; i < end; i++) {
- rates[i]["cov"] = 0;
- }
- for (let i = 0, endI = rates.length - 1; i < endI; i++) {
- let wasSwap = false;
- for (let j = 0, endJ = endI - i; j < endJ; j++) {
- if (parseInt(rates[j].price) > parseInt(rates[j+1].price)) {
- [rates[j], rates[j+1]] = [rates[j+1], rates[j]];
- wasSwap = true;
- }
- }
- if (!wasSwap) break;
- }
- go('Все предложения');
- function go(labelResult) {
- // обновление 3х блоков
- document.getElementById("p100").innerHTML ="<h5 style='width: 100%;'>" + labelResult + "</h5>";
- document.getElementById("from1to99p").innerHTML = "<h5 style='width: 100%;'>Похожие результаты</h5>";
- document.getElementById("other_banks").innerHTML = "<h5 style='width: 100%;'>Предложения от других банков</h5>";
- // counter
- let countTag = 0;
- for (let i = 0; i < tags.length; i++) {
- if (document.getElementById("tag" + tags[i].id).checked) {
- countTag += 1;
- for (let j = 0; j < rates.length; j++) {
- if (rates[j].tags.split(",").includes(tags[i].id)) {
- rates[j].cov += 1;
- }
- }
- }
- }
- // allBanksChecked
- let checkBanks = document.getElementsByClassName("active");
- let checkBanksId = [];
- for (var i = 0; i < checkBanks.length; i++) {
- checkBanksId.push(document.getElementsByClassName("active")[i].id.split("-")[1]);
- }
- console.log('checkBanksId :');
- console.log(checkBanksId);
- let p100 = 0;
- let from1to99p = 0;
- let other_banks = 0;
- // drawing response
- for (var i = 0; i < rates.length; i++) {
- console.log(rates[i].tags.split(","));
- if (countTag) {
- rates[i].cov = (rates[i].cov / countTag) * 100;
- }
- console.log(checkBanksId.includes(rates[i].id_bank));
- if (checkBanksId.length == 0 || checkBanksId.includes(rates[i].id_bank)) {
- console.log('RISUEM');
- if (rates[i].cov == 100 ||(checkBanksId.length == 0 && rates[i].cov==0) || (checkBanksId.length != 0 && rates[i].cov==0)) {
- p100 += 1
- drawChoose(i, "p100");
- } else if (rates[i].cov < 100 && rates[i].cov != 0 && from1to99p != 3) { // Условия для отбора похожих можно сменить на не лояльные
- from1to99p += 1;
- drawChoose(i, "from1to99p");
- }
- } else {
- if (rates[i].cov == 100) {
- other_banks += 1;
- drawChoose(i, "other_banks");
- }
- }
- rates[i].cov = 0;
- }
- if (!p100) {
- document.getElementById("p100").innerHTML = "<h5 style='width: 100%;'>Результатов не найдено</h5>";
- }
- if (!from1to99p) {
- document.getElementById("from1to99p").innerHTML = "";
- }
- if (!other_banks) {
- document.getElementById("other_banks").innerHTML = "";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement