Changeset View
Changeset View
Standalone View
Standalone View
src/resources/vue/Widgets/SubscriptionSelect.vue
Show First 20 Lines • Show All 66 Lines • ▼ Show 20 Lines | export default { | ||||
// assign currency, discount, discount_description of the current user | // assign currency, discount, discount_description of the current user | ||||
this.$root.userWalletProps(this) | this.$root.userWalletProps(this) | ||||
if (this.object.wallet) { | if (this.object.wallet) { | ||||
this.discount = this.object.wallet.discount | this.discount = this.object.wallet.discount | ||||
this.discount_description = this.object.wallet.discount_description | this.discount_description = this.object.wallet.discount_description | ||||
} | } | ||||
axios.get('/api/v4/' + this.type + 's/' + this.object.id + '/skus', { loader: true }) | let url = '/api/v4/' + this.type + 's/' + this.object.id + '/skus' | ||||
if (!this.object.id) { | |||||
url = '/api/v4/skus?type=' + this.type.replace(/-([a-z])/g, (match, p1) => p1.toUpperCase()) | |||||
} | |||||
axios.get(url, { loader: true }) | |||||
.then(response => { | .then(response => { | ||||
if (this.readonly) { | if (this.readonly && this.object.skus) { | ||||
response.data = response.data.filter(sku => { return sku.id in this.object.skus }) | response.data = response.data.filter(sku => { return sku.id in this.object.skus }) | ||||
} | } | ||||
// "merge" SKUs with user entitlement-SKUs | // "merge" SKUs with user entitlement-SKUs | ||||
this.skus = response.data | this.skus = response.data | ||||
.map(sku => { | .map(sku => { | ||||
const objSku = this.object.skus[sku.id] | const objSku = this.object.skus ? this.object.skus[sku.id] : null | ||||
if (objSku) { | if (objSku) { | ||||
sku.enabled = true | sku.enabled = true | ||||
sku.skuCost = sku.cost | sku.skuCost = sku.cost | ||||
sku.cost = objSku.costs.reduce((sum, current) => sum + current) | sku.cost = objSku.costs.reduce((sum, current) => sum + current) | ||||
sku.value = objSku.count | sku.value = objSku.count | ||||
sku.costs = objSku.costs | sku.costs = objSku.costs | ||||
} else if (!sku.readonly) { | } else { | ||||
if ('nextCost' in sku) { | |||||
sku.cost = sku.nextCost | |||||
} | |||||
if (!sku.readonly) { | |||||
sku.enabled = false | sku.enabled = false | ||||
} | } | ||||
} | |||||
return sku | return sku | ||||
}) | }) | ||||
// Update all range inputs (and price) | // Update all range inputs (and price) | ||||
this.$nextTick(() => { | this.$nextTick(() => { | ||||
$(this.$el).find('input[type=range]').each((idx, elem) => { this.rangeUpdate(elem) }) | $(this.$el).find('input[type=range]').each((idx, elem) => { this.rangeUpdate(elem) }) | ||||
}) | }) | ||||
▲ Show 20 Lines • Show All 101 Lines • Show Last 20 Lines |