Advertisement
Aleksandr37rus

Untitled

Oct 10th, 2022
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $(document).ready(function(){function e(e){for(var t in e){var n=e[t]||[];if(!(n.length<=1)){var o=function(e){return e.reduce(function(e,t){var n=Number($(t).find('.js-table-input[data-type="quantity"]').val().trim())||1;return e+n},0)}(n),r=n.slice(1,n.length);$(n[0]).attr("data-quantity",o).find('.js-table-input[data-type="quantity"]').val(o),function(e){e.forEach(function(e){$(e).remove()})}(r)}}}function t(e,t){for(var n in t){var o="";t[n].forEach(function(e){o+=N(n,e.clientCode,e.vendorCode,e.code,e.uoms,e.link,e.description,e.quantity,e.balance,e.outOfStock,e.multiplicity,e.analyticalCategory,e.selectedUomCode,e.hasError,e.hasEqualCodes,e.id,e.errorMsg,e.etmCode)}),e.eq(--n).replaceWith(o)}initStyleElement();var r=de.find(".js-table-row");y(),X.show(),d(),c(r)}function n(e,t){return e.filter('[data-type="'+t+'"]')}function o(e){return e?e.replace(/\D/g,""):null}function r(){return $(window).width()}function a(e){e<768?(R.show(),W.hide(),D.hide(),M.hide()):(R.hide(),W.show(),D.show(),M.show())}function l(e){return null===e?"":++e||""}function i(e,t){de.append(function(e,t){var n="";for(var o in e){e[o].forEach(function(e){n+=N(++t,e.clientCode,e.vendorCode,e.code,e.uoms,e.link,e.description,e.quantity,e.balance,e.outOfStock,e.multiplicity,e.analyticalCategory,e.selectedUomCode,e.hasError,e.hasEqualCodes,e.id,e.errorMsg,e.etmCode)})}return n}(e,t)),initStyleElement();var n=de.find(".js-table-row");y(),X.show(),d(),c(n)}function c(e){var t=e.filter('[data-equal-codes="true"]'),n="",o={};t.length?(t.each(function(e,t){var n=$(t).attr("data-error-msg");o[n]=""}),Object.keys(o).forEach(function(e){n+=function(e){return'<div class="alerts__warnings-item alerts__warnings-item_dec">'+e+"</div>"}(e)}),le.html(n),ae.show()):ae.hide()}function d(){var e=s();re.empty(),e.length?(!function(e){var t="";$(e).each(function(e,n){var o=$(n),r=o.find(".js-table-number-row").text(),a=function(e){if(!e.includes("Снятый"))return e;var t=e.split(".");return t[0]+t[1]}(o.attr("data-error-msg"));t+=function(e,t){return'<div data-number-row="'+e+'" class="js-alerts-error-row alerts__errors-item alerts__errors-item_dec"><span class="alerts__errors-number-row alerts__errors-number-row_dec">Строка <span class="js-alert-error-number-row">'+e+'</span> : </span><span class="alerts__errors-text alerts__errors-text_dec"> '+t+"</span></div>"}(r,a)}),re.append(t)}(e),oe.show()):oe.hide()}function s(){return de.find('.js-table-row[data-has-error="true"]')}function u(e){$(e).button("loading")}function f(e){$(e).button("reset")}function m(e,t){var n=e.split(/\n/g),o=de.find(".js-table-row").length,r=[];return n.forEach(function(e){var n=function(e,t){var n=/\t+/g,o=/\s+/g;if(b(e,n))return _(e,n,t);if(b(e,o))return _(e,o,t);return function(e,t){var n={};return n[t]=e,n}(e,t)}(e.trim(),t);r.push(T(++o,n.code,n.clientCode,n.vendorCode,n.etmCode,null,n.quantity))}),r}function b(e,t){return null!==e.match(t)}function _(e,t,n){var o=e.split(t),r=function(e){return e.length}(o),a=o[r-1],l={};return 2!==r||O(o[1])?2===r?(l[n]=o[0],l.quantity=o[1],l):o.length>2&&!O(a)?(l[n]=o.join(" "),l.quantity="1",l):(o.length>2&&O(a)&&(l[n]=o.slice(0,r-1).join(" "),l.quantity=a),l):(l[n]=o.join(" "),l.quantity="1",l)}function h(e){var t=[];return e.each(function(e,n){t.push(function(e){var t=e.attr("data-number-row")||null,n=e.attr("data-code")||null,o=e.attr("data-client-code")||null,r=e.attr("data-vendor-code")||null,a=e.attr("data-etm-code")||null,l=e.attr("data-uom-id")||null,i=e.attr("data-quantity")||null;return T(t,n,o,r,a,l,i)}($(n)))}),t}function w(e){return e.find(".js-table-checkbox:checked").closest(".js-table-row")}function p(e){var t=0;e.find(".js-table-number-row").text(function(n,o){var r=e.eq(n),a=++t;return r.attr("data-number-row",a),a})}function v(e){return $(e).length}function j(e,t){return"Заказной"===t&&function(e){return e&&1!==Number(e)}(e)?e:""}function y(){return v(de.find(".js-table-row"))===v(de.find(".js-table-checkbox:checked"))?ce.prop("checked",!0):ce.prop("checked",!1)}function g(e,t){return e?e.length>1?function(e,t){return'<label class="table__row-label table__row-label_dec"><select data-type="active" class="js-select-box js-styled-select SumoUnder" tabindex="-1">'+k(e,t)+"</select></label>"}(e,t):function(e){return'<label class="table__row-label table__row-label_dec"><select disabled class="js-styled-select SumoUnder" tabindex="-1">'+k(e)+"</select></label>"}(e):""}function C(e){return e||""}function k(e,t){var n="";return e.forEach(function(e){var o=t===e.uomCode;n+=function(e,t,n){if(n)return'<option selected data-code="'+e+'">'+t+"</option>";return'<option data-code="'+e+'">'+t+"</option>"}(e.uomCode,e.uomName,o)}),n}function x(e,t){return'<label class="table__row-label  table__row-label_dec"><input data-type="'+t+'" type="text" value="'+C(e)+'" class="js-table-input table__row-input table__row-input_dec"></label>'}function q(e,t){be.showMsg(e,t)}function S(){$("#resultPreloader").hide()}function E(){$("#resultPreloader").show()}function O(e){return console.log(e),!isNaN(parseFloat(e))&&isFinite(e)&&!~e.indexOf("-")&&!~e.indexOf("+")}function P(e){return e.startsWith("<!DOCTYPE")}function N(e,t,n,o,r,a,l,i,c,d,s,u,f,m,b,_,h,w){return'<tr data-number-row="'+e+'" data-has-error="'+C(m)+'" data-quantity="'+C(i)+'"  data-uom-id="'+C(f)+'" data-product-id="'+C(_)+'" data-equal-codes="'+C(b)+'" data-etm-code="'+C(w)+'" data-code="'+C(o)+'" data-client-code="'+C(t)+'" data-vendor-code="'+C(n)+"\" data-error-msg='"+C(h)+"' class=\"js-table-row row table__row table__row_dec "+function(e,t){return e?e?"danger":"":t?"info":""}(m,b)+'"><td class="js-table-number-row col-sm-1 col-md-1 table__row-item table__row-item_dec">'+e+'</td><td class="col-sm-1 col-md-1 table__row-item table__row-item_dec"><label class="check table__row-label-checkbox  table__row-label-checkbox_dec"><input checked type="checkbox" class="js-table-checkbox table__row-checkbox table__row-checkbox_dec"><span></span></label></td><td class="col-sm-1 col-md-1 table__row-item table__row-item_dec">'+x(t,"client-code")+'</td><td class="col-sm-1 col-md-1 table__row-item table__row-item_dec">'+x(n,"vendor-code")+'</td><td class="col-sm-1 col-md-1 table__row-item table__row-item_dec">'+x(o,"code")+'</td><td class="col-sm-1 col-md-1 table__row-item table__row-item_dec">'+x(w,"etm-code")+'</td><td class="js-table-selectbox col-sm-1 col-md-1 table__row-item table__row-item_dec">'+g(r,f)+'</td><td class="col-sm-2 col-md-2 table__row-item table__row-item_dec"><div class="js-table-link table__row-link-wrap table__row-link-wrap_dec">'+function(e,t){return e&&t?'<a target="_blank" href="'+me+e+'" title="'+t+'" class="table__row-link table__row-link_dec">'+t+"</a>":""}(a,l)+'</div></td><td class="col-sm-1 col-md-1 table__row-item table__row-item_dec">'+x(i,"quantity")+"</td>"+("N"===d?'<td class="js-table-balance col-sm-1 col-md-1 table__row-item table__row-item_dec" colspan="2" style="font-weight: bold; font-size: 16px;">Нет в продаже</td>':'<td class="js-table-balance col-sm-1 col-md-1 table__row-item table__row-item_dec">'+function(e){return e>=0?e:""}(c)+'</td><td class="js-table-multiplicity col-sm-1 col-md-1 table__row-item table__row-item_dec">'+j(s,u)+"</td>")+'<td class="col-sm-1 col-md-1 table__row-item table__row-item_dec"><button type="button" class="js-table-delete-row table__row-icon table__row-icon_dec">&#x75;</button></td></tr>'}function T(e,t,n,o,r,a,l){var i=l||1;return n?{numberRow:e,code:null,clientCode:n,vendorCode:null,etmCode:null,selectedUomCode:a,quantity:i}:t?{numberRow:e,code:t,clientCode:null,vendorCode:null,etmCode:null,selectedUomCode:a,quantity:i}:o?{numberRow:e,code:null,clientCode:null,vendorCode:o,etmCode:null,selectedUomCode:a,quantity:i}:r?{numberRow:e,code:null,clientCode:null,vendorCode:null,etmCode:r,selectedUomCode:a,quantity:i}:{numberRow:e,code:null,clientCode:null,vendorCode:null,etmCode:null,selectedUomCode:a,quantity:i}}function F(e){return new Promise(function(t,n){$.ajax({method:"POST",url:"/positionEntrySearchItem",data:"items="+JSON.stringify(e),success:function(e){t(tryParseJSON(e))},error:function(e){n(e)}})})}var J="user-form_active",U="Не выбрано ни одной позиции. Выберите позиции с помощью галочек.",M=$("#main"),R=$("#mobileContent"),D=$("#switcher"),I=D.find(".switcher__item"),W=$("#headline"),A=W.find(".headline__buttons-wrap"),L=W.find('.js-headline-buttons[data-type="parseFile"]'),z=$("#userForm"),B=z.find(".js-user-form"),Y=z.find('.js-user-form[data-type="file"]'),H=Y.find(".js-input-columns"),G=function(e){return JSON.parse(localStorage.getItem(e))}("latestColumns")||!1,K=z.find('.js-user-form[data-type="clipboard"]'),Q=K.find(".js-send-clipboard-values"),V=z.find(".js-clipboard-input"),X=$("#tableWrap"),Z=X.find(".js-add-to-cart"),ee=X.find(".js-main-delete"),te=X.find(".js-check-item"),ne=X.find("#alert"),oe=ne.find(".js-alert-error"),re=oe.find(".js-alert-error-list"),ae=ne.find(".js-alert-warning"),le=ae.find(".js-alert-warning-list"),ie=$("#table"),ce=ie.find(".js-table-header").find(".js-main-checkbox"),de=ie.find(".js-table-body"),se=$("#loadFileModal"),ue=se.find(".js-load"),fe=se.find("#inputFile"),me=$("#pageContextPath").val(),be={hidePreloader:function(e){$(e).preloader("hide")},showPreloader:function(e,t){$(e).preloader({overlayBackground:"rgba(255, 255, 255, .6)",showOverlay:!0,contentsWidth:t+"px",contentsHtml:'<img src=" '+changeStaticLink($("#constantEndecaPath").val()+"/static/img/assets/product-card/preloader.gif")+' " class="preloader__image" alt="" role="presentation">',delay:0})},showMsg:function(e,t,n){var o=$("#cartModal");$("#cartBody").html(e),$("#cartTitle").text("Предупреждение"),o.attr("data-type",n),o.modal(),setTimeout(function(){$("#cartModal").modal("hide")},1e4)}};if(a(r()),G){var _e=l(G.etmCode),he=l(G.code),we=l(G.clientCode),pe=l(G.vendorCode),ve=l(G.quantity);n(H,"code").val(he),n(H,"etm-code").val(_e),n(H,"client-code").val(we),n(H,"vendor-code").val(pe),n(H,"quantity").val(ve)}I.on("click",function(){var e=$(this),t=e.attr("data-type");e.hasClass("switcher__item_active")||(e.addClass("switcher__item_active").siblings().removeClass("switcher__item_active"),A.fadeToggle(160),function(e){B.removeClass(J),z.find(".js-user-form[data-type="+e+"]").addClass(J)}(t))}),L.on("click",function(){0===Y.find(".js-input-columns.border-red").length?$("#loadFileModal").modal("show"):q("Исправьте порядок колонок","Предупреждение")}),ue.on("click",function(){var e=fe.prop("files")[0],t=n(H,"code").val().trim(),o=n(H,"etm-code").val().trim(),r=n(H,"client-code").val().trim(),a=n(H,"vendor-code").val().trim(),l=function(e,t,n,o,r){return{code:e?--e:null,etmCode:t?--t:null,clientCode:n?--n:null,vendorCode:o?--o:null,quantity:r?--r:null}}(t,o,r,a,n(H,"quantity").val().trim()),c=s(),d=++de.find(".js-table-row").length;t||r||a||o?!function(e){var t=function(e){var t=[];for(var n in e)t.push(e[n]);return t}(e);return t.some(function(e){return null!==e&&t.indexOf(e)!==t.lastIndexOf(e)})}(l)?(!function(e,t){localStorage.setItem(e,JSON.stringify(t))}("latestColumns",l),u(L),E(),function(e,t,n){return new Promise(function(o,r){var a=new FormData;a.append("columns",JSON.stringify(t)),a.append("file",e),a.append("startNumberRow",JSON.stringify(n)),$.ajax({method:"POST",url:"/positionEntryFile",processData:!1,contentType:!1,enctype:"multipart/form-data",data:a,success:function(e){o(tryParseJSON(e))},error:function(e){r(e)}})})}(e,l,d).then(function(e){if(e.error){var t=e.message;P(t)?q("При отправке файла произошла ошибка! Попробуйте позднее или обратитесь в поддержку.","Предупреждение"):q(t,"Предупреждение"),S(),f(L)}else{var n=de.find(".js-table-row").length;c.length===n&&de.empty();i(e.items,n),f(L),S()}},function(e){var t=e.responseText;P(t)?q("При отправке файла произошла ошибка! Попробуйте позднее или обратитесь в поддержку.","Предупреждение"):q(t,"Предупреждение"),S(),f(L)})):q("Несколько одинаковых значений не могут находиться в одном столбце.","Предупреждение"):q("Укажите номер столбца для поиска товара.","Предупреждение")}),$(".js-merge-lines").on("click",function(){e(function(e){return e.toArray().reduce(function(e,t){var n=$(t).attr("data-code"),o=e[n];return o?o.push(t):e[n]=[t],e},{})}(de.find(".js-table-row")));var t=de.find(".js-table-row");p(t),c(t)}),fe.on("change",function(){$(this).prop("files")[0]?ue.prop("disabled",!1):ue.prop("disabled",!0)}),ce.on("change",function(){(function(e){return $(e).prop("checked")})(this)?de.find(".js-table-checkbox:not(:checked)").prop("checked",!0):de.find(".js-table-checkbox:checked").prop("checked",!1)}),ee.on("click",function(){var e=de.find(".js-table-row"),t=w(e);t.length?(t.remove(),(e=de.find(".js-table-row")).length||X.hide(),p(e),d(),c(e)):q(U,"Предупреждение")}),Z.on("click",function(){var e=de.find(".js-table-row"),n=w(e),o=n.length,r=h(n);o?o>500?q("Число добавляемых позиций не может превышать 500","Предупреждение"):(E(),function(e){return new Promise(function(t,n){$.ajax({method:"POST",url:"/positionEntryAddToCart",data:"items="+JSON.stringify(e),success:function(e){t(tryParseJSON(e))},error:function(e){n(e)}})})}(r).then(function(n){var o=n.success,r=n.error||"При добавлении в корзину произошла ошибка! Попробуйте позднее или обратитесь в поддержку.",a=n.data;if(S(),!o)return a?void t(e,a):void q(r,"Предупреждение");var l=a||{},i=[];for(var c in l){l[c].forEach(function(e){i.push(buildYaProduct(e.id,validateStringLength(e.description,50),0,e.brand,e.quantity))})}pushElementToDataLayerForAddingElements(i),window.location.href=me+"/cart.htm"})):q(U,"Предупреждение")}),te.on("click",function(){var e=w(de.find(".js-table-row")),n=h(e),o=function(e){var t=[];return e.forEach(function(e){null===e.code&&null===e.clientCode&&null===e.vendorCode&&null===e.etmCode&&t.push(e.numberRow)}),t}(n);e.length?o.length?q(function(e){var t="";return e.forEach(function(e){t+=function(e){return"<div>Строка "+e+" : Укажите хотя бы 1 столбец для проверки позиции.</div>"}(e)}),t}(o),"Предупреждение"):(E(),F(n).then(function(e){if(e.error){S();var n=e.message;P(n)?q("При проверке позиций произошла ошибка! Попробуйте позднее или обратитесь в поддержку.","Предупреждение"):q(n,"Предупреждение")}else{t(de.find(".js-table-row"),e.items),p(de.find(".js-table-row")),S()}},function(e){S();var t=e.responseText;P(t)?q("При проверке позиций произошла ошибка! Попробуйте позднее или обратитесь в поддержку.","Предупреждение"):q(t,"Предупреждение")})):q(U,"Предупреждение")}),Q.on("click",function(){var e=V.val().trim(),t=K.find(".js-clipboard-radio:checked").attr("data-type"),n=de.find(".js-table-row"),o=s(),r=m(e,t);V.removeClass("border-red"),u(Q),E(),F(r).then(function(e){if(e.error){S();var t=e.message;P(t)?q("При проверке позиций произошла ошибка! Попробуйте позднее или обратитесь в поддержку.","Предупреждение"):q(t,"Предупреждение")}else{o.length===n.length&&de.empty();i(e.items,n.length),f(Q),S()}},function(e){S(),f(Q);var t=e.responseText;P(t)?q("При отправке позиций произошла ошибка! Попробуйте позднее или обратитесь в поддержку.","Предупреждение"):q(t,"Предупреждение")})}),de.on("change",".js-select-box",function(){var e=$(this),t=e.closest(".js-table-row"),n=e.find("option:selected").attr("data-code");t.attr("data-uom-id",n)}),de.on("change",".js-table-checkbox",function(){y()}),de.on("click",".js-table-delete-row",function(){$(this).closest(".js-table-row").remove();var e=de.find(".js-table-row");e.length||X.hide(),p(e),d(),c(e)}),Y.on("input",".js-input-columns",function(){var e=$(this),t=e.val();e.val(o(t))}),de.on("input",".js-table-input",function(){var e=$(this),t=e.attr("data-type"),n=e.closest(".js-table-row");"quantity"!==t&&"code"!==t||e.val(o(e.val())),n.attr("data-"+t,e.val())}),$(window).on("resize",function(){a(r())})});
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement