Vue.component('checkout_review', { template: `
{{order.vendor.name_en}}
{{item.name_en}}
Quantity: {{item.quantity}} | per piece: {{item.price}}BD

Delivered by {{ order.delivered_by }} {{order.vendor.delivery_self_time}}
Total: {{order.total_items_price}}BD | Delivery: {{order.shipping_cost}}BD | Grand total: {{order.grand_price}}BD
Total: {{review.grand_price}}{{review.grand_price_currency}}
`, props: ['api_url', 'site_url', 'shopping_cart'], data: function () { return { is_loading: true, review: [], original_review: [], coupon_code: '', delivery_options: [ { 'text': 'Standard +1 BD (2 to 3 days)', 'value': 'standard' }, { 'text': 'Express + 2BD (within 2 hours)', 'value': 'express' } ] } }, methods: { requestReview: function () { if(this.shopping_cart == null || this.shopping_cart.length == 0) { return; } var thisCompo = this; this.is_loading = true; var custom_options = []; if (this.review != this.original_review) { // something is custom, // prepare custom options for (i in this.review.orders) { var order = this.review.orders[i]; var custom_option = { 'vendor_id': order.vendor.id, 'delivery_option': order.delivery_option } custom_options.push(custom_option); } } axios.post(thisCompo.api_url + '/checkout/review', { 'shopping_cart': JSON.stringify(thisCompo.shopping_cart), 'custom_options': JSON.stringify(custom_options), 'coupon_code': thisCompo.coupon_code }) .then(function (response) { thisCompo.review = response.data.data; thisCompo.original_review = JSON.parse(JSON.stringify(response.data.data)); // console.log(thisCompo.review); thisCompo.$emit('review_update', thisCompo.review); thisCompo.is_loading = false; }) .catch(function (error) { console.log(error); }); }, deliveryOptionUpdated: function () { var thisCompo = this; setTimeout(function () { thisCompo.requestReview(); }, 100); } }, watch: { api_url: { handler: function (newVal, oldVal) { this.requestReview(); } }, shopping_cart: { handler: function (newVal, oldVal) { if(newVal != oldVal) { this.requestReview(); } }, deep: true }, // review: { // handler: function(newVal, oldVal) { // this.requestReview(); // }, // deep: true // } }, created: function () { this.requestReview(); } });