[Improvement] Coupon i18n (#431)

This commit is contained in:
neverland
2017-12-14 10:46:26 +08:00
committed by GitHub
parent c6a37bba5b
commit 1d105afc70
10 changed files with 175 additions and 116 deletions
+62 -40
View File
@@ -21,66 +21,88 @@
</template>
<script>
const coupon = {
available: 1,
discount: 0,
denominations: 150,
origin_condition: 0,
reason: '',
value: 150,
condition: '下单立减 1.50 元',
name: '新手专用优惠券',
start_at: 1489104000,
end_at: 1514592000
};
const discountCoupon = {
...coupon,
discount: 88,
denominations: 0,
origin_condition: 50,
value: 12,
condition: '下单即享 8.8 折'
};
const disabledCoupon = {
...coupon,
avaliable: 0,
reason: '未满足使用门槛'
};
const disabledDiscountCoupon = {
...discountCoupon,
avaliable: 0,
reason: '未满足使用门槛'
};
export default {
i18n: {
'zh-CN': {
coupon: {
name: '优惠券名称',
reason: '优惠券不可用原因'
},
exchange: '兑换成功'
},
'en-US': {
coupon: {
name: 'Coupon name',
reason: 'Coupon unavailable reason'
},
exchange: 'Success'
}
},
data() {
return {
showList: false,
chosenCoupon: -1,
coupons: [coupon, discountCoupon],
disabledCoupons: [disabledCoupon, disabledDiscountCoupon]
chosenCoupon: -1
};
},
computed: {
coupons() {
return [this.coupon, this.discountCoupon];
},
disabledCoupons() {
return [this.disabledCoupon, this.disabledDiscountCoupon];
},
coupon() {
return {
available: 1,
discount: 0,
denominations: 150,
origin_condition: 0,
reason: '',
value: 150,
name: this.$t('coupon.name'),
start_at: 1489104000,
end_at: 1514592000
}
},
discountCoupon() {
return {
...this.coupon,
discount: 88,
denominations: 0,
origin_condition: 50,
value: 12
}
},
disabledCoupon() {
return {
...this.coupon,
avaliable: 0,
reason: this.$t('coupon.reason')
}
},
disabledDiscountCoupon() {
return {
...this.discountCoupon,
avaliable: 0,
reason: this.$t('coupon.reason')
}
}
},
methods: {
onChange(index) {
this.showList = false;
this.chosenCoupon = index;
},
onExchange(code) {
Toast('兑换成功');
Toast(this.$t('exchange'));
this.coupons.push(coupon);
}
}
+32 -35
View File
@@ -13,14 +13,14 @@ Vue.use(CouponList);
#### Basic Usage
```html
<!-- 优惠券单元格 -->
<!-- Coupon Cell -->
<van-coupon-cell
:coupons="coupons"
:chosenCoupon="chosenCoupon"
@click="showList = true"
/>
<!-- 优惠券列表 -->
<!-- Coupon List -->
<van-popup v-model="showList" position="bottom">
<van-coupon-list
:coupons="coupons"
@@ -40,8 +40,7 @@ const coupon = {
origin_condition: 0,
reason: '',
value: 150,
condition: '下单立减 1.50 元',
name: '新手专用优惠券',
name: 'Coupon name',
start_at: 1489104000,
end_at: 1514592000
};
@@ -69,47 +68,45 @@ export default {
### CouponCell API
| Attribute | Description | Type | Default | 必须 |
| Attribute | Description | Type | Default | Accepted Values |
|-----------|-----------|-----------|-------------|-------------|
| title | 单元格标题 | `String` | `优惠` | - |
| chosenCoupon | 当前选中优惠券的索引 | `Number` | `-1` | - |
| coupons | 可用优惠券列表 | `Array` | `[]` | - |
| editable | 能否切换优惠券 | `Boolean` | `true` | - |
| title | Cell title | `String` | `Coupon` | - |
| chosenCoupon | Index of chosen coupon | `Number` | `-1` | - |
| coupons | Coupon list | `Array` | `[]` | - |
| editable | Cell editable | `Boolean` | `true` | - |
### CouponList API
| Attribute | Description | Type | Default | 必须 |
| Attribute | Description | Type | Default | Accepted Values |
|-----------|-----------|-----------|-------------|-------------|
| v-model | 是否展示优惠券列表 | `Boolean` | `false` | - |
| chosenCoupon | 当前选中优惠券的索引 | `Number` | `-1` | - |
| coupons | 可用优惠券列表 | `Array` | `[]` | - |
| disabledCoupons | 不可用优惠券列表 | `Array` | `[]` | - |
| exchangeButtonText | 兑换按钮文字 | `String` | `兑换` | - |
| exchangeButtonDisabled | 是否禁用兑换按钮 | `Boolean` | `false` | - |
| displayedCouponIndex | 滚动至特定优惠券位置 | `Number` | - | - |
| closeButtonText | 列表底部按钮文字 | `String` | 不使用优惠 | - |
| disabledListTitle | 不可用券列表标题 | `String` | 不可用优惠 | - |
| inputPlaceholder | 输入框文字提示 | `String` | 请输入优惠码 | - |
| chosenCoupon | Index of chosen coupon | `Number` | `-1` | - |
| coupons | Coupon list | `Array` | `[]` | - |
| disabledCoupons | Disabled voupon list | `Array` | `[]` | - |
| exchangeButtonText | Exchange button text | `String` | `Exchange` | - |
| exchangeButtonDisabled | Whether to disable exchange button | `Boolean` | `false` | - |
| displayedCouponIndex | Index of displayed coupon | `Number` | - | - |
| closeButtonText | Close button text | `String` | `Close` | - |
| disabledListTitle | Disabled list title | `String` | `Unavailable` | - |
| inputPlaceholder | Input placeholder | `String` | `Coupon code` | - |
### CouponList Event
| Event | Description | Attribute |
|-----------|-----------|-----------|
| change | 优惠券切换回调 | index, 选中优惠券的索引 |
| exchange | 兑换优惠券回调 | code, 兑换码 |
| change | Triggered when change chosen coupon | index: index of chosen coupon |
| exchange | Triggered when exchange coupon | code: exchange code |
### Coupon Item Data Structure
### Data Structure
#### 优惠券字段说明
| key | Description | Type |
|-----------|-----------|-----------|
| id | 优惠券 id | `String` |
| name | 优惠券名称 | `String` |
| available | 是否可用, 1:可用,0:不可用 | `Number` |
| discount | 折扣(0为满减券)88=>8.8折 | `Number` |
| denominations | 面值(0为折扣券)单位分 | `Number` |
| origin_condition | 满减条件(0为无门槛,满XX元可用)单位分 | `Number` |
| start_at | 卡有效开始时间 | `Number` |
| end_at | 卡失效日期 | `Number` |
| reason | 不可用原因 | `String` |
| value | 订单优惠金额,单位分 | `Number` |
| condition | 格式化输出 value | `String` |
| id | Id | `String` |
| name | Name | `String` |
| discount | Discount | `Number` |
| denominations | Denominations | `Number` |
| origin_condition | Condition | `Number` |
| start_at | Start time | `Number` |
| end_at | End time | `Number` |
| reason | Unavailable reason | `String` |
| value | Value | `Number` |
+7 -10
View File
@@ -40,8 +40,7 @@ const coupon = {
origin_condition: 0,
reason: '',
value: 150,
condition: '下单立减 1.50 元',
name: '新手专用优惠券',
name: '优惠券名称',
start_at: 1489104000,
end_at: 1514592000
};
@@ -72,7 +71,7 @@ export default {
| 参数 | 说明 | 类型 | 默认值 | 必须 |
|-----------|-----------|-----------|-------------|-------------|
| title | 单元格标题 | `String` | `优惠` | - |
| title | 单元格标题 | `String` | `优惠券码` | - |
| chosenCoupon | 当前选中优惠券的索引 | `Number` | `-1` | - |
| coupons | 可用优惠券列表 | `Array` | `[]` | - |
| editable | 能否切换优惠券 | `Boolean` | `true` | - |
@@ -81,7 +80,6 @@ export default {
| 参数 | 说明 | 类型 | 默认值 | 必须 |
|-----------|-----------|-----------|-------------|-------------|
| v-model | 是否展示优惠券列表 | `Boolean` | `false` | - |
| chosenCoupon | 当前选中优惠券的索引 | `Number` | `-1` | - |
| coupons | 可用优惠券列表 | `Array` | `[]` | - |
| disabledCoupons | 不可用优惠券列表 | `Array` | `[]` | - |
@@ -89,9 +87,9 @@ export default {
| exchangeButtonDisabled | 是否禁用兑换按钮 | `Boolean` | `false` | - |
| displayedCouponIndex | 滚动至特定优惠券位置 | `Number` | - | - |
| showCloseButton | 是否显示列表底部按钮 | `Boolean` | `true` | - |
| closeButtonText | 列表底部按钮文字 | `String` | 不使用优惠 | - |
| disabledListTitle | 不可用券列表标题 | `String` | 不可用优惠 | - |
| inputPlaceholder | 输入框文字提示 | `String` | 请输入优惠码 | - |
| closeButtonText | 列表底部按钮文字 | `String` | `不使用优惠` | - |
| disabledListTitle | 不可用券列表标题 | `String` | `不可用优惠` | - |
| inputPlaceholder | 输入框文字提示 | `String` | `请输入优惠码` | - |
| showExchangeBar | 是否展示兑换栏 | `Boolean` | `true` | - |
### CouponList Event
@@ -107,12 +105,11 @@ export default {
|-----------|-----------|-----------|
| id | 优惠券 id | `String` |
| name | 优惠券名称 | `String` |
| available | 是否可用, 1:可用,0:不可用 | `Number` |
| discount | 折扣(0为满减券)88=>8.8折 | `Number` |
| denominations | 面值(0为折扣券)单位分 | `Number` |
| origin_condition | 满减条件(0为无门槛,满XX元可用)单位分 | `Number` |
| start_at | 卡有效开始时间 | `Number` |
| start_at | 卡有效开始时间 | `Number` |
| end_at | 卡失效日期 | `Number` |
| reason | 不可用原因 | `String` |
| value | 订单优惠金额,单位分 | `Number` |
| condition | 格式化输出 value | `String` |
+1 -1
View File
@@ -532,7 +532,7 @@ module.exports = {
},
{
path: '/coupon',
title: 'Coupon (In translation)'
title: 'Coupon'
},
{
path: '/goods-action',