diff --git a/docs/markdown/en-US/button.md b/docs/markdown/en-US/button.md
index 20d9f34f0..0eb2c63ea 100644
--- a/docs/markdown/en-US/button.md
+++ b/docs/markdown/en-US/button.md
@@ -69,6 +69,7 @@ Use `tag` prop to custom button tag
|-----------|-----------|-----------|-------------|-------------|
| type | Type | `String` | `default` | `primary` `danger` |
| size | Size | `String` | `normal` | `large` `small` `mini` |
+| text | Text | `String` | - | - |
| tag | Tag | `String` | `button` | - |
| native-type | Native Type Attribute | `String` | `''` | - |
| disabled | Whether disable button | `Boolean` | `false` | - |
diff --git a/docs/markdown/en-US/changelog.md b/docs/markdown/en-US/changelog.md
index 69f449aa7..017725342 100644
--- a/docs/markdown/en-US/changelog.md
+++ b/docs/markdown/en-US/changelog.md
@@ -1,5 +1,35 @@
## Changelog
+
+### [0.12.5](https://github.com/youzan/vant/tree/v0.12.5)
+`2018-01-23`
+
+**Improvements**
+
+* Button: add text prop [\#563](https://github.com/youzan/vant/pull/563) [@chenjiahan](https://github.com/chenjiahan)
+* CouponList: support v-model、exchangeButtonLoading、exchangeMinLength [\#556](https://github.com/youzan/vant/pull/556) [\#566](https://github.com/youzan/vant/pull/566) [@chenjiahan](https://github.com/chenjiahan)
+* Icon: update share icon [\#562](https://github.com/youzan/vant/pull/562) [@chenjiahan](https://github.com/chenjiahan)
+* Sku: improve render performance [\#550](https://github.com/youzan/vant/pull/550) [@chenjiahan](https://github.com/chenjiahan)
+
+**Bug Fixes**
+* Area: should not display city & county list when not select province [\#560](https://github.com/youzan/vant/pull/560) [@chenjiahan](https://github.com/chenjiahan)
+* Cell: fix required style [\#553](https://github.com/youzan/vant/pull/553) [@qianzhaoy](https://github.com/qianzhaoy)
+
+
+### [0.12.4](https://github.com/youzan/vant/tree/v0.12.4)
+`2018-01-18`
+
+**Improvements**
+
+* Picker: add props to custom button text [\#548](https://github.com/youzan/vant/pull/548) [@chenjiahan](https://github.com/chenjiahan)
+* Toast: add setDefaultOptions method [\#541](https://github.com/youzan/vant/pull/541) [@chenjiahan](https://github.com/chenjiahan)
+* Dialog: add setDefaultOptions method [\#539](https://github.com/youzan/vant/pull/539) [@chenjiahan](https://github.com/chenjiahan)
+
+**Bug Fixes**
+
+* Stepper: not fire event on changing the value prop [\#546](https://github.com/youzan/vant/pull/546) [@chuangbo](https://github.com/chuangbo)
+* Picker: fix misspelling of visibleItemCount prop [\#549](https://github.com/youzan/vant/pull/549) [@chenjiahan](https://github.com/chenjiahan)
+
### [0.12.3](https://github.com/youzan/vant/tree/v0.12.3)
`2018-01-12`
diff --git a/docs/markdown/en-US/coupon.md b/docs/markdown/en-US/coupon.md
index 1936abc8a..f66831482 100644
--- a/docs/markdown/en-US/coupon.md
+++ b/docs/markdown/en-US/coupon.md
@@ -79,11 +79,14 @@ export default {
| Attribute | Description | Type | Default | Accepted Values |
|-----------|-----------|-----------|-------------|-------------|
+| v-model | Current exchange code | `String` | - | - |
| chosen-coupon | Index of chosen coupon | `Number` | `-1` | - |
| coupons | Coupon list | `Array` | `[]` | - |
| disabled-coupons | Disabled voupon list | `Array` | `[]` | - |
| exchange-button-text | Exchange button text | `String` | `Exchange` | - |
+| exchange-button-loading | Whether to show loading in exchange button | `Boolean` | `false` | - |
| exchange-button-disabled | Whether to disable exchange button | `Boolean` | `false` | - |
+| exchange-min-length | Min length to enable exchange button | `Number` | `1` | - |
| displayed-coupon-index | Index of displayed coupon | `Number` | - | - |
| close-button-text | Close button text | `String` | `Close` | - |
| disabled-list-title | Disabled list title | `String` | `Unavailable` | - |
diff --git a/docs/markdown/zh-CN/button.md b/docs/markdown/zh-CN/button.md
index 8dafe15f6..e107dd4ee 100644
--- a/docs/markdown/zh-CN/button.md
+++ b/docs/markdown/zh-CN/button.md
@@ -73,8 +73,9 @@ Vue.use(Button);
|-----------|-----------|-----------|-------------|-------------|
| type | 按钮类型 | `String` | `default` | `primary` `danger` |
| size | 按钮尺寸 | `String` | `normal` | `large` `small` `mini` |
+| text | 按钮文字 | `String` | - | - |
| tag | 按钮标签 | `String` | `button` | 任意`HTML`标签 |
-| native-type | 按钮类型(原生) | `String` | `''` | - |
+| native-type | 按钮类型(原生) | `String` | - | - |
| disabled | 是否禁用 | `Boolean` | `false` | - |
| loading | 是否显示为加载状态 | `Boolean` | `false` | - |
| block | 是否为块级元素 | `Boolean` | `false` | - |
diff --git a/docs/markdown/zh-CN/changelog-generated.md b/docs/markdown/zh-CN/changelog-generated.md
index b91722ef0..fae164c9d 100644
--- a/docs/markdown/zh-CN/changelog-generated.md
+++ b/docs/markdown/zh-CN/changelog-generated.md
@@ -1,5 +1,55 @@
## 更新日志
+## [v0.12.5](https://github.com/youzan/vant/tree/v0.12.5) (2018-01-23)
+[Full Changelog](https://github.com/youzan/vant/compare/v0.12.4...v0.12.5)
+
+**Issue**
+
+- ssr项目使用时css加载错误 [\#561](https://github.com/youzan/vant/issues/561)
+- css加载报错 [\#559](https://github.com/youzan/vant/issues/559)
+- tabbar的active手动设置不生效 [\#558](https://github.com/youzan/vant/issues/558)
+- 页面手动刷新 tabbar 会 回到起始路由页面对应的 active icon [\#557](https://github.com/youzan/vant/issues/557)
+- 轮播图van-swipe 懒加载图片v-lazy 使用报错Failed to resolve directive: lazy [\#554](https://github.com/youzan/vant/issues/554)
+- ssr 使用 babel-plugin-import报错 [\#552](https://github.com/youzan/vant/issues/552)
+- stepper如何放到cell里面? [\#551](https://github.com/youzan/vant/issues/551)
+- DatetimePicker设置每一列可见元素个数visibile-column-count失效 [\#547](https://github.com/youzan/vant/issues/547)
+- Toast 和 Dialog 增加全局参数配置 [\#538](https://github.com/youzan/vant/issues/538)
+- picker 组件文档 [\#537](https://github.com/youzan/vant/issues/537)
+
+**Improvements**
+
+- \[Improvement\] CouponList: support v-model & exchangeButtonLoading [\#566](https://github.com/youzan/vant/pull/566) ([chenjiahan](https://github.com/chenjiahan))
+- \[Improvement\] update dependencies [\#565](https://github.com/youzan/vant/pull/565) ([chenjiahan](https://github.com/chenjiahan))
+- \[Improvement\] Button: add text prop [\#563](https://github.com/youzan/vant/pull/563) ([chenjiahan](https://github.com/chenjiahan))
+- \[Improvement\] Icon: update share icon [\#562](https://github.com/youzan/vant/pull/562) ([chenjiahan](https://github.com/chenjiahan))
+- \[bugfix\] Area: should not display city & county list when not select province [\#560](https://github.com/youzan/vant/pull/560) ([chenjiahan](https://github.com/chenjiahan))
+- \[Improvement\] CouponList: add exchangeMinLength prop [\#556](https://github.com/youzan/vant/pull/556) ([chenjiahan](https://github.com/chenjiahan))
+- \[bugfix\] Cell: fix required style [\#553](https://github.com/youzan/vant/pull/553) ([qianzhaoy](https://github.com/qianzhaoy))
+- \[Improvement\] Sku: improve render performance [\#550](https://github.com/youzan/vant/pull/550) ([chenjiahan](https://github.com/chenjiahan))
+
+## [v0.12.4](https://github.com/youzan/vant/tree/v0.12.4) (2018-01-18)
+[Full Changelog](https://github.com/youzan/vant/compare/v0.12.3...v0.12.4)
+
+**Issue**
+
+- \[Stepper\]: should not fire the events on changing the value prop [\#545](https://github.com/youzan/vant/issues/545)
+- 有关vant导入所有组件用法示例异常 [\#543](https://github.com/youzan/vant/issues/543)
+- 密码输入框组件与数字键盘组件报错 [\#542](https://github.com/youzan/vant/issues/542)
+- ImagePreview 组件文档 [\#540](https://github.com/youzan/vant/issues/540)
+- 官网文档 Button组件API "disabled" 拼写错误 [\#536](https://github.com/youzan/vant/issues/536)
+- TabBar切换颜色没有加深 [\#535](https://github.com/youzan/vant/issues/535)
+- 问一个swipe的问题?为什么写了img 写上了v-lazy 没效果 [\#534](https://github.com/youzan/vant/issues/534)
+- checkbox的全选取消的问题 [\#533](https://github.com/youzan/vant/issues/533)
+
+**Improvements**
+
+- \[bugfix\] Picker: misspelling of visibleItemCount [\#549](https://github.com/youzan/vant/pull/549) ([chenjiahan](https://github.com/chenjiahan))
+- \[Improvement\] Picker: add props to custom button text [\#548](https://github.com/youzan/vant/pull/548) ([chenjiahan](https://github.com/chenjiahan))
+- \[bug fix\] Stepper: not fire event on changing the value prop [\#546](https://github.com/youzan/vant/pull/546) ([chuangbo](https://github.com/chuangbo))
+- \[Doc\] fix misspelling of NumberKeyboard [\#544](https://github.com/youzan/vant/pull/544) ([chenjiahan](https://github.com/chenjiahan))
+- \[Improvement\] Toast: add setDefaultOptions method [\#541](https://github.com/youzan/vant/pull/541) ([chenjiahan](https://github.com/chenjiahan))
+- \[Improvement\] Dialog: add setDefaultOptions method [\#539](https://github.com/youzan/vant/pull/539) ([chenjiahan](https://github.com/chenjiahan))
+
## [v0.12.3](https://github.com/youzan/vant/tree/v0.12.3) (2018-01-12)
[Full Changelog](https://github.com/youzan/vant/compare/v0.12.2...v0.12.3)
diff --git a/docs/markdown/zh-CN/changelog.md b/docs/markdown/zh-CN/changelog.md
index 46f75f9ab..fe2207b67 100644
--- a/docs/markdown/zh-CN/changelog.md
+++ b/docs/markdown/zh-CN/changelog.md
@@ -1,5 +1,34 @@
## 更新日志
+### [0.12.5](https://github.com/youzan/vant/tree/v0.12.5)
+`2018-01-23`
+
+**Improvements**
+
+* Button: 新增 text 属性 [\#563](https://github.com/youzan/vant/pull/563) [@chenjiahan](https://github.com/chenjiahan)
+* CouponList: 支持 v-model、exchangeButtonLoading、exchangeMinLength [\#556](https://github.com/youzan/vant/pull/556) [\#566](https://github.com/youzan/vant/pull/566) [@chenjiahan](https://github.com/chenjiahan)
+* Icon: 更新 share 图标 [\#562](https://github.com/youzan/vant/pull/562) [@chenjiahan](https://github.com/chenjiahan)
+* Sku: 优化渲染性能 [\#550](https://github.com/youzan/vant/pull/550) [@chenjiahan](https://github.com/chenjiahan)
+
+**Bug Fixes**
+* Area: 修复未选中省份时市区展示错误的问题 [\#560](https://github.com/youzan/vant/pull/560) [@chenjiahan](https://github.com/chenjiahan)
+* Cell: 修复 required 样式错误的问题 [\#553](https://github.com/youzan/vant/pull/553) [@qianzhaoy](https://github.com/qianzhaoy)
+
+
+### [0.12.4](https://github.com/youzan/vant/tree/v0.12.4)
+`2018-01-18`
+
+**Improvements**
+
+* Picker: 新增 confirmButtonText、cancelButtonText 属性 [\#548](https://github.com/youzan/vant/pull/548) [@chenjiahan](https://github.com/chenjiahan)
+* Toast: 新增 setDefaultOptions 方法 [\#541](https://github.com/youzan/vant/pull/541) [@chenjiahan](https://github.com/chenjiahan)
+* Dialog: 新增 setDefaultOptions 方法 [\#539](https://github.com/youzan/vant/pull/539) [@chenjiahan](https://github.com/chenjiahan)
+
+**Bug Fixes**
+
+* Stepper: 修改 value 值时不触发 change 事件 [\#546](https://github.com/youzan/vant/pull/546) [@chuangbo](https://github.com/chuangbo)
+* Picker: 修复 visibleItemCount 属性拼写错误 [\#549](https://github.com/youzan/vant/pull/549) [@chenjiahan](https://github.com/chenjiahan)
+
### [0.12.3](https://github.com/youzan/vant/tree/v0.12.3)
`2018-01-12`
diff --git a/docs/markdown/zh-CN/coupon.md b/docs/markdown/zh-CN/coupon.md
index df633df6a..a9b5685fc 100644
--- a/docs/markdown/zh-CN/coupon.md
+++ b/docs/markdown/zh-CN/coupon.md
@@ -69,7 +69,7 @@ export default {
### CouponCell API
-| 参数 | 说明 | 类型 | 默认值 | 必须 |
+| 参数 | 说明 | 类型 | 默认值 | 可选值 |
|-----------|-----------|-----------|-------------|-------------|
| title | 单元格标题 | `String` | `优惠券码` | - |
| chosen-coupon | 当前选中优惠券的索引 | `Number` | `-1` | - |
@@ -78,13 +78,16 @@ export default {
### CouponList API
-| 参数 | 说明 | 类型 | 默认值 | 必须 |
+| 参数 | 说明 | 类型 | 默认值 | 可选值 |
|-----------|-----------|-----------|-------------|-------------|
+| v-model | 当前输入的兑换码 | `String` | - | - |
| chosen-coupon | 当前选中优惠券的索引 | `Number` | `-1` | - |
| coupons | 可用优惠券列表 | `Array` | `[]` | - |
| disabled-doupons | 不可用优惠券列表 | `Array` | `[]` | - |
| exchange-button-text | 兑换按钮文字 | `String` | `兑换` | - |
+| exchange-button-loading | 是否在兑换按钮上显示加载动画 | `Boolean` | `false` | - |
| exchange-button-disabled | 是否禁用兑换按钮 | `Boolean` | `false` | - |
+| exchange-min-length | 兑换码最小长度 | `Number` | `1` | - |
| displayed-coupon-index | 滚动至特定优惠券位置 | `Number` | - | - |
| show-close-button | 是否显示列表底部按钮 | `Boolean` | `true` | - |
| close-button-text | 列表底部按钮文字 | `String` | `不使用优惠` | - |
diff --git a/docs/src/index.tpl b/docs/src/index.tpl
index 25be4e5ac..d8dad08f8 100644
--- a/docs/src/index.tpl
+++ b/docs/src/index.tpl
@@ -5,6 +5,7 @@
Vant - 有赞移动端 Vue 组件库
+
diff --git a/package-lock.json b/package-lock.json
index cba6758a1..289c23cbb 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,6 +1,6 @@
{
"name": "vant",
- "version": "0.12.4",
+ "version": "0.12.5",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
diff --git a/package.json b/package.json
index 2f431a5b5..a289dfa7c 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "vant",
- "version": "0.12.4",
+ "version": "0.12.5",
"description": "A Vue.js 2.0 Mobile UI at YouZan",
"main": "lib/vant.js",
"style": "lib/vant-css/index.css",
@@ -50,7 +50,7 @@
"vue": ">= 2.5.0"
},
"devDependencies": {
- "autoprefixer": "^7.2.4",
+ "autoprefixer": "^7.2.5",
"avoriaz": "2.0.0",
"babel-cli": "^6.26.0",
"babel-core": "^6.26.0",
@@ -63,10 +63,10 @@
"chai": "^4.1.2",
"codecov": "^3.0.0",
"cross-env": "^5.1.3",
- "css-loader": "^0.28.8",
- "dependency-tree": "^5.12.0",
- "eslint": "^4.15.0",
- "eslint-plugin-vue": "^4.1.0",
+ "css-loader": "^0.28.9",
+ "dependency-tree": "^6.0.0",
+ "eslint": "^4.16.0",
+ "eslint-plugin-vue": "^4.2.0",
"extract-text-webpack-plugin": "3.0.2",
"fast-vue-md-loader": "^1.0.3",
"friendly-errors-webpack-plugin": "^1.6.1",
@@ -89,23 +89,23 @@
"precss": "2.0.0",
"progress-bar-webpack-plugin": "^1.10.0",
"rimraf": "^2.5.4",
- "shelljs": "^0.7.8",
+ "shelljs": "^0.8.1",
"sinon": "^2.4.1",
"sinon-chai": "^2.12.0",
"style-loader": "^0.19.1",
"uppercamelcase": "^3.0.0",
"url-loader": "^0.6.2",
- "vant-doc": "1.0.1",
+ "vant-doc": "1.0.2",
"vue": "^2.5.13",
- "vue-loader": "^13.6.2",
+ "vue-loader": "^13.7.0",
"vue-router": "^3.0.1",
- "vue-sfc-compiler": "^0.0.7",
+ "vue-sfc-compiler": "^0.0.8",
"vue-style-loader": "^3.0.0",
"vue-template-compiler": "^2.5.13",
"vue-template-es2015-compiler": "^1.6.0",
"webpack": "^3.10.0",
- "webpack-bundle-analyzer": "^2.9.1",
- "webpack-dev-server": "2.9.7",
+ "webpack-bundle-analyzer": "^2.9.2",
+ "webpack-dev-server": "2.11.1",
"webpack-merge": "^4.1.1"
}
}
diff --git a/packages/area/index.vue b/packages/area/index.vue
index b01e9cf6f..1a3e3f7ac 100644
--- a/packages/area/index.vue
+++ b/packages/area/index.vue
@@ -94,23 +94,23 @@ export default create({
// 根据省市县类型和对应的`code`获取对应列表
getList(type, code) {
- if (!this.listValid) {
- return [];
- }
+ let result = [];
- const { areaList } = this;
- const list =
- type === 'province'
- ? areaList.province_list
- : type === 'city' ? areaList.city_list : areaList.county_list;
+ if (this.listValid && (type === 'province' || code)) {
+ const { areaList } = this;
+ const list =
+ type === 'province'
+ ? areaList.province_list
+ : type === 'city' ? areaList.city_list : areaList.county_list;
- let result = Object.keys(list).map(code => ({
- code,
- name: list[code]
- }));
+ result = Object.keys(list).map(code => ({
+ code,
+ name: list[code]
+ }));
- if (type !== 'province' && code) {
- result = result.filter(item => item.code.indexOf(code) === 0);
+ if (type !== 'province' && code) {
+ result = result.filter(item => item.code.indexOf(code) === 0);
+ }
}
result.unshift({
diff --git a/packages/button/index.vue b/packages/button/index.vue
index 7ba592405..4fe3aab95 100644
--- a/packages/button/index.vue
+++ b/packages/button/index.vue
@@ -23,7 +23,7 @@
:color="type === 'default' ? 'black' : 'white'"
/>
-
+ {{ text }}
@@ -35,6 +35,7 @@ export default create({
name: 'van-button',
props: {
+ text: String,
block: Boolean,
loading: Boolean,
disabled: Boolean,
diff --git a/packages/coupon-list/index.vue b/packages/coupon-list/index.vue
index dfbfcd415..b3dddeda5 100644
--- a/packages/coupon-list/index.vue
+++ b/packages/coupon-list/index.vue
@@ -3,7 +3,7 @@
@@ -11,11 +11,11 @@
size="small"
type="danger"
class="van-coupon-list__exchange"
- :disabled="exchangeButtonDisabled || !exchangeCode.length"
+ :text="exchangeButtonText || $t('exchange')"
+ :loading="exchangeButtonLoading"
+ :disabled="buttonDisabled"
@click="onClickExchangeButton"
- >
- {{ exchangeButtonText || $t('exchange') }}
-
+ />
{{ disabledListTitle || $t('disabled') }}
- {{ closeButtonText || $t('close') }}
-
+ @click="$emit('change', -1)"
+ />
@@ -69,11 +68,22 @@ export default create({
CouponItem
},
+ model: {
+ prop: 'code'
+ },
+
props: {
+ code: String,
closeButtonText: String,
inputPlaceholder: String,
disabledListTitle: String,
exchangeButtonText: String,
+ exchangeButtonLoading: Boolean,
+ exchangeButtonDisabled: Boolean,
+ exchangeMinLength: {
+ type: Number,
+ default: 1
+ },
chosenCoupon: {
type: Number,
default: -1
@@ -86,10 +96,6 @@ export default create({
type: Array,
default: () => []
},
- exchangeButtonDisabled: {
- type: Boolean,
- default: false
- },
displayedCouponIndex: {
type: Number,
default: -1
@@ -104,16 +110,34 @@ export default create({
}
},
- watch: {
- displayedCouponIndex(val) {
- this.scrollToShowCoupon(val);
+ data() {
+ return {
+ currentCode: this.code || ''
+ };
+ },
+
+ computed: {
+ buttonDisabled() {
+ return (
+ !this.exchangeButtonLoading &&
+ (this.exchangeButtonDisabled ||
+ this.currentCode.length < this.exchangeMinLength)
+ );
}
},
- data() {
- return {
- exchangeCode: ''
- };
+ watch: {
+ code(code) {
+ this.currentCode = code;
+ },
+
+ currentCode(code) {
+ this.$emit('input', code);
+ },
+
+ displayedCouponIndex(val) {
+ this.scrollToShowCoupon(val);
+ }
},
mounted() {
@@ -121,17 +145,16 @@ export default create({
},
methods: {
- onClickNotUse() {
- this.$emit('change', -1);
- },
- onClickCoupon(index) {
- this.$emit('change', index);
- },
onClickExchangeButton() {
- this.$emit('exchange', this.exchangeCode);
- this.exchangeCode = '';
+ this.$emit('exchange', this.currentCode);
+
+ // auto clear currentCode when not use v-model
+ if (!this.code) {
+ this.currentCode = '';
+ }
},
- // 滚动到特定优惠券的位置
+
+ // scroll to show specific coupon
scrollToShowCoupon(index) {
if (index === -1) {
return;
diff --git a/packages/dialog/dialog.vue b/packages/dialog/dialog.vue
index 4a8f0349b..166bf115e 100644
--- a/packages/dialog/dialog.vue
+++ b/packages/dialog/dialog.vue
@@ -50,14 +50,11 @@ export default create({
callback: Function,
confirmButtonText: String,
cancelButtonText: String,
+ showCancelButton: Boolean,
showConfirmButton: {
type: Boolean,
default: true
},
- showCancelButton: {
- type: Boolean,
- default: false
- },
overlay: {
type: Boolean,
default: true
diff --git a/packages/index.js b/packages/index.js
index e0f2a340f..2a7c59799 100644
--- a/packages/index.js
+++ b/packages/index.js
@@ -62,7 +62,7 @@ import TreeSelect from './tree-select';
import Uploader from './uploader';
import Waterfall from './waterfall';
-const version = '0.12.4';
+const version = '0.12.5';
const components = [
Actionsheet,
AddressEdit,
diff --git a/packages/sku/containers/SkuContainer.vue b/packages/sku/Sku.vue
similarity index 86%
rename from packages/sku/containers/SkuContainer.vue
rename to packages/sku/Sku.vue
index fb27be30a..4360b149e 100644
--- a/packages/sku/containers/SkuContainer.vue
+++ b/packages/sku/Sku.vue
@@ -3,7 +3,12 @@
-
+
-
+
-
+
-
+
-
+
-
+
/* eslint-disable camelcase */
import Vue from 'vue';
-import Popup from '../../popup';
-import Toast from '../../toast';
-import SkuHeader from '../components/SkuHeader';
-import SkuRow from '../components/SkuRow';
-import SkuRowItem from '../components/SkuRowItem';
-import SkuStepper from '../components/SkuStepper';
-import SkuMessages from '../components/SkuMessages';
-import SkuActions from '../components/SkuActions';
+import Popup from '../popup';
+import Toast from '../toast';
+import SkuHeader from './components/SkuHeader';
+import SkuRow from './components/SkuRow';
+import SkuRowItem from './components/SkuRowItem';
+import SkuStepper from './components/SkuStepper';
+import SkuMessages from './components/SkuMessages';
+import SkuActions from './components/SkuActions';
import {
isAllSelected,
getSkuComb,
getSelectedSkuValues
-} from '../utils/skuHelper';
-import { LIMIT_TYPE } from '../constants';
-import { create } from '../../utils';
+} from './utils/skuHelper';
+import { LIMIT_TYPE } from './constants';
+import { create } from '../utils';
const { QUOTA_LIMIT } = LIMIT_TYPE;
@@ -115,13 +126,20 @@ export default create({
},
props: {
+ sku: Object,
goods: Object,
+ value: Boolean,
+ buyText: String,
goodsId: [Number, String],
+ stepperTitle: String,
+ hideStock: Boolean,
+ resetStepperOnHide: Boolean,
+ resetSelectedSkuOnHide: Boolean,
+ disableStepperInput: Boolean,
initialSku: {
type: Object,
default: () => ({})
},
- sku: Object,
quota: {
type: Number,
default: 0
@@ -130,25 +148,18 @@ export default create({
type: Number,
default: 0
},
- hideStock: Boolean,
showAddCartBtn: {
type: Boolean,
default: true
},
- buyText: String,
- stepperTitle: String,
bodyOffsetTop: {
type: Number,
default: 200
},
- resetStepperOnHide: Boolean,
- resetSelectedSkuOnHide: Boolean,
- disableStepperInput: Boolean,
messagePlaceholderMap: {
type: Object,
default: () => ({})
- },
- value: Boolean
+ }
},
data() {
@@ -205,19 +216,19 @@ export default create({
maxHeight: maxHeight + 'px'
};
},
+
isSkuCombSelected() {
return isAllSelected(this.sku.tree, this.selectedSku);
},
- // sku数据不存在时不渲染模板
+
isSkuEmpty() {
- for (var key in this.sku) {
- if (Object.prototype.hasOwnProperty.call(this.sku, key)) return false;
- }
- return true;
+ return Object.keys(this.sku).length === 0;
},
+
hasSku() {
return !this.sku.none_sku;
},
+
selectedSkuComb() {
if (!this.hasSku) {
return {
@@ -230,13 +241,14 @@ export default create({
}
return null;
},
+
skuTree() {
return this.sku.tree || [];
}
},
created() {
- var skuEventBus = new Vue();
+ const skuEventBus = new Vue();
this.skuEventBus = skuEventBus;
skuEventBus.$on('sku:close', this.handleCloseClicked);
@@ -263,19 +275,23 @@ export default create({
}
});
},
+
getSkuMessages() {
return this.$refs.skuMessages ? this.$refs.skuMessages.getMessages() : {};
},
+
getSkuCartMessages() {
return this.$refs.skuMessages
? this.$refs.skuMessages.getCartMessages()
: {};
},
+
validateSkuMessages() {
return this.$refs.skuMessages
? this.$refs.skuMessages.validateMessages()
: '';
},
+
validateSku() {
if (this.selectedNum === 0) {
return this.$t('unavailable');
@@ -289,9 +305,11 @@ export default create({
return this.$t('spec');
}
},
+
handleCloseClicked() {
this.show = false;
},
+
handleSkuSelected(skuValue) {
// 点击已选中的sku时则取消选中
this.selectedSku =
@@ -305,9 +323,11 @@ export default create({
selectedSkuComb: this.selectedSkuComb
});
},
+
handleNumChange(num) {
this.selectedNum = num;
},
+
handleOverLimit({ action, limitType, quota, quotaUsed }) {
if (action === 'minus') {
Toast(this.$t('least'));
@@ -321,12 +341,15 @@ export default create({
}
}
},
+
handleAddCartClicked() {
this.handleBuyOrAddCart('add-cart');
},
+
handleBuyClicked() {
this.handleBuyOrAddCart('buy-clicked');
},
+
handleBuyOrAddCart(type) {
const error = this.validateSku();
if (error) {
diff --git a/packages/sku/components/SkuActions.vue b/packages/sku/components/SkuActions.vue
index 199128944..1654c7b29 100644
--- a/packages/sku/components/SkuActions.vue
+++ b/packages/sku/components/SkuActions.vue
@@ -1,7 +1,17 @@
- {{ $t('cart') }}
- {{ buyText || $t('buy') }}
+
+
@@ -20,15 +30,6 @@ export default create({
buyText: String,
skuEventBus: Object,
showAddCartBtn: Boolean
- },
-
- methods: {
- onAddCartClicked() {
- this.skuEventBus.$emit('sku:addCart');
- },
- onBuyClicked() {
- this.skuEventBus.$emit('sku:buy');
- }
}
});
diff --git a/packages/sku/components/SkuHeader.vue b/packages/sku/components/SkuHeader.vue
index cbe82c8c6..b8469abd9 100644
--- a/packages/sku/components/SkuHeader.vue
+++ b/packages/sku/components/SkuHeader.vue
@@ -1,12 +1,12 @@
@@ -26,9 +26,6 @@ export default create({
},
computed: {
- skuTree() {
- return this.sku.tree;
- },
goodsImg() {
const s1Id = this.selectedSku.s1;
const skuImg = this.getSkuImg(s1Id);
@@ -45,14 +42,11 @@ export default create({
},
methods: {
- onCloseClicked() {
- this.skuEventBus.$emit('sku:close');
- },
getSkuImg(id) {
if (!id) return;
// 目前skuImg都挂载在skuTree中s1那类sku上
- const treeItem = this.skuTree.filter(treeItem => treeItem.k_s === 's1')[0] || {};
+ const treeItem = this.sku.tree.filter(treeItem => treeItem.k_s === 's1')[0] || {};
if (!treeItem.v) {
return;
diff --git a/packages/sku/components/SkuMessages.vue b/packages/sku/components/SkuMessages.vue
index e72796c25..a1839030c 100644
--- a/packages/sku/components/SkuMessages.vue
+++ b/packages/sku/components/SkuMessages.vue
@@ -1,26 +1,14 @@
-
-
-
-
-
+
@@ -47,26 +35,23 @@ export default create({
computed: {
internalMessages() {
- if (Object.prototype.toString.call(this.messages) === '[object Array]') {
- return this.messages;
- }
- return [];
+ return Array.isArray(this.messages) ? this.messages.filter(message => message.type !== 'image') : [];
},
messageValues() {
- const messageValues = [];
- this.internalMessages.forEach((message, index) => {
- messageValues[index] = '';
- });
-
- return messageValues;
+ return this.internalMessages.map(() => '');
}
},
methods: {
- getType({ type, datetime }) {
- if (type === 'id_no') return 'text';
- return datetime > 0 ? 'datetime-local' : type;
+ getType(message) {
+ if (+message.multiple === 1) {
+ return 'textarea';
+ }
+ if (message.type === 'id_no') {
+ return 'text';
+ }
+ return message.datetime > 0 ? 'datetime-local' : message.type;
},
getMessages() {
@@ -96,8 +81,9 @@ export default create({
return messages;
},
- getPlaceholder(key) {
- return this.messagePlaceholderMap[key] || this.$t(`placeholder.${key}`);
+ getPlaceholder(message) {
+ const type = +message.multiple === 1 ? 'textarea' : message.type;
+ return this.messagePlaceholderMap[type] || this.$t(`placeholder.${type}`);
},
validateMessages() {
diff --git a/packages/sku/components/SkuRowItem.vue b/packages/sku/components/SkuRowItem.vue
index e33068a34..3c0920a0d 100644
--- a/packages/sku/components/SkuRowItem.vue
+++ b/packages/sku/components/SkuRowItem.vue
@@ -1,12 +1,14 @@
+ :class="{
+ 'van-sku-row__item--active': isChoosed,
+ 'van-sku-row__item--disabled': !isChoosable
+ }"
+ @click="onSkuSelected"
+ >
{{ skuValue.name }}
- {{ skuValue.name }}