UNPKG

@apicart/vue-components

Version:

Apicart Vue.Js components for simple e-commerce platform development

8 lines (6 loc) 10.1 kB
/** * @apicart/vue-components v1.0.0-alpha7 * (c) 2018-2020 Apicart Company * Released under the MIT License. */ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("@apicart/core-sdk"),require("../.."),require("./..")):"function"==typeof define&&define.amd?define(["@apicart/core-sdk","../..","./.."],e):(t=t||self).ApicartShippingMethodsList=e(t.Apicart,t.src,t.components)}(this,(function(t,e,i){"use strict";function s(t,e,i,s){return new(i||(i=Promise))((function(n,o){function a(t){try{d(s.next(t))}catch(t){o(t)}}function p(t){try{d(s.throw(t))}catch(t){o(t)}}function d(t){var e;t.done?n(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(a,p)}d((s=s.apply(t,e||[])).next())}))}function n(t,e){var i,s,n,o,a={label:0,sent:function(){if(1&n[0])throw n[1];return n[1]},trys:[],ops:[]};return o={next:p(0),throw:p(1),return:p(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function p(o){return function(p){return function(o){if(i)throw new TypeError("Generator is already executing.");for(;a;)try{if(i=1,s&&(n=2&o[0]?s.return:o[0]?s.throw||((n=s.return)&&n.call(s),0):s.next)&&!(n=n.call(s,o[1])).done)return n;switch(s=0,n&&(o=[2&o[0],n.value]),o[0]){case 0:case 1:n=o;break;case 4:return a.label++,{value:o[1],done:!1};case 5:a.label++,s=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!(n=a.trys,(n=n.length>0&&n[n.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!n||o[1]>n[0]&&o[1]<n[3])){a.label=o[1];break}if(6===o[0]&&a.label<n[1]){a.label=n[1],n=o;break}if(n&&a.label<n[2]){a.label=n[2],a.ops.push(o);break}n[2]&&a.ops.pop(),a.trys.pop();continue}o=e.call(t,a)}catch(t){o=[6,t],s=0}finally{i=n=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,p])}}}var o,a=((t=t&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t).VueComponentsTranslator||e.Translator).getI18n(),p="undefined"!=typeof window,d={name:"apicart-shipping-methods-list",i18n:a,props:{loadingEnabled:{type:Boolean,default:!0}},components:{"apicart-loader":p&&window.ApicartLoader?window.ApicartLoader:i.ApicartLoader},data:function(){return{shippingMethods:[],shippingMethodsLoaded:!1,selectedShippingMethodIndex:null,selectedShippingMethod:null,allowedMethods:[],disabledMethods:[]}},watch:{loadingEnabled:function(){this.loadMethodsList()}},methods:{toggleShippingMethod:function(t){return s(this,void 0,void 0,(function(){return n(this,(function(e){switch(e.label){case 0:return this.selectedShippingMethodIndex=t,this.selectedShippingMethod=this.shippingMethods[t],[4,o.getCart()];case 1:return e.sent().addParameter("shippingMethod",{id:this.selectedShippingMethod.getId()}),this.$emit("shipping-method-updated",this.selectedShippingMethod),[2]}}))}))},loadMethodsList:function(){var e=this;this.loadingEnabled&&!this.shippingMethodsList&&o.getShippingMethods().then((function(i){return s(e,void 0,void 0,(function(){var e,s,a=this;return n(this,(function(n){switch(n.label){case 0:return this.shippingMethods=i.filter((function(t){var e=t.getUid(),i=!0;return a.allowedMethods.length&&-1===a.allowedMethods.indexOf(e)&&(i=!1),a.disabledMethods.length&&a.disabledMethods.indexOf(e)>-1&&(i=!1),i})),this.shippingMethodsLoaded=!0,[4,o.getCart()];case 1:return[4,n.sent().getParameterValue("shippingMethod")];case 2:return e=n.sent(),(s=e?e.id:null)&&this.shippingMethods.length&&t.Utils.Loops.forEach(this.shippingMethods,(function(t,e){if(t.getId()===s)return a.selectedShippingMethodIndex=e,a.selectedShippingMethod=t,a.$emit("shipping-method-updated",a.selectedShippingMethod),!1})),[2]}}))}))}))}},mounted:function(){o=t.getConfigParameter("store");var e=t.getConfigParameter("vueComponents.shippingMethodsList");e&&(Array.isArray(e.allowedMethods)&&(this.allowedMethods=e.allowedMethods),Array.isArray(e.disabledMethods)&&(this.disabledMethods=e.disabledMethods)),this.loadMethodsList()}};!function(t,e){void 0===e&&(e={});var i=e.insertAt;if(t&&"undefined"!=typeof document){var s=document.head||document.getElementsByTagName("head")[0],n=document.createElement("style");n.type="text/css","top"===i&&s.firstChild?s.insertBefore(n,s.firstChild):s.appendChild(n),n.styleSheet?n.styleSheet.cssText=t:n.appendChild(document.createTextNode(t))}}('.apicart-shipping-methods-list{font-family:-apple-system,"Segoe UI",Roboto,Oxygen,Ubuntu,Cantarell,"Helvetica Neue",Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol";-webkit-font-smoothing:antialiased;box-sizing:border-box;outline:0}.apicart-shipping-methods-list *{box-sizing:border-box;outline:0}.apicart-shipping-methods-list{margin-bottom:20px;display:flex;flex-direction:column;width:100%;border:1px solid #e6e6e7;border-radius:2px}.apicart-shipping-methods-list__item{border-bottom:1px solid #e6e6e7;cursor:pointer;user-select:none;position:relative;padding:12px 12px 12px 0}.apicart-shipping-methods-list__item--no-methods-found{text-align:center;cursor:initial}.apicart-shipping-methods-list__item:last-of-type{border-bottom:0}.apicart-shipping-methods-list__item--selected .apicart-shipping-methods-list__item-description{display:block;padding-left:50px}.apicart-shipping-methods-list__item-header{display:flex;flex-direction:row;align-items:center}.apicart-shipping-methods-list__item-checkbox-wrapper{display:flex;position:relative;justify-content:center;padding:14px 26px;align-items:center}.apicart-shipping-methods-list__item-checkbox-input{display:none}.apicart-shipping-methods-list__item-checkbox-input-placeholder{position:absolute;display:inline-block;border:1px solid #e6e6e7;display:block;width:20px;height:20px;border-radius:100%;pointer-events:none;user-select:none;background-color:#e6e6e7;background-repeat:no-repeat;background-position:center center;background-size:90%;box-shadow:0;transition:background-color .3s}.apicart-shipping-methods-list__item-details-wrapper{display:flex;justify-content:space-between;width:100%;width:100%;align-items:center}.apicart-shipping-methods-list__item-details-name-image{display:flex;flex-direction:column;align-items:flex-start}@media (min-width:576px){.apicart-shipping-methods-list__item-details-name-image{flex-direction:row;align-items:center}}.apicart-shipping-methods-list__item-image{max-width:90px;margin-bottom:12px}@media (min-width:576px){.apicart-shipping-methods-list__item-image{margin-bottom:0;margin-right:20px}}.apicart-shipping-methods-list__item-name{font-size:12px}.apicart-shipping-methods-list__item-description{font-size:14px;line-height:1.5;padding-left:50px;color:#b3b3b3;overflow:hidden;height:auto;max-height:0;transition:max-height .3s,margin-top .3s;margin-top:0}.apicart-shipping-methods-list__item-description>:last-child{margin-bottom:0}.apicart-shipping-methods-list__item-details-price{font-size:18px;font-weight:500}.apicart-shipping-methods-list__item--selected .apicart-shipping-methods-list__item-description{max-height:100px;margin-top:8px;margin-top:8px}.apicart-shipping-methods-list__item--selected .apicart-shipping-methods-list__item-checkbox-input-placeholder{background-color:#121212}.apicart-shipping-methods-list--loading{padding:20px;text-align:center}.apicart-shipping-methods-list--loading p{margin-top:0}');return function(t,e,i,s,n,o,a,p,d,r){"boolean"!=typeof a&&(d=p,p=a,a=!1);const h="function"==typeof i?i.options:i;let l;if(t&&t.render&&(h.render=t.render,h.staticRenderFns=t.staticRenderFns,h._compiled=!0,n&&(h.functional=!0)),s&&(h._scopeId=s),o?(l=function(t){(t=t||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext)||"undefined"==typeof __VUE_SSR_CONTEXT__||(t=__VUE_SSR_CONTEXT__),e&&e.call(this,d(t)),t&&t._registeredComponents&&t._registeredComponents.add(o)},h._ssrRegister=l):e&&(l=a?function(t){e.call(this,r(t,this.$root.$options.shadowRoot))}:function(t){e.call(this,p(t))}),l)if(h.functional){const t=h.render;h.render=function(e,i){return l.call(i),t(e,i)}}else{const t=h.beforeCreate;h.beforeCreate=t?[].concat(t,l):[l]}return i}({render:function(){var t=this,e=t.$createElement,i=t._self._c||e;return t.shippingMethodsLoaded?i("div",{staticClass:"apicart-shipping-methods-list",attrs:{id:t.$t("shippingMethodsList.id")}},[t.shippingMethods.length?i("div",t._l(t.shippingMethods,(function(e,s){return i("div",{key:s,staticClass:"apicart-shipping-methods-list__item",class:{"apicart-shipping-methods-list__item--selected":s===t.selectedShippingMethodIndex},attrs:{"data-shipping-method-uid":e.getUid()},on:{click:function(e){return t.toggleShippingMethod(s)}}},[i("div",{staticClass:"apicart-shipping-methods-list__item-header"},[i("div",{staticClass:"apicart-shipping-methods-list__item-checkbox-wrapper"},[i("input",{staticClass:"apicart-shipping-methods-list__item-checkbox-input",attrs:{type:"radio",name:"shipping-method"},domProps:{checked:s===t.selectedShippingMethodIndex,value:s}}),i("div",{staticClass:"apicart-shipping-methods-list__item-checkbox-input-placeholder"})]),i("div",{staticClass:"apicart-shipping-methods-list__item-details-wrapper"},[i("div",{staticClass:"apicart-shipping-methods-list__item-details-name-image"},[e.getImage()?i("img",{staticClass:"apicart-shipping-methods-list__item-image",attrs:{src:e.getImage(),loading:"lazy",alt:""}}):t._e(),i("div",{staticClass:"apicart-shipping-methods-list__item-name"},[t._v(t._s(e.getName()))])]),i("div",{staticClass:"apicart-shipping-methods-list__item-details-price"},[t._v(" "+t._s(t.$n(e.getPrice(),"currency"))+" ")])])]),i("div",{staticClass:"apicart-shipping-methods-list__item-description apicart-shipping-methods-list__item-description--collapsed",domProps:{innerHTML:t._s(e.getDescription())}})])})),0):i("div",{staticClass:"apicart-shipping-methods-list__item apicart-shipping-methods-list__item--no-methods-found"},[t._v(" "+t._s(t.$t("shippingMethodsList.methodsNotFound"))+" ")])]):i("div",{staticClass:"apicart-shipping-methods-list apicart-shipping-methods-list--loading",attrs:{id:t.$t("shippingMethodsList.id")}},[i("apicart-loader",{attrs:{visible:!0}})],1)},staticRenderFns:[]},void 0,d,void 0,!1,void 0,!1,void 0,void 0,void 0)}));