var thFields = [[]], thOrder = [[]], thFieldsZoom = [[]], thOrderZoom = [[]];
let defaultTables = [], zoomTables = [];
let pipeStandard = null;
thFields["sheet"] = ["ID", "نام محصول", "تولیدکننده", "حالت", "نوع", "ضخامت", "استاندارد", "ابعاد(m)", "محل بارگیری", "وزن(kg)", "واحد", "قیمت (تومان)", "بروزرسانی"];
thOrder["sheet"] = ["id", "name", "producer", "state", "type", "thickness", "analysis", "size", "loadingPlace", "weight", "unit", "price", "lastUpdate"];
thFieldsZoom["sheet"] = ["ID", "نام محصول", "قیمت (تومان)", "بروزرسانی"];
thOrderZoom["sheet"] = ["id", "name", "price", "lastUpdate"];
thFields["rebar"] = ["نام محصول", "تولیدکننده", "سایز(mm)", "حالت", "نوع", "طول(m)", "آنالیز", "محل بارگیری", "وزن(kg)", "واحد", "قیمت (تومان)", "بروزرسانی"];
thOrder["rebar"] = ["name", "producer", "size", "state", "type", "length", "analysis", "loadingPlace", "weight", "unit", "price", "lastUpdate"];
thFieldsZoom["rebar"] = ["نام محصول", "قیمت (تومان)", "بروزرسانی"];
thOrderZoom["rebar"] = ["name", "price", "lastUpdate"];
thFields["girder"] = ["نام محصول", "تولیدکننده", "سایز(mm)", "حالت", "طول(m)", "محل بارگیری", "وزن(kg)", "واحد", "قیمت (تومان)", "بروزرسانی"];
thOrder["girder"] = ["name", "producer", "size", "state", "length", "loadingPlace", "weight", "unit", "price", "lastUpdate"];
thFieldsZoom["girder"] = ["نام محصول", "قیمت (تومان)", "بروزرسانی"];
thOrderZoom["girder"] = ["name", "price", "lastUpdate"];
thFields["profile"] = ["نام محصول", "تولیدکننده", "نوع", "ضخامت", "سایز(mm)", "حالت", "طول(m)", "محل بارگیری", "وزن(kg)", "واحد", "قیمت (تومان)", "بروزرسانی"];
thOrder["profile"] = ["name", "producer", "type", "thickness", "size", "state", "length", "loadingPlace", "weight", "unit", "price", "lastUpdate"];
thFieldsZoom["profile"] = ["نام محصول", "قیمت (تومان)", "بروزرسانی"];
thOrderZoom["profile"] = ["name", "price", "lastUpdate"];
thFields["pipe"] = ["نام محصول", "تولیدکننده", "سایز(mm)", "طول(m)", "حالت", "ضخامت", "محل بارگیری", "وزن(kg)", "واحد", "قیمت (تومان)", "بروزرسانی"];
thOrder["pipe"] = ["name", "producer", "size", "state", "thickness", "loadingPlace", "weight", "unit", "price", "lastUpdate"];
thFieldsZoom["pipe"] = ["نام محصول", "قیمت (تومان)", "بروزرسانی"];
thOrderZoom["pipe"] = ["name", "price", "lastUpdate"];
thFields["wire"] = ["نام محصول", "تولیدکننده", "سایز(mm)", "طول(m)", "حالت", "ضخامت", "محل بارگیری", "وزن(kg)", "واحد", "قیمت (تومان)", "بروزرسانی"];
thOrder["wire"] = ["name", "producer", "size", "state", "thickness", "loadingPlace", "weight", "unit", "price", "lastUpdate"];
thFieldsZoom["wire"] = ["نام محصول", "قیمت (تومان)", "بروزرسانی"];
thOrderZoom["wire"] = ["name", "price", "lastUpdate"];
thFields["corner"] = ["نام محصول", "سایز(mm)", "ضخامت(mm)", "حالت", "طول(m)", "تولیدکننده", "محل بارگیری", "وزن(kg)", "واحد", "قیمت (تومان)", "بروزرسانی"];
thOrder["corner"] = ["name", "size", "thickness", "state", "length", "producer", "loadingPlace", "weight", "unit", "price", "lastUpdate"];
thFieldsZoom["corner"] = ["نام محصول", "قیمت (تومان)", "بروزرسانی"];
thOrderZoom["corner"] = ["name", "price", "lastUpdate"];
thFields["stud"] = ["نام محصول", "تولیدکننده", "سایز(mm)", "حالت", "طول(m)", "محل بارگیری", "وزن(kg)", "واحد", "قیمت (تومان)", "بروزرسانی"];
thOrder["stud"] = ["name", "producer", "size", "state", "length", "loadingPlace", "weight", "unit", "price", "lastUpdate"];
thFieldsZoom["stud"] = ["نام محصول", "قیمت (تومان)", "بروزرسانی"];
thOrderZoom["stud"] = ["name", "price", "lastUpdate"];
thFields["wire"] = ["نام محصول", "حالت", "نوع", "ضخامت(mm)", "سایز(mm)", "ضخامت(mm)", "سایز(mm)", "واحد", "قیمت"];
thOrder["wire"] = ["name", "state", "type", "thickness", "size", "unit", "price"];
thFieldsZoom["wire"] = ["نام محصول", "قیمت (تومان)", "بروزرسانی"];
thOrderZoom["wire"] = ["name", "price", "lastUpdate"];
class MyTable extends HTMLDivElement {
constructor(fields, fieldsOrder, rows) {
super();
this.className = 'divTable';
const td = [];
if (rows['data'][0]['kind1'] === 'pipe' && rows['data'][0]['kind2'] !== 'furniture' && pipeStandard === null) {
pipeStandard = {'0/125': 10.2, '0/25': 13.5, '0/375': 17.2, '0/5': 21.3, '0/75': 26.7, '1': 33.4, '1/25': 42.2, '1/5': 48.3, '2': 60.3, '2/5': 73, '3': 88.9,
'3/5': 101.6, '4': 114.3, '5': 141.3, '6': 168.3, '8': 219.1, '10': 273.1, '12': 323.9, '14': 406.4, '16': 457, '18': 506, '20': 559,'22': 610, '24': 660};
}
const divTableTitle = createDiv();
divTableTitle.className = 'divTableTitle';
this.appendChild(divTableTitle);
const imgLogo = document.createElement('img');
imgLogo.src = rows['producerLogo'];
imgLogo.alt = "قیمت " + rows['kind2Name'] + " " + rows['producer'];
imgLogo.style.width = imgLogo.style.height = '1.3cm';
imgLogo.style.marginInlineEnd = '0.3cm';
divTableTitle.appendChild(imgLogo);
const h2Title = document.createElement("h2");
h2Title.innerHTML = "قیمت " + rows['kind2Name'] + " " + rows['producer'];
h2Title.style.marginInlineEnd = 'auto';
divTableTitle.appendChild(h2Title);
this.h2Title = h2Title;
const divCheckbox = createDiv();
divCheckbox.style.flexDirection = 'row';
divCheckbox.style.marginInlineStart = 'auto';
divTableTitle.appendChild(divCheckbox);
const checkbox = document.createElement('input');
checkbox.type = 'checkbox';
setHoverPointer(checkbox);
checkbox.addEventListener('change', function (event) {
if (event.target.checked) {
for (let i = 0; i < td.length; i++) {
for (let j = 0; j < fieldsCount; j++) {
if (fieldsOrder[j] === 'price' && table.data['data'][i]['price'] !== '0') {
td[i]['price'].innerHTML = getSplitterDigit(Math.ceil(parseInt(table.data['data'][i]['price']) * 110 / 100));
}
}
}
} else {
for (let i = 0; i < td.length; i++) {
for (let j = 0; j < fieldsCount; j++) {
if (fieldsOrder[j] === 'price' && table.data['data'][i]['price'] !== '0') {
td[i]['price'].innerHTML = getSplitterDigit(table.data['data'][i]['price']);
}
}
}
}
});
divCheckbox.appendChild(checkbox);
const pTax = createP(str(strShowWithTax));
divCheckbox.appendChild(pTax);
const table = document.createElement("table");
this.appendChild(table);
this.table = table;
table.data = rows;
const fieldsCount = fields.length;
const rowsCount = rows['data'].length;
const tr = document.createElement("tr");
this.headerTR = tr;
let i = 0
for (; i < fieldsCount; i++) {
const th = document.createElement("th");
th.innerHTML = fields[i];
tr.appendChild(th);
}
const th = document.createElement("th");
th.innerHTML = "سفارش";
tr.appendChild(th);
table.appendChild(tr);
for (let i = 0; i < rowsCount; i++) {
if (rows['data'][i]['kind1'] === 'sheet' && rows['data'][i]['kind2'] === 'steel') {
rows['data'][i]['analysis'] = rows['data'][i]['producer'];
rows['data'][i]['producer'] = 'وارداتی';
}
const tr = document.createElement("tr");
td[i] = {};
setHoverAnimationOpacity(tr, 1, 0.8);
for (let j = 0; j < fieldsCount; j++) {
td[i][fieldsOrder[j]] = document.createElement("td");
rows['data'][i]['thickness'] = rows['data'][i]['thickness'].replace('.', '/');
rows['data'][i]['size'] = rows['data'][i]['size'].replace('.', '/');
rows['data'][i]['length'] = rows['data'][i]['length'].replace('.', '/');
if (fieldsOrder[j] === 'name') {
let createdName = createProductName(td[i][fieldsOrder[j]], rows['data'][i]);
td[i][fieldsOrder[j]] = createdName['td'];
td[i][fieldsOrder[j]].innerHTML = createdName['text'];
} else {
let text;
const row = rows['data'][i];
if (row['kind1'] === 'sheet') {
text = row[fieldsOrder[j]];
if (fieldsOrder[j] === "size") {
td[i][fieldsOrder[j]].style.direction = "ltr";
if (row["state"] === "رول") {
text = 'عرض ' + text;
} else {
text = text + " × " + row["length"];
}
}
} else if (row['kind1'] === 'rebar') {
text = row[fieldsOrder[j]];
if (fieldsOrder[j] === "length") {
if (row['state'] === 'شاخه') {
text = text + " متری";
} else if (row['state'] === 'کلاف') {
text = '-';
}
}
} else if (row['kind1'] === 'girder') {
text = row[fieldsOrder[j]];
if (fieldsOrder[j] === "length") {
text = text + " متری";
}
} else if (row['kind1'] === 'profile') {
text = row[fieldsOrder[j]];
if (fieldsOrder[j] === "size") {
if (row['size'] === '0') {
text = '-';
} else if (row['kind2'] === 'industrial' || row['kind2'] === 'furniture') {
text = row['size'] + ' × ' + row['analysis'];
}
} else if (fieldsOrder[j] === "length") {
text = text + " متری";
}
} else if (row['kind1'] === 'pipe') {
text = row[fieldsOrder[j]];
if (fieldsOrder[j] === "length") {
text = text + " متری";
} else if (fieldsOrder[j] === "size") {
const pointPos = row['size'].indexOf('/');
if (row['kind2'] === 'furniture') {
text = '-';
} else if (pointPos !== -1) {
const intPart = row['size'].substring(0, pointPos);
const decPart = row['size'].substring(pointPos + 1);
text = (decPart === '25' ? '1/4' : (decPart === '5' ? '1/2' : '3/4')) + (intPart === '0' ? '' : (' - ' + intPart));
}
} else if (fieldsOrder[j] === 'state') {
if (row['kind2'] === 'furniture') {
text = row['size'];
} else {
text = pipeStandard[row['size']];
}
}
} else if (row['kind1'] === 'corner') {
text = row[fieldsOrder[j]];
if (fieldsOrder[j] === "length") {
text = text + " متری";
} else if (fieldsOrder[j] === "size") {
text = text + " × " + text;
}
} else if (row['kind1'] === 'stud') {
text = row[fieldsOrder[j]];
if (fieldsOrder[j] === "length") {
text = text + " متری";
}
} else if (row['kind1'] === 'wire') {
text = row[fieldsOrder[j]];
}
if (fieldsOrder[j] === "price") {
td[i][fieldsOrder[j]].style.fontWeight = "bold";
if (text === "0") {
text = "تماس بگیرید";
} else {
text = getSplitterDigit(text);
}
} else if (fieldsOrder[j] === "pdPrice") {
if (text === "0") {
text = "بدون قیمت";
} else {
text = getSplitterDigit(text);
}
} else if (fieldsOrder[j] === "lastUpdate") {
if (row['price'] === '0') {
text = '-';
} else {
// text = getElapsedTime(Date.now() / 1000 - parseInt(text)) + " " + str(strAgo);
text = new Date(parseInt(text) * 1000).toLocaleDateString('fa-IR');
}
}
if (fieldsOrder[j] === "weight" && text === '0') {
text = '-';
}
if (fieldsOrder[j] === "analysis" && text === '') {
text = '-';
}
td[i][fieldsOrder[j]].innerHTML = text;
}
tr.appendChild(td[i][fieldsOrder[j]]);
}
const tdImg = document.createElement("td");
const img = document.createElement("img");
img.className = 'tableImg';
img.src = imgCheckout;
img.alt = "خرید " + rows["kind2Name"];
setHoverPointer(img);
img.addEventListener("click", function () {
if (localStorage["cookie"] !== undefined && localStorage["cookie"].length > 0) {
window.alert("لطفاً جهت سفارش با شماره 91001040-031 تماس حاصل فرمائید");
} else {
window.alert(str(strYouShouldLogin));
window.location.replace(linkRegLogin + encodeUrlSearch({"origin": window.location.href}));
}
});
tdImg.appendChild(img);
tr.appendChild(tdImg);
table.appendChild(tr);
}
}
}
class MyTable2 extends HTMLDivElement {
constructor(fields, rows) {
super();
this.style.backgroundColor = colorless;
this.style.display = "flex";
this.style.flexDirection = "column";
const table = document.createElement("table");
table.style.borderCollapse = "separate";
table.style.borderSpacing = "0";
table.style.marginTop = "0.2cm";
this.appendChild(table);
const fieldsCount = fields.length;
const rowsCount = rows.length;
this.th = [];
const tr = document.createElement("tr");
for (let i = 0; i < fieldsCount; i++) {
const th = document.createElement("th");
th.style.fontFamily = "fontface1";
th.style.fontWeight = "bold";
th.style.fontSize = sizeText2;
th.style.padding = "0 0.2cm";
th.style.textAlign = "center";
th.style.border = "1px solid #ffffff55";
th.style.color = "#ffffff";
th.style.backgroundColor = colorHeaderBackground1;
const textNode = document.createTextNode(fields[i]);
th.appendChild(textNode);
tr.appendChild(th);
this.th[i] = th;
}
table.appendChild(tr);
this.td = [];
for (let i = 0; i < rowsCount; i++) {
this.td[i] = [];
const tr = document.createElement("tr");
for (let j = 0; j < fieldsCount; j++) {
const td = document.createElement("td");
td.style.fontFamily = "fontface1";
td.style.fontWeight = "normal";
td.style.fontSize = sizeText2;
td.style.padding = "0 0.2cm";
td.style.textAlign = "center";
td.style.border = "1px solid #00000011";
td.style.color = colorText;
if (j > 0) {
td.style.direction = "ltr";
}
const textNode = document.createTextNode(rows[i][j]);
td.appendChild(textNode);
tr.appendChild(td);
this.td[i][j] = td;
}
table.appendChild(tr);
}
}
setTextSize(textSize) {
for (let i = 0; i < this.th.length; i++) {
this.th[i].style.fontSize = textSize;
for (let j = 0; j < this.td.length; j++) {
this.td[j][i].style.fontSize = textSize;
}
}
}
}
class MyTable3 extends HTMLDivElement {
constructor(kind1, kind2, skip, take, producers) {
super();
let tableToolsZoomStatus = "none";
let defaultTables = [], zoomTables = [];
const root = this;
root.style.backgroundColor = colorless;
root.style.display = "flex";
root.style.flexDirection = "column";
window.addEventListener("resize", function () {
if ((tableToolsZoomStatus === "none" || tableToolsZoomStatus === "default") && zoom) {
tableToolsZoomStatus = "zoom";
for (let i = 0; i < defaultTables.length; i++) {
root.style.marginLeft = "4%";
root.style.marginRight = "4%";
root.style.width = "92%";
defaultTables[i].remove();
root.appendChild(zoomTables[i]);
}
} else if ((tableToolsZoomStatus === "none" || tableToolsZoomStatus === "zoom") && !zoom) {
tableToolsZoomStatus = "default";
for (let i = 0; i < defaultTables.length; i++) {
root.style.marginLeft = "auto";
root.style.marginRight = "auto";
root.style.width = "98%";
zoomTables[i].remove();
root.appendChild(defaultTables[i]);
}
}
});
const sendData = new FormData();
sendData.append("kind1", kind1);
sendData.append("kind2", kind2);
sendData.append("skip", skip);
sendData.append("take", take);
sendData.append("producers", JSON.stringify(producers));
sendData.append("sizes", JSON.stringify([]));
sendData.append("analysis", JSON.stringify([]));
sendData.append("thicknesses", JSON.stringify([]));
const xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (this.readyState === 4 && this.status === 200) {
const getData = JSON.parse(this.responseText);
if (getData['result'] === 'ok') {
for (let i = 0; i < getData["products"].length; i++) {
defaultTables[i] = new MyTable(thFields[kind1], thOrder[kind1], getData["products"][i]);
zoomTables[i] = new MyTable(thFieldsZoom[kind1], thOrderZoom[kind1], getData["products"][i]);
}
tableToolsZoomStatus = "none";
window.dispatchEvent(new Event("resize"));
}
}
};
xhr.open("POST", apiGetProductsSkipTake, true);
xhr.send(sendData);
}
}
class MyTableOthers extends HTMLDivElement {
constructor(fields, fieldsOrder, rows) {
super();
this.className = 'divTable';
const td = [];
const level = localStorage.getItem('level');
const divTableTitle = createDiv();
divTableTitle.className = 'divTableTitle';
this.appendChild(divTableTitle);
const imgLogo = document.createElement('img');
imgLogo.src = rows['producerLogo'];
imgLogo.alt = "قیمت " + rows['kind2Name'] + " " + rows['producer'];
imgLogo.style.width = imgLogo.style.height = '1.3cm';
imgLogo.style.marginInlineEnd = '0.3cm';
divTableTitle.appendChild(imgLogo);
const h2Title = document.createElement("h2");
h2Title.innerHTML = "قیمت " + rows['kind2Name'] + " " + rows['producer'];
h2Title.style.marginInlineEnd = 'auto';
divTableTitle.appendChild(h2Title);
this.h2Title = h2Title;
const checkbox = document.createElement('input');
checkbox.type = 'checkbox';
setHoverPointer(checkbox);
checkbox.addEventListener('change', function (event) {
if (event.target.checked) {
for (let i = 0; i < td.length; i++) {
for (let j = 0; j < fieldsCount; j++) {
if (fieldsOrder[j] !== 'id' && fieldsOrder[j] !== 'name') {
if (fieldsOrder[j] === 'safiranahan') {
if (myThis.data['data'][i]['price'] !== '0') {
inputPrice[i].value = Math.ceil(parseInt(myThis.data['data'][i]['price']) * 110 / 100);
}
}
else if (fieldsOrder[j] !== 'phone') {
if (myThis.data['data'][i][fieldsOrder[j] + 'Price'] !== '0') {
const newPrice = Math.ceil(parseInt(myThis.data['data'][i][fieldsOrder[j] + 'Price']) * 110 / 100);
// td[i][fieldsOrder[j]].innerHTML = '' + getSplitterDigit(newPrice) + '' + ' - ' + myThis.data['data'][i][fieldsOrder[j] + 'Update'] + ' - ' + myThis.data['data'][i][fieldsOrder[j] + 'Id'];
td[i][fieldsOrder[j]].innerHTML = '' + getSplitterDigit(newPrice) + '' + ' - ' + myThis.data['data'][i][fieldsOrder[j] + 'Update'];
}
}
}
}
}
} else {
for (let i = 0; i < td.length; i++) {
for (let j = 0; j < fieldsCount; j++) {
if (fieldsOrder[j] !== 'id' && fieldsOrder[j] !== 'name') {
if (fieldsOrder[j] === 'safiranahan') {
if (myThis.data['data'][i]['price'] !== '0') {
inputPrice[i].value = parseInt(myThis.data['data'][i]['price']);
}
}
else if (fieldsOrder[j] !== 'phone') {
if (myThis.data['data'][i][fieldsOrder[j] + 'Price'] !== '0') {
// td[i][fieldsOrder[j]].innerHTML = '' + getSplitterDigit(myThis.data['data'][i][fieldsOrder[j] + 'Price']) + '' + ' - ' + myThis.data['data'][i][fieldsOrder[j] + 'Update'] + ' - ' + myThis.data['data'][i][fieldsOrder[j] + 'Id'];
td[i][fieldsOrder[j]].innerHTML = '' + getSplitterDigit(myThis.data['data'][i][fieldsOrder[j] + 'Price']) + '' + ' - ' + myThis.data['data'][i][fieldsOrder[j] + 'Update'];
}
}
}
}
}
}
});
divTableTitle.appendChild(checkbox);
const pTax = createP(str(strShowWithTax));
divTableTitle.appendChild(pTax);
const table = document.createElement("table");
this.appendChild(table);
this.table = table;
this.data = rows;
const fieldsCount = fields.length;
const rowsCount = rows['data'].length;
const tr = document.createElement("tr");
this.headerTR = tr;
let i = 0
for (; i < fieldsCount; i++) {
const th = document.createElement("th");
th.innerHTML = fields[i];
tr.appendChild(th);
}
table.appendChild(tr);
const inputPrice = [];
const inputPhone = [];
for (let i = 0; i < rowsCount; i++) {
const tr = document.createElement("tr");
tr.style.width = "100%";
td[i] = {};
setHoverAnimationOpacity(tr, 1, 0.8);
for (let j = 0; j < fieldsCount; j++) {
td[i][fieldsOrder[j]] = document.createElement("td");
td[i][fieldsOrder[j]].id = i + ',' + fieldsOrder[j];
if (fieldsOrder[j] === 'id') {
td[i][fieldsOrder[j]].innerHTML = rows['data'][i]['id'];
} else if (fieldsOrder[j] === 'name') {
let createdName = createProductName(td[i][fieldsOrder[j]], rows['data'][i]);
td[i][fieldsOrder[j]] = createdName['td'];
if (createdName['text'] !== undefined) {
td[i][fieldsOrder[j]].innerHTML = createdName['text'].substring(rows['kind2Name'].length + 5);
}
} else if (fieldsOrder[j] === 'safiranahan') {
td[i][fieldsOrder[j]].innerHTML = new Date(parseInt(rows['data'][i]['lastUpdate']) * 1000).toLocaleDateString('fa-IR');
inputPrice[i] = document.createElement("input");
inputPrice[i].className = 'inputPrice';
inputPrice[i].id = i;
inputPrice[i].type = "number";
inputPrice[i].min = "0";
inputPrice[i].max = "100000000";
inputPrice[i].placeholder = 'تماس';
if (level === 'master') {
inputPrice[i].addEventListener("input", function (event) {
if (event.target.value === '0') {
event.target.value = '';
}
});
inputPrice[i].addEventListener("focus", function (event) {
event.target.value = '';
});
} else {
inputPrice[i].readOnly = true;
}
if (rows['data'][i]['price'] === '0') {
inputPrice[i].value = '';
} else {
inputPrice[i].value = rows['data'][i]['price'];
}
td[i][fieldsOrder[j]].appendChild(inputPrice[i]);
} else if (fieldsOrder[j] === 'phone') {
inputPhone[i] = document.createElement("input");
inputPhone[i].className = 'inputPrice';
inputPhone[i].id = i;
inputPhone[i].type = "number";
inputPhone[i].min = "0";
inputPhone[i].max = "100000000";
inputPhone[i].placeholder = 'نامعلوم';
inputPhone[i].addEventListener("input", function (event) {
if (event.target.value === '0') {
event.target.value = '';
}
});
inputPhone[i].addEventListener("focus", function (event) {
event.target.value = '';
});
if (rows['data'][i]['phonePrice'] === '0') {
inputPhone[i].value = '';
td[i][fieldsOrder[j]].innerHTML = '-';
} else {
inputPhone[i].value = rows['data'][i]['phonePrice'];
td[i][fieldsOrder[j]].innerHTML = new Date(parseInt(rows['data'][i]['phoneUpdate']) * 1000).toLocaleDateString('fa-IR') + ' - ' + rows['data'][i]['phonePricer'];
}
td[i][fieldsOrder[j]].appendChild(inputPhone[i]);
} else {
td[i][fieldsOrder[j]].style.transition = '0.2s';
// setHoverAnimation2(td[i][fieldsOrder[j]], '', '#00000022');
if (level === 'master') {
setHoverPointer(td[i][fieldsOrder[j]]);
td[i][fieldsOrder[j]].addEventListener('click', function (event) {
const id = event.target.id;
const commaId = id.indexOf(',');
const id1 = parseInt(id.substring(0, commaId));
const id2 = id.substring(commaId + 1);
if (rows['data'][id1][id2 + 'Price'] !== '0') {
inputPrice[id1].value = rows['data'][id1][id2 + 'Price'];
}
});
}
if (rows['data'][i][fieldsOrder[j] + 'Id'] === '' || rows['data'][i][fieldsOrder[j] + 'Id'] === '0') {
td[i][fieldsOrder[j]].innerHTML = '-';
} else if (rows['data'][i][fieldsOrder[j] + 'Price'] === '0') {
td[i][fieldsOrder[j]].innerHTML = 'تماس';
} else {
let id = rows['data'][i][fieldsOrder[j] + 'Id'];
let price = getSplitterDigit(rows['data'][i][fieldsOrder[j] + 'Price']);
let date = rows['data'][i][fieldsOrder[j] + 'Update'];
if (fieldsOrder[j].substring(0, 7) === 'esfahan') {
const dash1Pos = date.indexOf('-');
const dash2Pos = date.indexOf('-', dash1Pos + 1);
const year = date.substring(0, dash1Pos);
const month = parseInt(date.substring(dash1Pos + 1, dash2Pos)) - 1;
const day = date.substring(dash2Pos + 1);
date = new Date(year, month, day).toLocaleDateString('fa-IR');
}
// td[i][fieldsOrder[j]].innerHTML = '' + price + '' + ' - ' + date + ' - ' + rows['data'][i][fieldsOrder[j] + 'Id'];
td[i][fieldsOrder[j]].innerHTML = '' + price + '' + ' - ' + date;
}
}
tr.appendChild(td[i][fieldsOrder[j]]);
}
table.appendChild(tr);
}
this.inputPrice = inputPrice;
this.inputPhone = inputPhone;
this.tds = td;
const myThis = this;
}
}
class MyTableBlackSheetWeight extends HTMLDivElement {
constructor() {
super();
let root = this;
let zoomStatus = "none";
let tables = [];
let resized = false;
let myData = null;
const myThFields = ["نام محصول", "تولیدکننده", "حالت", "ابعاد(m)", "ضخامت", "استاندارد", "وزن"];
const myThOrder = ["name", "producer", "state", "size", "thickness", "analysis", "weight"];
const myThFieldsZoom = ["نام محصول", "تولیدکننده", "وزن"];
const myThOrderZoom = ["name", "producer", "weight"];
root.style.backgroundColor = colorless;
root.style.display = "flex";
root.style.flexDirection = "column";
window.addEventListener("resize", function () {
resized = true;
});
window.dispatchEvent(new Event("resize"));
setInterval(function () {
if (resized) {
resized = false;
if (zoom) {
if (zoomStatus === "none" || zoomStatus === "default" || (myData !== null && tables.length === 0)) {
createTables();
}
zoomStatus = "zoom";
zoomStyle();
} else if (!zoom) {
if (zoomStatus === "none" || zoomStatus === "zoom" || (myData !== null && tables.length === 0)) {
createTables();
}
zoomStatus = "default";
defaultStyle();
}
}
}, 200);
function zoomStyle() {
if (tables.length !== 0) {
for (let i = 0; i < tables.length; i++) {
tables[i].style.width = percent(90);
tables[i].style.marginBottom = "0.5cm";
tables[i].style.marginRight = tables[i].style.marginLeft = "auto";
}
}
}
function defaultStyle() {
if (tables.length !== 0) {
for (let i = 0; i < tables.length; i++) {
tables[i].style.width = "96%";
tables[i].style.marginBottom = "1cm";
tables[i].style.marginRight = tables[i].style.marginLeft = "auto";
}
}
}
function createTables() {
if (myData !== null && myData["result"] === "ok") {
for (let i = 0; i < tables.length; i++) {
tables[i].remove();
}
if (zoom) {
for (let i = 0; i < myData["products"].length; i++) {
tables[i] = new MyPrivateBlackSheetWeight(myThFieldsZoom, myThOrderZoom, myData["products"][i]);
root.appendChild(tables[i]);
}
} else {
for (let i = 0; i < myData["products"].length; i++) {
tables[i] = new MyPrivateBlackSheetWeight(myThFields, myThOrder, myData["products"][i]);
root.appendChild(tables[i]);
}
}
fixTables1Header(tables);
}
}
const sendData = new FormData();
sendData.append("kind1", "sheet");
sendData.append("kind2", "black");
sendData.append("producers", JSON.stringify([]));
sendData.append("skip", "0");
sendData.append("take", "10000");
const xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (this.readyState === 4 && this.status === 200) {
myData = JSON.parse(this.responseText);
if (myData['result'] === 'ok') {
window.dispatchEvent(new Event("resize"));
}
}
};
xhr.open("POST", apiGetProductsSkipTake, true);
xhr.send(sendData);
}
}
class MyPrivateBlackSheetWeight extends HTMLDivElement {
constructor(fields, fieldsOrder, rows) {
super();
this.style.backgroundColor = colorless;
this.style.display = "flex";
this.style.flexDirection = "column";
const h3Title = document.createElement("h3");
h3Title.innerHTML = "وزن " + rows['kind2Name'] + " " + rows['producer'];
h3Title.style.fontSize = sizeText2;
h3Title.style.margin = "0cm";
h3Title.style.padding = "0cm";
h3Title.style.fontWeight = "bold";
h3Title.style.fontFamily = "fontface1";
h3Title.style.color = "#0051ff";
this.appendChild(h3Title);
this.h2Title = h3Title;
const table = document.createElement("table");
table.style.width = "100%";
table.style.borderCollapse = "separate";
table.style.borderSpacing = "0";
table.style.marginTop = "0.2cm";
table.style.boxShadow = "3px 3px 10px #00000077";
table.style.borderRadius = "0.5cm";
this.appendChild(table);
const fieldsCount = fields.length;
const rowsCount = rows['data'].length;
const tr = document.createElement("tr");
tr.style.width = "100%";
this.headerTR = tr;
let i = 0
for (; i < fieldsCount; i++) {
const th = document.createElement("th");
th.style.fontFamily = "fontface2";
th.style.fontWeight = "bold";
th.style.fontSize = "0.38cm";
th.style.padding = "0.2cm";
th.style.textAlign = "center";
th.style.border = "1px solid #ffffff55";
th.style.color = "#ffffff";
th.style.backgroundColor = colorHeaderBackground1;
th.innerHTML = fields[i];
tr.appendChild(th);
}
table.appendChild(tr);
for (let i = 0; i < rowsCount; i++) {
const tr = document.createElement("tr");
tr.style.width = "100%";
setHoverAnimationOpacity(tr, 1, 0.7);
for (let j = 0; j < fieldsCount; j++) {
const td = document.createElement("td");
td.style.fontFamily = "fontface1";
td.style.fontWeight = "normal";
td.style.fontSize = "0.35cm";
td.style.paddingLeft = td.style.paddingRight = "0.2cm";
td.style.paddingTop = td.style.paddingBottom = "0cm";
td.style.textAlign = "center";
td.style.border = "1px solid #00000011";
td.style.color = "#000000";
let text;
if (fieldsOrder[j] === "name") {
text = "وزن " + rows['kind2Name'] + " ضخامت " + getPersianDigit(rows['data'][i]["thickness"]).replace(".", "/") + " " + rows['data'][i]["state"] +
" " + rows['data'][i]["type"] + (rows['data'][i]["state"] === "رول" ? (" عرض " + getPersianDigit(rows['data'][i]["size"]).replace(".", "/")) :
(" سایز " + getPersianDigit(rows['data'][i]["size"].replace(".", "/")) + " در " + getPersianDigit(rows['data'][i]["length"]).replace(".", "/")));
td.style.textAlign = "start";
} else {
text = rows['data'][i][fieldsOrder[j]];
if (fieldsOrder[j] === "size" || fieldsOrder[j] === "thickness") {
text = getPersianDigit(text);
}
if (fieldsOrder[j] === "size") {
td.style.direction = "ltr";
if (rows['data'][i]["state"] === "رول") {
text = 'عرض ' + text;
} else {
text = text + " × " + getPersianDigit(rows['data'][i]["length"]);
}
}
if (fieldsOrder[j] === "thickness" || fieldsOrder[j] === "size") {
td.style.direction = "ltr";
}
if (fieldsOrder[j] === "weight") {
td.style.direction = "rtl";
td.style.fontSize = "0.45cm";
td.style.fontWeight = "bold";
text = getPersianDigit(text) + ' کیلوگرم';
}
if (fieldsOrder[j] === "thickness" || fieldsOrder[j] === "size") {
text = text.replace(".", "/");
}
}
td.innerHTML = text;
tr.appendChild(td);
}
table.appendChild(tr);
}
}
}
function TableToolsZoomStyle(div, defaultTables, zoomTables) {
for (let i = 0; i < defaultTables.length; i++) {
div.style.marginLeft = "2%";
div.style.marginRight = "2%";
div.style.width = "96%";
defaultTables[i].remove();
zoomTables[i].style.width = div.style.width;
zoomTables[i].style.fontSize = sizeText1;
div.appendChild(zoomTables[i]);
}
}
function TableToolsDefaultStyle(div, defaultTables, zoomTables) {
for (let i = 0; i < defaultTables.length; i++) {
div.style.marginLeft = "auto";
div.style.marginRight = "auto";
div.style.width = headerWidth;
zoomTables[i].remove();
defaultTables[i].style.width = div.style.width;
defaultTables[i].style.fontSize = sizeText2;
div.appendChild(defaultTables[i]);
}
}
function loadTableCorners() {
const tableRadius = "0.5cm";
if (htmlDir() === "rtl") {
style.textContent += "tr:nth-child(even) {background-color: " + colorHeaderBackground11 + ";}" +
"th {" +
"position: -webkit-sticky;" +
"position: sticky;" +
// "top: 2cm;" +
"z-index: 3;" +
"}" +
"th:first-of-type {border-top-right-radius: " + tableRadius + ";}" +
"th:last-of-type {border-top-left-radius: " + tableRadius + ";}" +
"tr:last-child td:first-child {border-bottom-right-radius: " + tableRadius + ";}" +
"tr:last-child td:last-child {border-bottom-left-radius: " + tableRadius + ";}";
} else if (htmlDir() === "ltr") {
style.textContent += "tr:nth-child(even) {background-color: " + colorHeaderBackground11 + ";}" +
"th {" +
"position: -webkit-sticky;" +
"position: sticky;" +
// "top: 2cm;" +
"z-index: 6;" +
"}" +
"th:first-of-type {border-top-left-radius: " + tableRadius + ";}" +
"th:last-of-type {border-top-right-radius: " + tableRadius + ";}" +
"tr:last-child td:first-child {border-bottom-left-radius: " + tableRadius + ";}" +
"tr:last-child td:last-child {border-bottom-right-radius: " + tableRadius + ";}";
}
}
function fixTables1Header(tables) {
for (let i = 0; i < tables.length; i++) {
tables[i].headerTR.style.position = "sticky";
tables[i].headerTR.style.overflowY = "auto";
tables[i].headerTR.style.top = zoom ? "2.2cm" : "2.45cm";
}
fixTablesHeader(tables);
}
function fixTables3Header(tables) {
for (let i = 0; i < tables.length; i++) {
tables.childNodes[i].headerTR.style.position = "sticky";
tables.childNodes[i].headerTR.style.overflowY = "auto";
tables.childNodes[i].headerTR.style.top = zoom ? "2.2cm" : "2.45cm";
}
fixTablesHeader(tables);
}
function fixTablesHeader(tables) {
let scrolling = false;
window.addEventListener("scroll", function (event) {
scrolling = true;
});
setInterval(function () {
if (scrolling) {
scrolling = false;
let i = 0, j = 0;
for (; i < tables.length; i++) {
const topY = tables[i].getBoundingClientRect().top + tables[i].h2Title.clientHeight - 100;
const bottomY = tables[i].getBoundingClientRect().bottom + tables[i].h2Title.clientHeight - 100;
if (topY < 0 && bottomY > 0) {
if (!zoom) {
header.divGold.style.display = "none";
header.style.height = "2.5cm";
} else {
headerZoom.divGoldZoom.style.display = "none";
headerZoom.style.height = "2.5cm";
}
break;
}
}
if (i === tables.length) {
if (!zoom) {
header.divGold.style.display = "flex";
header.style.height = "3cm";
} else {
headerZoom.divGoldZoom.style.display = "flex";
headerZoom.style.height = "3cm";
}
}
}
}, 200);
}
function createProductName(td, row) {
let text;
if (row['kind1'] === 'sheet') {
if (row['kind2'] === 'black') {
text = "قیمت ورق " + row["type"] + "" + " ضخامت " + row["thickness"] + " " + row["state"] + " " + row["analysis"] +
(row["state"] === "رول" ? (" عرض " + row["size"]) : (" سایز " + row["size"] + " × " + row["length"]));
} else if (row['kind2'] === 'color') {
text = 'قیمت ورق ' + row["type"] + "" + " ضخامت " + row["thickness"] + " " + row["state"] + " " + row["analysis"] +
(row["state"] === "رول" ? (" عرض " + row["size"]) : (" سایز " + row["size"] + " × " + row["length"]));
} else if (row['kind2'] === 'oil') {
text = "قیمت ورق " + row["type"] + "" + " ضخامت " + row["thickness"] + " " + row["state"] +
(row["state"] === "رول" ? (" عرض " + row["size"]) : (" سایز " + row["size"] + " × " + row["length"]));
} else if (row['kind2'] === 'galvanized') {
text = "قیمت ورق " + row["type"] + "" + " ضخامت " + row["thickness"] + " " + row["state"] +
(row["state"] === "رول" ? (" عرض " + row["size"]) : (" سایز " + row["size"] + " × " + row["length"]));
} else if (row['kind2'] === 'chequer') {
text = "قیمت ورق " + row["type"] + "" + " ضخامت " + row["thickness"] + " " + row["state"] +
(row["state"] === "رول" ? (" عرض " + row["size"]) : (" سایز " + row["size"] + " × " + row["length"])) + ' ' + row['analysis'];
} else if (row['kind2'] === 'steel') {
text = "قیمت ورق " + row["type"] + "" + " ضخامت " + row["thickness"] + " " + row["state"] + " " + row['analysis'] +
(row["state"] === "رول" ? (" عرض " + row["size"]) : (" سایز " + row["size"] + " × " + row["length"]));
} else if (row['kind2'] === 'acidWash') {
text = "قیمت ورق " + row["type"] + "" + " ضخامت " + row["thickness"] + " " + row["state"] + " " + row['analysis'] +
(row["state"] === "رول" ? (" عرض " + row["size"]) : (" سایز " + row["size"] + " × " + row["length"]));
} else if (row['kind2'] === 'aluminium') {
text = "قیمت ورق " + row["type"] + "" + " ضخامت " + row["thickness"] + " " + row["state"] +
(row["state"] === "رول" ? (" عرض " + row["size"]) : (" سایز " + row["size"] + " × " + row["length"]));
}
} else if (row['kind1'] === 'rebar') {
text = "قیمت میلگرد " + row["type"] + "" + " سایز " + row["size"] + " " + row["state"] + " " +
(row["state"] === "شاخه" ? (row["length"] + " متری ") : "") + "آنالیز " + row["analysis"];
} else if (row['kind1'] === 'girder') {
text = "قیمت تیرآهن " + row["type"] + "" + " سایز " + row["size"] + " " + row["state"] + " " + row["length"] + " متری";
} else if (row['kind1'] === 'profile') {
if (row['kind2'] === 'column') {
text = "قیمت پروفیل " + row["type"] + "" + " ضخامت " + row["thickness"] + " سایز " + row["size"] + "×" + row["analysis"] + " شاخه " + row["length"] + " متری";
} else if (row['kind2'] === 'industrial' || row['kind2'] === 'furniture' || row['kind2'] === 'structural') {
text = "قیمت پروفیل " + row["type"] + "" + " ضخامت " + row["thickness"] + " سایز " + row["size"] + "×" + row["analysis"] + " شاخه " + row["length"] + " متری";
} else if (row['kind2'] === 'z') {
text = "قیمت پروفیل " + row["type"] + "" + " ضخامت " + row["thickness"] + " سایز " + row["size"] + " شاخه " + row["length"] + " متری";
}
} else if (row['kind1'] === 'pipe') {
const pointPos = String(row['size']).indexOf('/');
let size = '';
if (row['kind2'] === 'furniture') {
size = row['size'] + ' میلیمتر';
} else if (pointPos === -1) {
size = row['size'] + " اینچ";
} else {
const intPart = row['size'].substring(0, pointPos);
const decPart = row['size'].substring(pointPos + 1);
size = (decPart === '25' ? '1/4' : (decPart === '5' ? '1/2' : '3/4')) + (intPart === '0' ? '' : (' - ' + intPart)) + ' اینچ';
}
text = "قیمت لوله " + row["type"] + "" + " سایز " + size + " ضخامت " + row["thickness"] + " شاخه " + row["length"] + " متری";
}
else if (row['kind1'] === 'corner') {
text = "قیمت نبشی " + row["type"] + "" + " سایز " + row['thickness'] + '×' + row["size"] + "×" + row["size"] +
" شاخه " + row["length"] + " متری آنالیز " + row["analysis"];
} else if (row['kind1'] === 'stud') {
text = "قیمت ناودانی " + row["type"] + "" + " سایز " + row['length'] + '000 × ' + row["size"];
} else if (row['kind1'] === 'wire') {
if (row['kind2'] === 'barbed') {
text = 'قیمت مفتولی خاردار ' + "" + row['state'] + ' ' + row['type'] + (row['state'] === 'حلقوی' ? (' قطر ' + row['size']) : '') + (row['analysis'] === '' ? '' : (' ' + row['analysis']));
} else if (row['kind2'] === 'lace') {
text = 'قیمت مفتولی توری ' + "" + row['type'] + ' ضخامت ' + row['thickness'] + ' سایز ' + row['size'] + '×' + row['length'];
} else if (row['kind2'] === 'fencePost') {
text = 'قیمت مفتولی تیرحصار ' + "" + row['type'] + ' قطر ' + row['thickness'] + ' طول ' + row['size'] + ' متر';
} else if (row['kind2'] === 'wired') {
text = 'قیمت سیم مفتولی ' + "" + row['type'] + ' قطر ' + row['size'] + ' ' + row['state'];
}
}
td.style.textAlign = "start";
return {'text': text, 'td': td};
}