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).ApicartPaymentMethodsList=e(t.Apicart,t.src,t.components)}(this,(function(t,e,i){"use strict";function a(t,e,i,a){return new(i||(i=Promise))((function(n,o){function s(t){try{r(a.next(t))}catch(t){o(t)}}function d(t){try{r(a.throw(t))}catch(t){o(t)}}function r(t){var e;t.done?n(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(s,d)}r((a=a.apply(t,e||[])).next())}))}function n(t,e){var i,a,n,o,s={label:0,sent:function(){if(1&n[0])throw n[1];return n[1]},trys:[],ops:[]};return o={next:d(0),throw:d(1),return:d(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function d(o){return function(d){return function(o){if(i)throw new TypeError("Generator is already executing.");for(;s;)try{if(i=1,a&&(n=2&o[0]?a.return:o[0]?a.throw||((n=a.return)&&n.call(a),0):a.next)&&!(n=n.call(a,o[1])).done)return n;switch(a=0,n&&(o=[2&o[0],n.value]),o[0]){case 0:case 1:n=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,a=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(n=s.trys,(n=n.length>0&&n[n.length-1])||6!==o[0]&&2!==o[0])){s=0;continue}if(3===o[0]&&(!n||o[1]>n[0]&&o[1]<n[3])){s.label=o[1];break}if(6===o[0]&&s.label<n[1]){s.label=n[1],n=o;break}if(n&&s.label<n[2]){s.label=n[2],s.ops.push(o);break}n[2]&&s.ops.pop(),s.trys.pop();continue}o=e.call(t,s)}catch(t){o=[6,t],a=0}finally{i=n=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,d])}}}var o,s=((t=t&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t).VueComponentsTranslator||e.Translator).getI18n(),d="undefined"!=typeof window,r={name:"apicart-payment-methods-list",i18n:s,props:{loadingEnabled:{type:Boolean,default:!0}},components:{"apicart-loader":d&&window.ApicartLoader?window.ApicartLoader:i.ApicartLoader},data:function(){return{paymentMethods:[],paymentMethodsLoaded:!1,selectedPaymentMethodIndex:null,selectedPaymentMethod:null,allowedMethods:[],disabledMethods:[]}},watch:{loadingEnabled:function(){this.loadMethodsList()}},methods:{togglePaymentMethod:function(t){return a(this,void 0,void 0,(function(){return n(this,(function(e){switch(e.label){case 0:return this.selectedPaymentMethodIndex=t,this.selectedPaymentMethod=this.paymentMethods[t],[4,o.getCart()];case 1:return e.sent().addParameter("paymentMethod",{id:this.selectedPaymentMethod.getId()}),this.$emit("payment-method-updated",this.selectedPaymentMethod),[2]}}))}))},loadMethodsList:function(){var e=this;this.loadingEnabled&&!this.paymentMethods.length&&o.getPaymentMethods().then((function(i){return a(e,void 0,void 0,(function(){var e,a,s=this;return n(this,(function(n){switch(n.label){case 0:return this.paymentMethods=i.filter((function(t){var e=t.getUid(),i=!0;return s.allowedMethods.length&&-1===s.allowedMethods.indexOf(e)&&(i=!1),s.disabledMethods.length&&s.disabledMethods.indexOf(e)>-1&&(i=!1),i})),this.paymentMethodsLoaded=!0,[4,o.getCart()];case 1:return[4,n.sent().getParameterValue("paymentMethod")];case 2:return e=n.sent(),(a=e?e.id:null)&&this.paymentMethods.length&&t.Utils.Loops.forEach(this.paymentMethods,(function(t,e){if(t.getId()===a)return s.selectedPaymentMethodIndex=e,s.selectedPaymentMethod=t,s.$emit("payment-method-updated",s.selectedPaymentMethod),!1})),[2]}}))}))}))}},mounted:function(){o=t.getConfigParameter("store");var e=t.getConfigParameter("vueComponents.paymentMethodsList");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 a=document.head||document.getElementsByTagName("head")[0],n=document.createElement("style");n.type="text/css","top"===i&&a.firstChild?a.insertBefore(n,a.firstChild):a.appendChild(n),n.styleSheet?n.styleSheet.cssText=t:n.appendChild(document.createTextNode(t))}}('.apicart-payment-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-payment-methods-list *{box-sizing:border-box;outline:0}.apicart-payment-methods-list{margin-bottom:20px;display:flex;flex-direction:column;width:100%;border:1px solid #e6e6e7;border-radius:2px}.apicart-payment-methods-list__item{border-bottom:1px solid #e6e6e7;cursor:pointer;user-select:none;position:relative;padding:12px 12px 12px 0}.apicart-payment-methods-list__item--no-methods-found{text-align:center;cursor:initial}.apicart-payment-methods-list__item:last-of-type{border-bottom:0}.apicart-payment-methods-list__item--selected .apicart-payment-methods-list__item-description{display:block;padding-left:50px}.apicart-payment-methods-list__item-header{display:flex;flex-direction:row;align-items:center}.apicart-payment-methods-list__item-checkbox-wrapper{display:flex;position:relative;justify-content:center;padding:14px 26px;align-items:center}.apicart-payment-methods-list__item-checkbox-input{display:none}.apicart-payment-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-payment-methods-list__item-details-wrapper{display:flex;justify-content:space-between;width:100%;width:100%;align-items:center}.apicart-payment-methods-list__item-details-name-image{display:flex;flex-direction:column;align-items:flex-start}@media (min-width:576px){.apicart-payment-methods-list__item-details-name-image{flex-direction:row;align-items:center}}.apicart-payment-methods-list__item-image{max-width:90px;margin-bottom:12px}@media (min-width:576px){.apicart-payment-methods-list__item-image{margin-bottom:0;margin-right:20px}}.apicart-payment-methods-list__item-name{font-size:12px}.apicart-payment-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-payment-methods-list__item-description>:last-child{margin-bottom:0}.apicart-payment-methods-list__item-details-price{font-size:18px;font-weight:500}.apicart-payment-methods-list__item--selected .apicart-payment-methods-list__item-description{max-height:100px;margin-top:8px;margin-top:8px}.apicart-payment-methods-list__item--selected .apicart-payment-methods-list__item-checkbox-input-placeholder{background-color:#121212}.apicart-payment-methods-list--loading{padding:20px;text-align:center}.apicart-payment-methods-list--loading p{margin-top:0}');return function(t,e,i,a,n,o,s,d,r,l){"boolean"!=typeof s&&(r=d,d=s,s=!1);const p="function"==typeof i?i.options:i;let c;if(t&&t.render&&(p.render=t.render,p.staticRenderFns=t.staticRenderFns,p._compiled=!0,n&&(p.functional=!0)),a&&(p._scopeId=a),o?(c=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,r(t)),t&&t._registeredComponents&&t._registeredComponents.add(o)},p._ssrRegister=c):e&&(c=s?function(t){e.call(this,l(t,this.$root.$options.shadowRoot))}:function(t){e.call(this,d(t))}),c)if(p.functional){const t=p.render;p.render=function(e,i){return c.call(i),t(e,i)}}else{const t=p.beforeCreate;p.beforeCreate=t?[].concat(t,c):[c]}return i}({render:function(){var t=this,e=t.$createElement,i=t._self._c||e;return t.paymentMethodsLoaded?i("div",{staticClass:"apicart-payment-methods-list",attrs:{id:t.$t("paymentMethodsList.id")}},[t.paymentMethods.length?i("div",t._l(t.paymentMethods,(function(e,a){return i("div",{key:a,staticClass:"apicart-payment-methods-list__item",class:{"apicart-payment-methods-list__item--selected":a===t.selectedPaymentMethodIndex},attrs:{"data-payment-method-uid":e.getUid(),"data-payment-method-id":e.getId()},on:{click:function(e){return t.togglePaymentMethod(a)}}},[i("div",{staticClass:"apicart-payment-methods-list__item-header"},[i("div",{staticClass:"apicart-payment-methods-list__item-checkbox-wrapper"},[i("input",{staticClass:"apicart-payment-methods-list__item-checkbox-input",attrs:{type:"radio",name:"payment-method"},domProps:{checked:a===t.selectedPaymentMethodIndex,value:a}}),i("div",{staticClass:"apicart-payment-methods-list__item-checkbox-input-placeholder"})]),i("div",{staticClass:"apicart-payment-methods-list__item-details-wrapper"},[i("div",{staticClass:"apicart-payment-methods-list__item-details-name-image"},[e.getImage()?i("img",{staticClass:"apicart-payment-methods-list__item-image",attrs:{src:e.getImage(),loading:"lazy",alt:""}}):t._e(),i("div",{staticClass:"apicart-payment-methods-list__item-name"},[t._v(t._s(e.getName()))])]),i("div",{staticClass:"apicart-payment-methods-list__item-details-price"},[t._v(" "+t._s(t.$n(e.getPrice(),"currency"))+" ")])])]),i("div",{staticClass:"apicart-payment-methods-list__item-description apicart-payment-methods-list__item-description--collapsed",domProps:{innerHTML:t._s(e.getDescription())}})])})),0):i("div",{staticClass:"apicart-payment-methods-list__item apicart-payment-methods-list__item--no-methods-found"},[t._v(" "+t._s(t.$t("paymentMethodsList.methodsNotFound"))+" ")])]):i("div",{staticClass:"apicart-payment-methods-list apicart-payment-methods-list--loading",attrs:{id:t.$t("paymentMethodsList.id")}},[i("apicart-loader",{attrs:{visible:!0}})],1)},staticRenderFns:[]},void 0,r,void 0,!1,void 0,!1,void 0,void 0,void 0)}));