Files
EdgeAdmin/web/public/js/components/plans/plan-price-config-box.js

220 lines
5.8 KiB
JavaScript
Raw Normal View History

2021-10-29 14:02:01 +08:00
// 套餐价格配置
Vue.component("plan-price-config-box", {
2022-01-23 19:16:22 +08:00
props: ["v-price-type", "v-monthly-price", "v-seasonally-price", "v-yearly-price", "v-traffic-price", "v-bandwidth-price"],
2021-10-29 14:02:01 +08:00
data: function () {
let priceType = this.vPriceType
if (priceType == null) {
priceType = "period"
}
2022-01-23 19:16:22 +08:00
// 按时间周期计费
2021-10-29 14:02:01 +08:00
let monthlyPriceNumber = 0
let monthlyPrice = this.vMonthlyPrice
if (monthlyPrice == null || monthlyPrice <= 0) {
monthlyPrice = ""
} else {
monthlyPrice = monthlyPrice.toString()
monthlyPriceNumber = parseFloat(monthlyPrice)
if (isNaN(monthlyPriceNumber)) {
monthlyPriceNumber = 0
}
}
let seasonallyPriceNumber = 0
let seasonallyPrice = this.vSeasonallyPrice
if (seasonallyPrice == null || seasonallyPrice <= 0) {
seasonallyPrice = ""
} else {
seasonallyPrice = seasonallyPrice.toString()
seasonallyPriceNumber = parseFloat(seasonallyPrice)
if (isNaN(seasonallyPriceNumber)) {
seasonallyPriceNumber = 0
}
}
let yearlyPriceNumber = 0
let yearlyPrice = this.vYearlyPrice
if (yearlyPrice == null || yearlyPrice <= 0) {
yearlyPrice = ""
} else {
yearlyPrice = yearlyPrice.toString()
yearlyPriceNumber = parseFloat(yearlyPrice)
if (isNaN(yearlyPriceNumber)) {
yearlyPriceNumber = 0
}
}
2022-01-23 19:16:22 +08:00
// 按流量计费
2021-11-09 17:36:38 +08:00
let trafficPrice = this.vTrafficPrice
let trafficPriceBaseNumber = 0
if (trafficPrice != null) {
trafficPriceBaseNumber = trafficPrice.base
2021-10-29 14:02:01 +08:00
} else {
2021-11-09 17:36:38 +08:00
trafficPrice = {
2021-10-29 14:02:01 +08:00
base: 0
}
}
2021-11-09 17:36:38 +08:00
let trafficPriceBase = ""
if (trafficPriceBaseNumber > 0) {
trafficPriceBase = trafficPriceBaseNumber.toString()
2021-10-29 14:02:01 +08:00
}
2022-01-23 19:16:22 +08:00
// 按带宽计费
let bandwidthPrice = this.vBandwidthPrice
if (bandwidthPrice == null) {
bandwidthPrice = {
percentile: 95,
ranges: []
}
} else if (bandwidthPrice.ranges == null) {
bandwidthPrice.ranges = []
}
2021-10-29 14:02:01 +08:00
return {
priceType: priceType,
monthlyPrice: monthlyPrice,
seasonallyPrice: seasonallyPrice,
yearlyPrice: yearlyPrice,
monthlyPriceNumber: monthlyPriceNumber,
seasonallyPriceNumber: seasonallyPriceNumber,
yearlyPriceNumber: yearlyPriceNumber,
2021-11-09 17:36:38 +08:00
trafficPriceBase: trafficPriceBase,
2022-01-23 19:16:22 +08:00
trafficPrice: trafficPrice,
bandwidthPrice: bandwidthPrice,
bandwidthPercentile: bandwidthPrice.percentile
}
},
methods: {
changeBandwidthPriceRanges: function (ranges) {
this.bandwidthPrice.ranges = ranges
2021-10-29 14:02:01 +08:00
}
},
watch: {
monthlyPrice: function (v) {
let price = parseFloat(v)
if (isNaN(price)) {
price = 0
}
this.monthlyPriceNumber = price
},
seasonallyPrice: function (v) {
let price = parseFloat(v)
if (isNaN(price)) {
price = 0
}
this.seasonallyPriceNumber = price
},
yearlyPrice: function (v) {
let price = parseFloat(v)
if (isNaN(price)) {
price = 0
}
this.yearlyPriceNumber = price
},
2021-11-09 17:36:38 +08:00
trafficPriceBase: function (v) {
2021-10-29 14:02:01 +08:00
let price = parseFloat(v)
if (isNaN(price)) {
price = 0
}
2021-11-09 17:36:38 +08:00
this.trafficPrice.base = price
2022-01-23 19:16:22 +08:00
},
bandwidthPercentile: function (v) {
let percentile = parseInt(v)
if (isNaN(percentile) || percentile <= 0) {
percentile = 95
} else if (percentile > 100) {
percentile = 100
}
this.bandwidthPrice.percentile = percentile
2021-10-29 14:02:01 +08:00
}
},
template: `<div>
<input type="hidden" name="priceType" :value="priceType"/>
<input type="hidden" name="monthlyPrice" :value="monthlyPriceNumber"/>
<input type="hidden" name="seasonallyPrice" :value="seasonallyPriceNumber"/>
<input type="hidden" name="yearlyPrice" :value="yearlyPriceNumber"/>
2021-11-09 17:36:38 +08:00
<input type="hidden" name="trafficPriceJSON" :value="JSON.stringify(trafficPrice)"/>
2022-01-23 19:16:22 +08:00
<input type="hidden" name="bandwidthPriceJSON" :value="JSON.stringify(bandwidthPrice)"/>
2021-10-29 14:02:01 +08:00
<div>
<radio :v-value="'period'" :value="priceType" v-model="priceType">&nbsp;按时间周期</radio> &nbsp; &nbsp;
2022-01-23 19:16:22 +08:00
<radio :v-value="'traffic'" :value="priceType" v-model="priceType">&nbsp;按流量</radio> &nbsp; &nbsp;
<radio :v-value="'bandwidth'" :value="priceType" v-model="priceType">&nbsp;按带宽</radio>
2021-10-29 14:02:01 +08:00
</div>
<!-- 按时间周期 -->
<div v-show="priceType == 'period'">
<div class="ui divider"></div>
<table class="ui table">
<tr>
<td class="title">月度价格</td>
<td>
<div class="ui input right labeled">
<input type="text" style="width: 7em" maxlength="10" v-model="monthlyPrice"/>
<span class="ui label"></span>
</div>
</td>
</tr>
<tr>
<td class="title">季度价格</td>
<td>
<div class="ui input right labeled">
<input type="text" style="width: 7em" maxlength="10" v-model="seasonallyPrice"/>
<span class="ui label"></span>
</div>
</td>
</tr>
<tr>
<td class="title">年度价格</td>
<td>
<div class="ui input right labeled">
<input type="text" style="width: 7em" maxlength="10" v-model="yearlyPrice"/>
<span class="ui label"></span>
</div>
</td>
</tr>
</table>
</div>
2021-11-09 17:36:38 +08:00
<!-- 按流量 -->
<div v-show="priceType =='traffic'">
2021-10-29 14:02:01 +08:00
<div class="ui divider"></div>
<table class="ui table">
<tr>
2022-01-23 19:16:22 +08:00
<td class="title">基础流量费用 *</td>
2021-10-29 14:02:01 +08:00
<td>
<div class="ui input right labeled">
2021-11-09 17:36:38 +08:00
<input type="text" v-model="trafficPriceBase" maxlength="10" style="width: 7em"/>
2021-10-29 14:02:01 +08:00
<span class="ui label">/GB</span>
</div>
</td>
</tr>
</table>
</div>
2022-01-23 19:16:22 +08:00
<!-- 按带宽 -->
<div v-show="priceType == 'bandwidth'">
<div class="ui divider"></div>
<table class="ui table">
<tr>
<td class="title">带宽百分位 *</td>
<td>
<div class="ui input right labeled">
<input type="text" style="width: 4em" maxlength="3" v-model="bandwidthPercentile"/>
<span class="ui label">th</span>
</div>
</td>
</tr>
<tr>
<td>带宽价格</td>
<td>
<plan-bandwidth-ranges :v-ranges="bandwidthPrice.ranges" @change="changeBandwidthPriceRanges"></plan-bandwidth-ranges>
</td>
</tr>
</table>
</div>
2021-10-29 14:02:01 +08:00
</div>`
})